:root {
  --bg-color: #0f172a;
  --panel-bg: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.5);
  --border-color: #334155;
  --sidebar-width: 280px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--panel-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.logo span {
  color: var(--accent);
}

.nav-links {
  list-style: none;
  padding: 24px 16px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  margin-bottom: 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s ease;
  font-weight: 500;
}

.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.nav-link.active {
  background-color: rgba(59, 130, 246, 0.1);
  color: var(--accent);
  border-left: 3px solid var(--accent);
  box-shadow: inset 20px 0 20px -20px var(--accent-glow);
}

.nav-icon {
  margin-right: 12px;
  width: 20px;
  height: 20px;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  height: 72px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 32px;
  background-color: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
}

/* View Container */
.view-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  overflow-y: auto;
  padding: 32px;
}

.view.active {
  opacity: 1;
  pointer-events: auto;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

.api-card {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  transition: all 0.3s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.api-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 10px 20px -10px var(--accent-glow);
}

.api-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.api-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.api-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  flex: 1;
}

.api-footer {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  font-size: 0.85rem;
}

.status-badge {
  padding: 4px 10px;
  border-radius: 99px;
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
}

/* Integration iframe */
#integration-view {
  padding: 0;
}

#integration-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--panel-bg);
}

/* Mobile menu toggle (hamburger) — hidden on desktop */
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.menu-toggle:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent);
}

.menu-toggle i { width: 20px; height: 20px; }

/* Mobile sidebar backdrop — hidden on desktop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ────────────────────────────── mobile ────────────────────────────── */
@media (max-width: 768px) {
  body {
    /* allow vertical scroll when content exceeds viewport */
    display: block;
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }

  .menu-toggle { display: inline-flex; }

  /* Sidebar becomes a slide-out drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    transform: translateX(-100%);
    z-index: 100;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop { display: block; }

  .main-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  .topbar {
    height: 60px;
    padding: 0 16px;
    position: sticky;
    top: 0;
  }

  .page-title { font-size: 1.1rem; }

  /* On mobile we drop the absolute-positioned crossfade between views; switch
     to plain show/hide so each .view contributes its own height to the flow. */
  .view-container {
    flex: 1;
    overflow: visible;
    position: static;
  }

  .view {
    position: static;
    width: 100%;
    height: auto;
    opacity: 1;
    pointer-events: auto;
    padding: 16px;
    display: none;
    overflow: visible;
  }

  .view.active { display: block; }

  /* Forecasting iframe needs an explicit, viewport-anchored height. Using dvh
     instead of vh avoids the iOS Safari URL-bar collapse jumping the layout. */
  #integration-view {
    padding: 0;
    height: calc(100dvh - 60px);
    min-height: 500px;
  }

  #integration-frame {
    width: 100%;
    height: 100%;
    min-height: 500px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .api-card { padding: 20px; }
}

/* Very small phones */
@media (max-width: 380px) {
  .view { padding: 12px; }
  .topbar { padding: 0 12px; }
  .api-card { padding: 16px; }
}
