:root {
  --ink: #171917;
  --ink-soft: #262a27;
  --paper: #f2f0e8;
  --surface: #ffffff;
  --surface-soft: #f7f6f0;
  --mint: #67d4b2;
  --mint-soft: #d8f3e9;
  --pink: #ee99ee;
  --lime: #cce967;
  --orange: #f3a45d;
  --muted: #6b716c;
  --line: #dedfd8;
  --danger: #ba3d48;
  --shadow: 0 24px 70px rgba(20, 28, 22, 0.12);
  --radius-lg: 24px;
  --radius-md: 15px;
  --radius-sm: 10px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body { min-width: 320px; background: var(--paper); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(480px, 1.05fr);
  background: var(--paper);
}

.auth-brand {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  padding: clamp(34px, 5vw, 72px);
  color: white;
  background:
    linear-gradient(130deg, rgba(103, 212, 178, 0.18), transparent 45%),
    radial-gradient(circle at 80% 18%, rgba(238, 153, 238, 0.18), transparent 31%),
    var(--ink);
}

.auth-brand::before,
.auth-brand::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 50%;
}
.auth-brand::before { width: 520px; height: 520px; right: -260px; bottom: -140px; }
.auth-brand::after { width: 330px; height: 330px; right: -155px; bottom: -45px; }

.brand-logo { width: 108px; height: auto; filter: drop-shadow(0 12px 22px rgba(0,0,0,.24)); }
.brand-copy { position: relative; z-index: 1; max-width: 590px; margin-top: clamp(110px, 20vh, 220px); }
.eyebrow { margin: 0 0 14px; color: var(--mint); font-size: 12px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.brand-copy h1 { margin: 0; max-width: 650px; font-size: clamp(43px, 5.3vw, 76px); line-height: .98; letter-spacing: -.055em; }
.brand-copy p { max-width: 520px; margin: 26px 0 0; color: rgba(255,255,255,.72); font-size: 17px; line-height: 1.65; }
.brand-pulse { display: flex; gap: 10px; align-items: center; margin-top: 46px; color: rgba(255,255,255,.75); font-size: 13px; }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 7px rgba(103,212,178,.12); }

.auth-panel { display: grid; place-items: center; min-width: 0; min-height: 100vh; padding: 40px; }
.auth-card { width: min(100%, 480px); min-width: 0; }
.auth-card h2 { margin: 0; font-size: clamp(34px, 4vw, 48px); letter-spacing: -.045em; }
.auth-intro { margin: 14px 0 34px; color: var(--muted); line-height: 1.6; }
.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field label { font-size: 13px; font-weight: 750; }
.field input, .field select {
  width: 100%;
  min-height: 52px;
  padding: 0 15px;
  border: 1px solid #cfd2ca;
  border-radius: 12px;
  color: var(--ink);
  background: white;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.field input:focus, .field select:focus { border-color: var(--ink); box-shadow: 0 0 0 4px rgba(103,212,178,.25); }
.password-hint { margin: -7px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.btn {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 11px;
  font-weight: 800;
  transition: transform .16s, opacity .16s, background .16s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: wait; opacity: .55; transform: none; }
.btn-primary { color: white; background: var(--ink); }
.btn-primary:hover { background: #2b302c; }
.btn-mint { color: var(--ink); background: var(--mint); }
.btn-ghost { border: 1px solid var(--line); color: var(--ink); background: transparent; }
.btn-danger { color: var(--danger); background: #fff0f1; }
.btn-wide { width: 100%; }
.form-error { min-height: 22px; margin: 8px 0 12px; color: var(--danger); font-size: 13px; font-weight: 650; }
.security-note { display: flex; gap: 11px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.5; }
.security-note svg { flex: 0 0 auto; }
.security-note span { min-width: 0; overflow-wrap: anywhere; }

.app-shell { display: grid; grid-template-columns: 258px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 26px 18px 20px; color: white; background: var(--ink); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-brand img { width: 57px; }
.sidebar-brand strong { display: block; font-size: 14px; letter-spacing: .02em; }
.sidebar-brand span { display: block; margin-top: 3px; color: rgba(255,255,255,.48); font-size: 11px; }
.nav { display: grid; gap: 6px; margin-top: 25px; overflow-y: auto; scrollbar-width: thin; }
.nav-label { padding: 0 12px 8px; color: rgba(255,255,255,.38); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.nav-button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 46px; padding: 0 13px; border: 0; border-radius: 11px; color: rgba(255,255,255,.68); background: transparent; text-align: left; font-weight: 650; }
.nav-button:hover { color: white; background: rgba(255,255,255,.07); }
.nav-button.active { color: var(--ink); background: var(--mint); }
.nav-button svg { width: 19px; height: 19px; }
.sidebar-bottom { margin-top: auto; padding: 18px 8px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-bottom p { margin: 0 0 3px; color: rgba(255,255,255,.45); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.sidebar-bottom strong { font-size: 12px; }
.sidebar-user { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 17px 4px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user > span { min-width: 0; flex: 1; overflow: hidden; color: rgba(255,255,255,.72); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-logout { display: grid; flex: 0 0 auto; place-items: center; width: 36px; height: 36px; border: 1px solid rgba(255,255,255,.15); border-radius: 10px; color: rgba(255,255,255,.72); background: transparent; }
.sidebar-logout:hover { color: var(--ink); background: var(--mint); }

.workspace { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; min-height: 82px; padding: 0 clamp(22px, 4vw, 54px); border-bottom: 1px solid var(--line); background: rgba(242,240,232,.9); backdrop-filter: blur(12px); }
.breadcrumb { color: var(--muted); font-size: 13px; }
.breadcrumb strong { color: var(--ink); }
.data-freshness { color: var(--muted); font-size: 11px; }
.profile { display: flex; align-items: center; gap: 12px; }
.profile-text { text-align: right; }
.profile-text strong { display: block; font-size: 13px; }
.profile-text span { color: var(--muted); font-size: 11px; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--pink); font-weight: 850; }
.logout-button { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: transparent; }

.content { padding: clamp(28px, 4vw, 54px); }
.source-banner { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; padding: 12px 16px; border: 1px solid #b9e4d5; border-radius: 12px; color: #245f4d; background: var(--mint-soft); font-size: 12px; line-height: 1.45; }
.source-banner strong { flex: 0 0 auto; padding: 5px 9px; border-radius: 7px; color: white; background: #176f57; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.page-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 30px; }
.page-heading h1 { margin: 0; font-size: clamp(32px, 4vw, 48px); letter-spacing: -.045em; }
.page-heading p { margin: 10px 0 0; color: var(--muted); }
.status-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 31px; padding: 0 11px; border-radius: 999px; background: var(--mint-soft); font-size: 11px; font-weight: 800; }
.status-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #1b956f; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; }
.metric-grid-four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card { position: relative; overflow: hidden; min-height: 174px; padding: 23px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.metric-card.accent { color: white; border-color: var(--ink); background: var(--ink); }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.accent .metric-label { color: rgba(255,255,255,.52); }
.metric-value { margin-top: 25px; font-size: 30px; font-weight: 820; letter-spacing: -.04em; }
.metric-description { margin-top: 10px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.accent .metric-description { color: rgba(255,255,255,.58); }
.metric-card .orb { position: absolute; width: 100px; height: 100px; right: -30px; bottom: -34px; border-radius: 50%; background: var(--mint); opacity: .2; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); gap: 17px; margin-top: 17px; }
.analytics-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; margin-top: 17px; }
.overview-grid { grid-template-columns: minmax(0, 1.7fr) minmax(290px, .7fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.panel { padding: 25px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.panel h2 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.panel-subtitle { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.empty-chart { position: relative; display: grid; place-items: center; min-height: 285px; margin-top: 24px; overflow: hidden; border-radius: 12px; background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px); background-size: 44px 44px; }
.empty-chart::before { content: ""; position: absolute; inset: 30% 7% auto; height: 3px; transform: rotate(-3deg); background: linear-gradient(90deg, transparent, var(--mint), var(--pink), transparent); opacity: .5; }
.empty-chart-copy { position: relative; max-width: 320px; padding: 22px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.94); text-align: center; box-shadow: 0 14px 30px rgba(0,0,0,.07); }
.empty-chart-copy strong { display: block; margin-bottom: 7px; }
.empty-chart-copy span { color: var(--muted); font-size: 12px; line-height: 1.5; }
.chart-panel { min-width: 0; overflow: hidden; }
.chart { width: 100%; height: 320px; margin-top: 14px; }
.chart-tall { height: 390px; }
.chart-xl { height: 520px; }
.map-chart { height: 680px; }
.map-side-chart { height: 680px; }
.filter-bar { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 20px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.filter-field { display: grid; flex: 0 0 165px; gap: 7px; min-width: 0; }
.filter-field.grow { flex: 1 1 260px; }
.filter-field label { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.filter-field input, .filter-field select { width: 100%; min-width: 0; height: 43px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; }
.filter-submit, .export-button { min-height: 43px; white-space: nowrap; }
.export-button { display: inline-flex; align-items: center; gap: 8px; }
.export-button.busy::before { content: ""; width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .7s linear infinite; }
.export-button.busy svg { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-panel, .error-panel { display: grid; min-height: 280px; place-items: center; margin-top: 17px; border: 1px solid var(--line); border-radius: var(--radius-md); color: var(--muted); background: var(--surface); }
.error-panel { color: var(--danger); }
.insight-note, .auth-notice { margin: 17px 0 0; padding: 13px 16px; border: 1px solid #bee6d8; border-radius: 11px; color: #276552; background: var(--mint-soft); font-size: 12px; line-height: 1.5; }
.auth-notice { margin: -14px 0 22px; }
.period-warning { margin: 0 0 17px; padding: 12px 15px; border: 1px solid #f0d28c; border-radius: 11px; color: #76550d; background: #fff6d8; font-size: 12px; }
.chart-tooltip-title { margin-bottom: 8px; color: rgba(255,255,255,.7); font-size: 11px; font-weight: 750; }
.chart-tooltip-row { display: flex; justify-content: space-between; align-items: center; gap: 22px; min-width: 170px; margin-top: 5px; }
.chart-tooltip-row span { display: flex; align-items: center; gap: 7px; }
.chart-tooltip-row i { width: 8px; height: 8px; border-radius: 50%; }
.chart-tooltip-row strong { font-variant-numeric: tabular-nums; }
.row-count { color: var(--muted); font-size: 12px; font-weight: 750; }
.table-scroll { width: 100%; overflow-x: auto; }
.timeline { display: grid; gap: 18px; margin-top: 24px; }
.timeline-item { display: grid; grid-template-columns: 12px 1fr; gap: 13px; }
.timeline-dot { width: 10px; height: 10px; margin-top: 4px; border: 2px solid white; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 2px var(--line); }
.timeline-dot.ready { background: #299c74; box-shadow: 0 0 0 2px var(--mint-soft); }
.timeline-item strong { display: block; font-size: 13px; }
.timeline-item p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

.table-panel { overflow: hidden; padding: 0; }
.table-tools { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 15px 20px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.data-table th { color: var(--muted); background: var(--surface-soft); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.data-table tr:last-child td { border-bottom: 0; }
.role-badge, .state-badge { display: inline-flex; min-height: 25px; align-items: center; padding: 0 9px; border-radius: 999px; background: var(--surface-soft); font-size: 10px; font-weight: 800; }
.role-select { min-height: 34px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: white; font-size: 11px; font-weight: 750; }
.state-badge.active { color: #157657; background: var(--mint-soft); }
.state-badge.invited { color: #785914; background: #fff0b9; }
.state-badge.disabled { color: var(--danger); background: #ffe7e9; }
.table-actions { display: flex; gap: 7px; }
.icon-btn { min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: white; font-size: 11px; font-weight: 750; }
.icon-btn.danger { color: var(--danger); }
.permission-badges { display: flex; flex-wrap: wrap; gap: 5px; min-width: 220px; }
.permission-badges span { padding: 4px 7px; border-radius: 6px; color: #315c4e; background: var(--mint-soft); font-size: 9px; font-weight: 750; }
.permission-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 18px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
.permission-grid legend { padding: 0 7px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.permission-grid label { display: flex; align-items: center; gap: 9px; min-height: 38px; padding: 7px 9px; border-radius: 8px; background: var(--surface-soft); font-size: 12px; font-weight: 650; }
.permission-grid input { accent-color: var(--ink); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-wide { width: min(100%, 680px); }
.user-modal-identity { display: grid; gap: 4px; margin-bottom: 20px; padding: 14px; border-radius: 10px; background: var(--surface-soft); }
.user-modal-identity span { color: var(--muted); font-size: 12px; }
.geo-grid { grid-template-columns: minmax(0, 1.5fr) minmax(330px, .75fr); }

.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px; background: rgba(15,17,15,.58); backdrop-filter: blur(7px); }
.modal { width: min(100%, 520px); padding: 27px; border-radius: 20px; background: white; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 8px; font-size: 24px; }
.modal > p { margin: 0 0 24px; color: var(--muted); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.link-box { padding: 13px; border: 1px dashed #a9ada5; border-radius: 10px; background: var(--surface-soft); word-break: break-all; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; line-height: 1.5; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: 390px; padding: 14px 17px; border-radius: 11px; color: white; background: var(--ink); box-shadow: var(--shadow); font-size: 13px; }
.hidden { display: none !important; }

@media (max-width: 980px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { min-height: 330px; }
  .brand-copy { margin-top: 65px; }
  .auth-panel { min-height: auto; }
  .app-shell { grid-template-columns: 84px minmax(0,1fr); }
  .sidebar-brand strong, .sidebar-brand span, .nav-button span, .nav-label, .sidebar-bottom { display: none; }
  .sidebar-brand { justify-content: center; padding-inline: 0; }
  .nav-button { justify-content: center; padding: 0; }
  .metric-grid { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .metric-grid-four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-grid, .overview-grid { grid-template-columns: 1fr; }
  .geo-grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .filter-bar { flex-wrap: wrap; }
  .filter-field, .filter-field.grow { flex: 1 1 220px; }
  .sidebar-user > span { display: none; }
  .map-chart, .map-side-chart { height: 560px; }
}

@media (max-width: 640px) {
  .auth-brand { min-height: 285px; padding: 28px; }
  .brand-logo { width: 76px; }
  .brand-copy { margin-top: 48px; }
  .brand-copy h1 { font-size: 39px; }
  .brand-copy p, .brand-pulse { display: none; }
  .auth-panel { padding: 32px 22px 50px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 5; inset: auto 0 0; flex-direction: row; width: 100%; height: 67px; padding: 8px 12px; }
  .sidebar-brand, .sidebar-bottom, .nav-label { display: none; }
  .sidebar-user { margin: 0; padding: 0; border: 0; }
  .sidebar-user > span { display: none; }
  .sidebar-logout { width: 50px; height: 50px; }
  .nav { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; margin: 0; }
  .nav-button { min-height: 50px; }
  .nav-button span { display: none; }
  .topbar { min-height: 68px; padding-inline: 18px; }
  .profile-text { display: none; }
  .data-freshness { display: none; }
  .content { padding: 25px 17px 95px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .table-panel { overflow-x: auto; }
  .data-table { min-width: 760px; }
  .metric-grid-four { grid-template-columns: 1fr; }
  .filter-bar { display: grid; grid-template-columns: 1fr 1fr; }
  .filter-field, .filter-field.grow { width: auto; }
  .filter-field.grow { grid-column: 1 / -1; }
  .filter-submit, .export-button { width: 100%; justify-content: center; }
  .source-banner { align-items: flex-start; }
  .permission-grid, .form-row { grid-template-columns: 1fr; }
  .map-chart, .map-side-chart { height: 480px; }
}
