/* ─────────────────────────────────────────────────────────────
   MPM Admin — Design System
   Editorial-operational. Pool aquatic accents.
   ───────────────────────────────────────────────────────────── */

:root {
  /* Type scale */
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Manrope', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Spatial */
  --sidebar-w: 72px;
  --flyout-w: 320px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-snap: cubic-bezier(0.6, 0, 0.2, 1);
  --t-fast: 140ms;
  --t-med: 240ms;
  --t-slow: 420ms;
}

/* ── DARK THEME (default) ──────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0a0e16;
  --bg-grad: radial-gradient(1200px 800px at 80% -10%, rgba(56, 189, 248, 0.05), transparent),
             radial-gradient(900px 600px at -10% 110%, rgba(56, 189, 248, 0.03), transparent),
             #0a0e16;
  --surface: #121724;
  --surface-2: #171d2c;
  --surface-3: #1c2335;
  --surface-elevated: #1f2738;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);
  --text: #e8edf4;
  --text-muted: #8b95a8;
  --text-dim: #5d6779;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.18);
  --accent-soft: rgba(56, 189, 248, 0.08);
  --success: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;
  --kbd-bg: rgba(255, 255, 255, 0.05);
  --shadow-flyout: 0 24px 60px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 18px 50px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
}

/* ── LIGHT THEME ───────────────────────────────────────────── */
[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-grad: radial-gradient(1200px 800px at 80% -10%, rgba(2, 132, 199, 0.05), transparent),
             #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #eaedf2;
  --surface-elevated: #ffffff;
  --border: rgba(12, 24, 40, 0.06);
  --border-strong: rgba(12, 24, 40, 0.1);
  --text: #0c1828;
  --text-muted: #5a6478;
  --text-dim: #98a1b3;
  --accent: #0284c7;
  --accent-glow: rgba(2, 132, 199, 0.14);
  --accent-soft: rgba(2, 132, 199, 0.08);
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --info: #2563eb;
  --kbd-bg: rgba(12, 24, 40, 0.05);
  --shadow-flyout: 0 24px 60px rgba(12, 24, 40, 0.12), 0 2px 8px rgba(12, 24, 40, 0.06);
  --shadow-pop: 0 18px 50px rgba(12, 24, 40, 0.14);
}

/* ── BASE ───────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg-grad);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--t-med) var(--ease-out), color var(--t-med) var(--ease-out);
}

button {
  font-family: inherit;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
}

a { color: inherit; text-decoration: none; cursor: pointer; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0;
}

/* lucide icons sizing */
[data-lucide] { width: 18px; height: 18px; flex-shrink: 0; }

/* ── APP LAYOUT ─────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  position: relative;
}

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  position: relative;
  z-index: 30;
}

.sidebar-brand {
  margin-bottom: 24px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  display: block;
  border-radius: 10px;
  /* Soft backdrop so dark-on-transparent logos remain visible in dark mode */
  background: var(--surface-3);
  padding: 4px;
  transition: background var(--t-med) var(--ease-out);
}

[data-theme="light"] .brand-logo {
  background: transparent;
  padding: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  width: 100%;
  align-items: center;
  padding: 0 12px;
}

.nav-item {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: var(--text-muted);
  position: relative;
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 22px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

/* ── SIDEBAR USER (bottom-left) ─────────────────────────────── */
.sidebar-bottom {
  padding: 0 12px;
}

.user-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  transition: transform var(--t-fast) var(--ease-out);
}

.user-btn:hover { transform: translateY(-1px); }

.user-avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #475569, #1e293b);
  color: white;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border-strong);
}

/* ── FLYOUT PANELS ──────────────────────────────────────────── */
.flyout {
  position: fixed;
  left: var(--sidebar-w);
  top: 0;
  height: 100vh;
  width: var(--flyout-w);
  background: var(--surface-elevated);
  border-right: 1px solid var(--border-strong);
  box-shadow: var(--shadow-flyout);
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  z-index: 40;
  /* Hidden state */
  opacity: 0;
  pointer-events: none;
  transform: translateX(-8px);
  transition:
    opacity var(--t-med) var(--ease-out),
    transform var(--t-med) var(--ease-out);
}

.flyout.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.flyout-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.flyout-eyebrow {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.flyout-header h3 {
  font-size: 22px;
  line-height: 1.1;
}

.flyout-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.flyout-pill {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-muted);
  flex-shrink: 0;
}

.flyout-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
  padding-right: 4px;
}

.flyout-section::-webkit-scrollbar { width: 6px; }
.flyout-section::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.flyout-section::-webkit-scrollbar-track { background: transparent; }

.flyout-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 9px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}

.flyout-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.flyout-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.flyout-item [data-lucide] {
  margin-top: 2px;
  width: 16px; height: 16px;
}

.flyout-item-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.flyout-item-text span { font-size: 13px; font-weight: 500; color: var(--text); }
.flyout-item-text p { margin: 0; font-size: 11px; color: var(--text-dim); }
.flyout-item.active .flyout-item-text span { color: var(--accent); }

.flyout-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.flyout-empty .empty-icon {
  width: 36px; height: 36px;
  opacity: 0.4;
  margin-bottom: 12px;
}

.flyout-empty p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.flyout-empty span {
  font-size: 12px;
  margin-top: 4px;
}

/* ── USER POPOVER ───────────────────────────────────────────── */
.user-popover {
  position: fixed;
  left: calc(var(--sidebar-w) + 12px);
  bottom: 16px;
  width: 280px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 8px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(0.96);
  transform-origin: bottom left;
  transition:
    opacity var(--t-med) var(--ease-out),
    transform var(--t-med) var(--ease-out);
}

.user-popover.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.user-popover-head {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 6px;
}

.user-avatar-lg {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #475569, #1e293b);
  color: white;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 14px;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.user-email {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.user-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 5px;
}

.user-popover-section {
  padding: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
}

.user-popover-section:first-of-type {
  border-top: 0;
  margin-top: 0;
  padding-top: 4px;
}

.user-popover-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
  text-align: left;
}

.user-popover-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.user-popover-item [data-lucide] { width: 15px; height: 15px; }
.user-popover-item.danger:hover { color: var(--danger); background: rgba(248, 113, 113, 0.08); }

/* Theme toggle */
.theme-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
}

.theme-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.theme-segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}

.seg-btn [data-lucide] { width: 13px; height: 13px; }
.seg-btn.active { background: var(--surface-elevated); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

/* ── MAIN ───────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.crumb-muted { color: var(--text-muted); font-weight: 500; }
.crumb-sep { color: var(--text-dim); width: 14px; height: 14px; }
.crumb-current { color: var(--text); font-weight: 600; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 11px;
  width: 320px;
  transition: border-color var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out);
}

.search-bar:focus-within {
  border-color: var(--accent);
  background: var(--surface-elevated);
}

.search-bar [data-lucide] {
  color: var(--text-dim);
  width: 15px; height: 15px;
}

.search-bar input {
  background: none;
  border: none;
  outline: none;
  flex: 1;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}

.search-bar input::placeholder { color: var(--text-dim); }

.search-bar kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  background: var(--kbd-bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: grid; place-items: center;
  color: var(--text-muted);
  position: relative;
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.notif-dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ── CONTENT ────────────────────────────────────────────────── */
.content {
  padding: 36px 32px;
  max-width: 1280px;
  overflow-y: auto;
  flex: 1;
}

.content::-webkit-scrollbar { width: 8px; }
.content::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.content::-webkit-scrollbar-track { background: transparent; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 36px;
}

.eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  margin-bottom: 10px;
}

.page-title {
  font-size: 38px;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin: 0 0 12px;
}

.page-lede {
  font-size: 15px;
  color: var(--text-muted);
  margin: 0;
  max-width: 580px;
  line-height: 1.55;
}

.page-header-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  transition: background var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn [data-lucide] { width: 15px; height: 15px; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover { background: var(--accent); filter: brightness(1.05); }

/* ── KPIs ───────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.kpi.accent {
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border-color: var(--accent-soft);
}

.kpi.accent::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, var(--accent-glow), transparent 60%);
  pointer-events: none;
}

.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: -0.005em;
}

.kpi-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 8px 0 12px;
  position: relative;
  z-index: 1;
}

.kpi-num {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.kpi.accent .kpi-num { color: var(--accent); }

.kpi-of {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.kpi-trend {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
}

.kpi-trend [data-lucide] { width: 13px; height: 13px; }
.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }
.kpi-trend.neutral { color: var(--text-muted); }

/* ── PANELS ─────────────────────────────────────────────────── */
.panel-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: 2px;
}

.panel-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 8px;
  border-radius: 6px;
  transition: background var(--t-fast) var(--ease-out);
}

.link-btn:hover { background: var(--accent-soft); }
.link-btn [data-lucide] { width: 13px; height: 13px; }

/* Activity list */
.activity-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 9px;
  transition: background var(--t-fast) var(--ease-out);
}

.activity-item:hover { background: var(--surface-2); }

.activity-icon {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: grid; place-items: center;
  flex-shrink: 0;
}

.activity-icon [data-lucide] { width: 15px; height: 15px; }
.activity-icon.success { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.activity-icon.warn { background: rgba(251, 191, 36, 0.12); color: var(--warn); }
.activity-icon.info { background: rgba(96, 165, 250, 0.12); color: var(--info); }
.activity-icon.danger { background: rgba(248, 113, 113, 0.12); color: var(--danger); }

.activity-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.activity-text strong { font-size: 13px; font-weight: 600; color: var(--text); }
.activity-text span { font-size: 11px; color: var(--text-muted); }

/* Bar list */
.bar-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }

.bar-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 6px;
}

.bar-label { font-weight: 500; color: var(--text); }
.bar-value { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.bar-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #0ea5e9);
  border-radius: 3px;
  transition: width var(--t-slow) var(--ease-out);
}

.bar-fill.warn { background: linear-gradient(90deg, var(--warn), #f59e0b); }

/* Note */
.note {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
}

.note [data-lucide] {
  color: var(--accent);
  width: 16px; height: 16px;
  margin-top: 2px;
}

.note strong { font-weight: 600; }

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
  .search-bar { width: 220px; }
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .content { padding: 24px 16px; }
  .page-title { font-size: 28px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .kpi-grid { grid-template-columns: 1fr; }
  .search-bar { display: none; }
}
