:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --line: #dbe4ef;
  --brand: #0f4c81;
  --brand-2: #1b8a5a;
  --danger: #b42318;
  --warn: #b54708;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 0 0, #e8f2ff 0, var(--bg) 38%);
}

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

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #0a2a44 0%, #122f4d 100%);
  padding: 24px 18px;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
}

.brand {
  display: block;
  margin-bottom: 24px;
  color: #f8fafc;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 1.25rem;
}

.nav-group { margin-bottom: 16px; }
.nav-group-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  color: #94a3b8;
}

.nav-link {
  display: block;
  border-radius: 8px;
  padding: 8px 10px;
  color: #cbd5e1;
  margin-bottom: 4px;
}

.nav-link.active,
.nav-link:hover {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  text-decoration: none;
}

.sidebar-session {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.sidebar-user-info {
  min-width: 0;
}

.sidebar-user-name {
  color: #f1f5f9;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  color: #94a3b8;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-roles {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.sidebar-role {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sidebar-role-admins {
  background: rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
}

.sidebar-role-mlengineers {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.sidebar-role-marketing {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.15);
  text-decoration: none;
  transition: all 0.15s ease;
}

.sidebar-logout:hover {
  background: rgba(148, 163, 184, 0.15);
  color: #e2e8f0;
  text-decoration: none;
}

.main {
  padding: 24px;
  min-width: 0;
  overflow-x: hidden;
}

.page-header h1 {
  margin: 0;
  font-size: 1.85rem;
}

.page-header p {
  margin-top: 8px;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}

.action-tile {
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  aspect-ratio: 1;
  padding: 10px 10px 8px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--muted);
  overflow: hidden;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.action-tile svg {
  width: 55%;
  height: 55%;
  display: block;
  stroke: var(--brand);
  opacity: 0.75;
  transition: opacity 0.15s, transform 0.15s, stroke 0.15s;
}

.action-tile span {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.action-tile:hover {
  border-color: var(--brand);
  border-width: 2px;
  box-shadow: 0 2px 8px rgba(15,76,129,0.15);
}

.action-tile:hover svg {
  opacity: 1;
  transform: scale(1.08);
}

.action-tile:hover span {
  color: var(--brand);
  font-weight: 600;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 6px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 0.92rem;
}

.table th {
  background: #f8fafc;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #334155;
}

.table tr:hover td { background: #f8fbff; }

.table td.num,
.table th.num { text-align: right; }

.filters,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

textarea { min-height: 100px; }

button,
.btn {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-secondary {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-danger {
  background: #b42318;
}

button:hover,
.btn:hover { filter: brightness(0.95); text-decoration: none; }

.alert {
  border-radius: 10px;
  padding: 12px;
  margin: 12px 0;
  border: 1px solid transparent;
}

.alert-error {
  background: #fef3f2;
  color: #7a271a;
  border-color: #fecdca;
}

.alert-info {
  background: #eff8ff;
  color: #194185;
  border-color: #b2ddff;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
}

.badge-gray { background: #f1f5f9; color: #334155; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e3a8a; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

.kv {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px;
  margin: 4px 0;
}

.code {
  font-family: "IBM Plex Mono", "SFMono-Regular", ui-monospace, monospace;
  font-size: 0.82rem;
  background: #eef2ff;
  border-radius: 6px;
  padding: 2px 6px;
}

pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
}

.chart-grid {
  display: grid;
  gap: 16px;
}

.chart-stage {
  position: relative;
  height: 320px;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
  overflow: hidden;
}

.chart-stage.compact {
  height: 260px;
}

.chart-stage svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-empty {
  margin: 0;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 10px;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

.chart-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0;
}

.controls-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.86rem;
  color: var(--muted);
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}

.preset-btn {
  background: #e2e8f0;
  color: #1e293b;
  border: 1px solid #d1dae7;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.preset-btn:hover {
  background: #d9e2ee;
}

.preset-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: #edf2f8;
}

.segmented .btn {
  background: transparent;
  color: #1e293b;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 7px 10px;
}

.segmented .btn.active {
  background: #fff;
  border-color: #d3dce8;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.1);
}

.muted-note {
  color: var(--muted);
  font-size: 0.84rem;
}

.table-sort-indicator {
  color: var(--brand);
  margin-left: 4px;
  font-size: 0.7rem;
}

.login-page {
  background: radial-gradient(circle at 20% 0, #e3efff 0, var(--bg) 44%);
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-title {
  margin: 0;
  font-size: 1.8rem;
}

.login-subtitle {
  margin: 8px 0 18px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-divider {
  margin: 16px 0 12px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-actions {
  display: grid;
  gap: 8px;
}

.login-oauth {
  justify-content: center;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px 1fr; }
}

/* Mobile header — hidden on desktop */
.mobile-header {
  display: none;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 920px) {
  html, body {
    overflow-x: hidden;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    max-width: 100vw;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    width: 100%;
    box-sizing: border-box;
    background: linear-gradient(90deg, #0a2a44 0%, #122f4d 100%);
    color: #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .mobile-header .brand {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
  }

  .menu-toggle {
    background: none;
    border: none;
    color: #e2e8f0;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 88vw;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: 1px solid var(--line);
    overflow-y: auto;
  }

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

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .grid-4,
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .chart-stage {
    height: 280px;
  }
}
