:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #12202b;
  --muted: #6c7983;
  --line: #dfe5e9;
  --brand: #086f6a;
  --brand-soft: #ddf2ef;
  --accent: #d79b4a;
  --danger: #a94a4a;
  --shadow: 0 14px 40px rgba(26, 44, 55, .08);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #081017;
  --surface: #101b24;
  --surface-2: #17242e;
  --text: #edf4f3;
  --muted: #93a2aa;
  --line: #253540;
  --brand: #54c7bb;
  --brand-soft: #153d3b;
  --accent: #e3ad62;
  --danger: #ef8888;
  --shadow: 0 16px 48px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "SF Arabic", "Geeza Pro", "Noto Sans Arabic", Arial, sans-serif; }
button, select, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.login-shell { min-height: 100vh; min-height: 100svh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 70% 12%, var(--brand-soft), transparent 38%), var(--bg); }
.login-card { width: min(100%, 410px); padding: 48px 32px; text-align: center; border: 1px solid var(--line); border-radius: 32px; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow); }
.brand-mark, .mini-mark { display: inline-flex; align-items: end; gap: 5px; color: var(--brand); }
.brand-mark { height: 52px; margin-bottom: 22px; }
.brand-mark span, .mini-mark i { display: block; width: 9px; border-radius: 8px; background: currentColor; }
.brand-mark span:nth-child(1), .mini-mark i:nth-child(1) { height: 38%; opacity: .5; }
.brand-mark span:nth-child(2), .mini-mark i:nth-child(2) { height: 70%; opacity: .72; }
.brand-mark span:nth-child(3), .mini-mark i:nth-child(3) { height: 100%; }
.login-card h1 { margin: 4px 0 6px; font-size: clamp(2rem, 10vw, 3.3rem); letter-spacing: -.04em; }
.login-copy { color: var(--muted); margin: 0 0 28px; }
.google-button { min-height: 44px; display: grid; place-items: center; }
.form-message { color: var(--danger); min-height: 24px; margin: 18px 0 0; font-size: .9rem; }

.eyebrow { margin: 0; color: var(--brand); font-size: .72rem; font-weight: 800; letter-spacing: .14em; }
.app-shell { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; height: 68px; display: flex; align-items: center; justify-content: space-between; padding: max(12px, env(safe-area-inset-top)) 18px 10px; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(18px); border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent); }
.wordmark { display: flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; }
.wordmark b { display: block; font-size: 1.05rem; }
.wordmark small { display: block; color: var(--muted); font-size: .56rem; letter-spacing: .14em; }
.mini-mark { height: 30px; }
.mini-mark i { width: 5px; }
.top-actions { display: flex; gap: 8px; }
.icon-button, .text-button { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 13px; min-height: 40px; padding: 0 13px; cursor: pointer; }
.icon-button { width: 40px; padding: 0; }
.sidebar { display: none; }
.main-content { padding: 22px 16px calc(92px + var(--safe-bottom)); max-width: 1480px; margin: 0 auto; }
.dashboard-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.dashboard-head h1 { margin: 3px 0 0; font-size: clamp(1.6rem, 7vw, 2.4rem); letter-spacing: -.035em; }
.date-tools { display: grid; gap: 4px; }
.date-tools label { color: var(--muted); font-size: .7rem; }
select, input[type="date"] { min-height: 44px; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: var(--surface); padding: 0 12px; }
.custom-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.custom-range label { display: grid; gap: 5px; color: var(--muted); font-size: .78rem; }
.primary-button { grid-column: 1 / -1; min-height: 44px; border: 0; border-radius: 14px; color: #fff; background: var(--brand); font-weight: 700; }
.freshness { min-height: 27px; margin-bottom: 12px; color: var(--muted); font-size: .76rem; }
.provisional { display: inline-flex; margin-inline-start: 8px; padding: 3px 8px; border-radius: 999px; color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); font-weight: 700; }

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.metric-card { min-height: 128px; padding: 17px 15px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 24px rgba(22, 41, 53, .035); }
.metric-card.primary { grid-column: 1 / -1; min-height: 154px; background: linear-gradient(145deg, var(--brand-soft), var(--surface) 72%); }
.metric-label { display: block; min-height: 42px; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.metric-value { display: block; margin-top: 8px; font-size: clamp(1.35rem, 6vw, 2rem); font-weight: 850; letter-spacing: -.045em; direction: ltr; text-align: right; }
.metric-card.primary .metric-value { font-size: clamp(2rem, 10vw, 3.2rem); color: var(--brand); }
.metric-foot { display: block; margin-top: 8px; color: var(--muted); font-size: .68rem; }
.section-grid { display: grid; gap: 13px; margin-top: 15px; }
.panel { overflow: hidden; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 30px rgba(22, 41, 53, .035); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.panel h2 { margin: 0; font-size: 1rem; }
.panel-sub { margin: 4px 0 0; color: var(--muted); font-size: .74rem; }
.chart { height: 190px; display: flex; align-items: end; gap: 8px; direction: ltr; }
.bar-column { flex: 1; min-width: 8px; display: grid; align-items: end; height: 100%; gap: 5px; }
.bar { width: 100%; min-height: 3px; border-radius: 7px 7px 3px 3px; background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 58%, transparent)); }
.bar-label { overflow: hidden; color: var(--muted); font-size: .58rem; text-align: center; white-space: nowrap; }
.source-list { display: grid; gap: 13px; }
.source-row { display: grid; grid-template-columns: minmax(90px, 1.3fr) 2fr auto; align-items: center; gap: 10px; }
.source-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
.track { height: 7px; overflow: hidden; border-radius: 999px; background: var(--surface-2); direction: ltr; }
.track i { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.source-value { color: var(--muted); font-size: .72rem; direction: ltr; }
.data-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.data-table th, .data-table td { padding: 12px 9px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.data-table th { position: sticky; top: 0; color: var(--muted); background: var(--surface); font-weight: 700; }
.data-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.table-wrap { overflow: auto; max-height: 65vh; }
.funnel { display: grid; gap: 12px; }
.funnel-step { padding: 16px; border-radius: 18px; background: var(--surface-2); }
.funnel-top { display: flex; justify-content: space-between; gap: 10px; }
.funnel-drop { margin-top: 8px; color: var(--muted); font-size: .72rem; }
.empty-state, .error-state { padding: 44px 20px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.skeleton-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.skeleton { height: 128px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 220% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -220% 0; } }

.bottom-nav { position: fixed; z-index: 40; inset: auto 0 0; display: grid; grid-template-columns: repeat(5, 1fr); padding: 7px 8px calc(7px + var(--safe-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(22px); }
.nav-link { display: grid; justify-items: center; gap: 3px; min-height: 50px; padding: 6px 2px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; text-decoration: none; font-size: .64rem; }
.nav-link span { font-size: 1.1rem; line-height: 1; }
.nav-link.active { color: var(--brand); background: var(--brand-soft); font-weight: 800; }

@media (min-width: 760px) {
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metric-card.primary { grid-column: span 2; }
  .section-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel.wide { grid-column: 1 / -1; }
  .skeleton-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1060px) {
  .topbar { padding-inline: 30px; }
  .sidebar { position: fixed; inset: 68px 0 0 auto; display: block; width: 232px; padding: 24px 16px; border-left: 1px solid var(--line); background: var(--surface); }
  .sidebar nav { display: grid; gap: 5px; }
  .sidebar .nav-link { grid-template-columns: 26px 1fr; justify-items: start; align-items: center; padding: 10px 13px; min-height: 46px; font-size: .84rem; }
  .main-content { margin-right: 232px; padding: 34px 36px 70px; }
  .bottom-nav { display: none; }
  .metric-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .metric-card.primary { grid-column: span 2; }
}
