/* =========================================================
   Meridian Dashboard: Main Stylesheet
   Separated for future Next.js migration
   ========================================================= */

/* ── Fonts ──────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700;800&display=swap');

/* ── CSS Variables ──────────────────────────────────────── */
:root {
  --accent:          #9b7ede;
  --accent-hover:    #c9b8e8;
  --accent-dim:      rgba(155,126,222,0.14);
  --green:           #3FB27F;
  --amber:           #E3A53D;
  --red:             #E2555C;

  --bg-base:         #0F1115;
  --bg-sidebar:      #171A21;
  --bg-card:         #1C2028;
  --bg-elevated:     #20242C;
  --bg-input:        #171A21;

  --border:          rgba(255,255,255,0.07);
  --border-subtle:   rgba(255,255,255,0.05);
  --border-strong:   rgba(255,255,255,0.12);

  --text-primary:    #F5F5F3;
  --text-secondary:  #B8B8B5;
  --text-muted:      #8a8c92;
  --text-dim:        #7d7f85;

  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   20px;

  --shadow-sm:   0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:   0 4px 14px rgba(0,0,0,0.3);
  --shadow-lg:   0 10px 30px rgba(0,0,0,0.4);
  --shadow-xl:   0 24px 60px rgba(0,0,0,0.6);

  --sidebar-w:   248px;
  --sidebar-collapsed: 76px;
  --header-h:    66px;

  --transition:  0.2s cubic-bezier(.4,0,.2,1);
}

/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; }
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Animations ─────────────────────────────────────────── */
@keyframes fadeUp    { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:none; } }
@keyframes fadeIn    { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp   { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:none; } }
@keyframes shimmer   { 0% { background-position:-800px 0; } 100% { background-position:800px 0; } }
@keyframes floatSlow  { 0%,100% { transform:translate(0,0); } 50% { transform:translate(14px,-18px); } }
@keyframes floatSlow2 { 0%,100% { transform:translate(0,0); } 50% { transform:translate(-16px,16px); } }
@keyframes pulseDot  { 0%,100% { opacity:1; } 50% { opacity:0.4; } }
@keyframes ripple    { to { transform:scale(4); opacity:0; } }
@keyframes spin      { to { transform:rotate(360deg); } }

/* ── Layout ─────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Background orbs */
#bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
#bg-orbs .orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(10px);
}
#bg-orbs .orb-1 {
  top: -120px; left: 8%;
  width: 520px; height: 520px;
  background: radial-gradient(circle, rgba(155,126,222,0.10), transparent 70%);
  animation: floatSlow 22s ease-in-out infinite;
}
#bg-orbs .orb-2 {
  bottom: -160px; right: 6%;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(63,178,127,0.07), transparent 70%);
  animation: floatSlow2 26s ease-in-out infinite;
}
#bg-orbs .orb-3 {
  top: 40%; left: 45%;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(227,165,61,0.05), transparent 70%);
  filter: blur(20px);
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 20;
  transition: width var(--transition);
  overflow: hidden;
}
#sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--border-subtle);
  flex: none;
  text-decoration: none;
  cursor: pointer;
}
/* Brand wordmark: the brand name itself, set with a deliberate weight/size
   contrast (a bold oversized initial + lighter tail) instead of an icon,
   reads as a logotype rather than "text next to a badge". */
.logo-wordmark {
  font-size: 19px;
  font-weight: 400;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  color: var(--text-primary);
  font-family: 'Geist', sans-serif;
}
.logo-wordmark-m {
  font-weight: 800;
  font-size: 1.25em;
  color: var(--accent);
  letter-spacing: -0.03em;
}

#sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  width: 100%;
  text-align: left;
  transition: background var(--transition), color var(--transition), transform 0.1s;
  background: transparent;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}
.nav-btn:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-btn.active { background: var(--bg-elevated); color: var(--text-primary); }
.nav-btn .nav-label { white-space: nowrap; overflow: hidden; }
.nav-btn svg { flex: none; }

/* Collapsed state */
#sidebar.collapsed .nav-label,
#sidebar.collapsed .logo-wordmark-tail,
#sidebar.collapsed .user-info { display: none; }
#sidebar.collapsed .nav-btn { justify-content: center; padding: 10px; }
#sidebar.collapsed .sidebar-logo { justify-content: center; padding: 22px 0; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: none;
}
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
}
.user-avatar {
  width: 32px; height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-info { min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.user-role {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-collapse {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 9px;
  padding: 8px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  width: 100%;
}
#btn-collapse:hover { background: var(--bg-card); color: var(--text-primary); }
#btn-collapse svg { transition: transform var(--transition); }

.whats-new-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}
.whats-new-btn:hover { background: var(--bg-card); color: var(--text-primary); }
.whats-new-btn svg { flex: none; }
.whats-new-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent, #9b7ede);
  flex: none;
  margin-left: auto;
}
#sidebar.collapsed .whats-new-btn { justify-content: center; padding: 8px; }
#sidebar.collapsed .whats-new-dot { display: none; }

/* ── Main Area ───────────────────────────────────────────── */
#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
#header {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 36px;
  height: var(--header-h);
  background: rgba(15,17,21,0.80);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.header-title-block { min-width: 0; }
.header-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.header-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

/* Search bar */
#search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text-muted);
  cursor: pointer;
  width: 230px;
  transition: border-color var(--transition);
}
#search-bar:hover { border-color: var(--border-strong); }
#search-bar span:not(.kbd) {
  font-size: 13px;
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kbd {
  font-size: 10.5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  color: var(--text-dim);
}

/* Clock */
.header-clock { text-align: right; line-height: 1.25; }
.header-clock-time {
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
.header-clock-date { font-size: 11px; color: var(--text-dim); }

/* Icon buttons */
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  flex: none;
}
.icon-btn:hover { background: var(--bg-elevated); }

/* Notification dot */
.notif-dot {
  position: absolute;
  top: 7px; right: 8px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--amber);
  animation: pulseDot 2.4s ease-in-out infinite;
}

/* ── Content ─────────────────────────────────────────────── */
#content {
  flex: 1;
  padding: 32px 36px 60px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Greeting banner (in dashboard) */
.greeting-banner {
  border-radius: 20px;
  padding: 30px 34px;
  background: linear-gradient(135deg, #1a1e27, #171A21);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm), 0 20px 40px -20px rgba(0,0,0,0.5);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.greeting-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.greeting-subtitle { font-size: 14px; color: #9a9ca2; margin-top: 8px; max-width: 520px; }
.greeting-tags { display: flex; gap: 8px; margin-top: 16px; }
.tag-blue {
  font-size: 12px; padding: 5px 11px; border-radius: 20px;
  background: rgba(155,126,222,0.12); color: #c9b8e8; border: 1px solid rgba(155,126,222,0.2);
}
.tag-green {
  font-size: 12px; padding: 5px 11px; border-radius: 20px;
  background: rgba(63,178,127,0.12); color: #7ecda6; border: 1px solid rgba(63,178,127,0.2);
}
.greeting-clock { text-align: right; }
.greeting-time {
  font-size: 38px; font-weight: 800; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; color: var(--text-primary);
}
.greeting-date { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-hover {
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.card-hover:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* KPI grid responsive */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  border: none;
  color: #0F1115;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity var(--transition), transform 0.1s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
}
.btn-secondary:hover { background: var(--bg-card); color: var(--text-primary); }

.btn-icon {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: background var(--transition);
}
.btn-icon:hover { background: var(--bg-card); color: var(--text-primary); }
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color var(--transition), color var(--transition);
}
.btn-chip:hover { border-color: rgba(155,126,222,0.4); color: var(--text-primary); }

/* ── Filter selects ──────────────────────────────────────── */
.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color var(--transition);
}
.filter-select:hover, .filter-select:focus { border-color: var(--border-strong); color: var(--text-primary); }

/* ── Skeleton ─────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #171A21 0%, #1e222b 50%, #171A21 100%);
  background-size: 800px 100%;
  animation: shimmer 1.6s linear infinite;
  border-radius: 12px;
}

/* ── Command Palette ─────────────────────────────────────── */
#cmd-overlay {
  position: fixed; inset: 0;
  background: rgba(8,9,12,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  animation: fadeIn 0.15s ease;
}
#cmd-panel {
  width: 560px;
  max-width: 90vw;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: slideUp 0.2s ease;
}
#cmd-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
#cmd-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14.5px;
  font-family: inherit;
}
#cmd-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
}
.cmd-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: background var(--transition);
  color: var(--text-secondary);
}
.cmd-item:hover, .cmd-item.active { background: var(--bg-elevated); color: var(--text-primary); }
.cmd-item-label { font-size: 13.5px; }
.cmd-item-hint { font-size: 11px; color: var(--text-dim); }

/* ── Export Modal ─────────────────────────────────────────── */
#export-overlay {
  position: fixed; inset: 0;
  background: rgba(8,9,12,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
#export-panel {
  width: 420px;
  max-width: 90vw;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 24px;
  animation: slideUp 0.2s ease;
}
.export-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13.5px;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 10px;
}
.export-btn:hover { border-color: rgba(155,126,222,0.4); background: var(--bg-elevated); }
.export-btn:last-child { margin-bottom: 0; }

/* ── Print ───────────────────────────────────────────────── */
@media print {
  @page { margin: 0.5cm; }
  #sidebar, #header, #cmd-overlay, #export-overlay,
  #toast-container, .btn-primary, .btn-secondary, .btn-icon { display: none !important; }
  #main { overflow: visible; }
  #content { padding: 0; overflow: visible; }
  *, *::before, *::after {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
    background-color: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    animation: none !important;
  }
}

/* ── Responsive (tablet: still the desktop layout, just tighter) ──── */
@media (max-width: 1100px) and (min-width: 769px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  #content { padding: 24px 20px 40px; }
  #header { padding: 0 20px; }
  #search-bar { width: 210px; }
}

/* ── Mobile tab bar (hidden on desktop/tablet) ──────────────────── */
/* Fixed 5 slots (4 primary views + "More"), each an equal fraction of the
   width — no horizontal scrolling. Every item reachable in exactly one
   tap: either it's here, or it's one tap away in the "More" sheet. */
#mobile-tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--mobile-tabbar-h);
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  z-index: 30;
}
#mobile-tabbar .mobile-tab {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}
#mobile-tabbar .mobile-tab.active { color: var(--accent); }
#mobile-tabbar .mobile-tab-label { font-size: 10px; font-weight: 500; white-space: nowrap; }

/* ── Mobile screen: a distinct layout, not a shrunk desktop one ───
   Below 769px the sidebar (built for a wide desktop chart-and-table
   layout) is replaced entirely by the bottom tab bar above, and every
   page collapses to a single scrollable column sized for touch. */
@media (max-width: 768px) {
  :root { --mobile-tabbar-h: 60px; }

  #sidebar { display: none; }
  #mobile-tabbar { display: flex; }

  #app { display: block; height: auto; min-height: 100vh; overflow: visible; }
  #main { overflow: visible; }

  #header {
    position: sticky;
    padding: 0 16px;
    gap: 10px;
    height: 58px;
  }
  .header-title { font-size: 16px; }
  .header-subtitle { display: none; }
  #search-bar { display: none; }
  .header-clock { display: none; }

  #content {
    padding: 14px 14px calc(var(--mobile-tabbar-h) + 24px);
    overflow: visible;
  }

  /* Every multi-column grid in the app becomes one column on mobile:
     charts, KPI tiles, and cards stack full-width instead of shrinking. */
  .kpi-grid,
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  .greeting-banner {
    flex-direction: column;
    align-items: flex-start;
    padding: 18px;
    gap: 14px;
  }
  .greeting-clock { text-align: left; }
  .greeting-time { font-size: 26px; }
  .greeting-title { font-size: 20px; }

  #cmd-panel, #export-panel { width: 92vw; }

  table { display: block; overflow-x: auto; white-space: nowrap; }
}
