/* ============================================================
   iRawda Sales Intelligence — style.css
   Premium dark SaaS dashboard, purple neon, glassmorphism.
   ============================================================ */

/* ---------- Theme tokens ---------- */
:root {
  --bg:            #0b0b16;
  --bg-2:          #0f0f1f;
  --card:          #16162a;
  --card-2:        #1c1c34;
  --text:          #f4f4fb;
  --muted:         #9a9ab8;
  --border:        rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);
  --primary:       #7c3aed;
  --primary-bright:#a78bfa;
  --accent:        #22d3ee;
  --success:       #34d399;
  --warning:       #fbbf24;
  --danger:        #f87171;
  --glow:          rgba(124,58,237,.35);
  --shadow:        0 18px 50px -20px rgba(0,0,0,.7);
  --radius:        18px;
  --radius-sm:     12px;
  --font:          'Public Sans','Inter',system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
  --fs-base:       15px;
  --sidebar-w:     264px;
  --sidebar-cw:    74px;
}

[data-theme="light"] {
  --bg:            #f4f5fb;
  --bg-2:          #eceef7;
  --card:          #ffffff;
  --card-2:        #f7f8fd;
  --text:          #1a1a2e;
  --muted:         #5d5d7a;
  --border:        rgba(20,20,50,.10);
  --border-strong: rgba(20,20,50,.18);
  --primary:       #7c3aed;
  --primary-bright:#6d28d9;
  --accent:        #0891b2;
  --success:       #059669;
  --warning:       #d97706;
  --danger:        #dc2626;
  --glow:          rgba(124,58,237,.18);
  --shadow:        0 16px 40px -22px rgba(60,40,120,.35);
}

[data-contrast="high"] {
  --border:        rgba(255,255,255,.22);
  --muted:         #c2c2dd;
}
[data-theme="light"][data-contrast="high"] {
  --border:        rgba(20,20,50,.28);
  --muted:         #3a3a55;
}

[data-compact="on"] { --fs-base: 13.5px; --radius: 14px; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html,body { height: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fs-base);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body[data-rtl="on"] { direction: rtl; }

/* ambient background glow */
body::before {
  content:""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(700px 400px at 12% -5%, rgba(124,58,237,.22), transparent 60%),
    radial-gradient(600px 500px at 100% 0%, rgba(34,211,238,.10), transparent 55%),
    radial-gradient(800px 600px at 60% 110%, rgba(167,139,250,.10), transparent 60%);
}
[data-theme="light"] body::before { opacity:.6; }

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

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  position: relative; z-index: 1;
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 36px 30px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.login-logo {
  width: 76px; height: 76px; border-radius: 18px; margin: 0 auto 18px; display: block;
  object-fit: contain; background: #0a0a14; padding: 4px;
  box-shadow: 0 0 30px var(--glow);
}
.login-card h1 { font-size: 1.35rem; text-align: center; letter-spacing:-.01em; }
.login-card .sub { text-align: center; color: var(--muted); margin: 6px 0 26px; font-size: .9rem; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 7px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  font-size: .95rem; transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  outline: none; border-color: var(--primary-bright);
  box-shadow: 0 0 0 3px var(--glow);
}
.btn-primary {
  width: 100%; padding: 12px 16px; border: none; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--primary-bright));
  color: #fff; font-weight: 600; font-size: .95rem;
  box-shadow: 0 10px 28px -10px var(--glow); transition: transform .15s, box-shadow .2s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 34px -8px var(--glow); }
.btn-primary:active { transform: translateY(0); }
.login-hint { margin-top: 18px; font-size: .78rem; color: var(--muted); text-align: center; line-height: 1.7; }
.login-error {
  background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.4);
  color: var(--danger); padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: .85rem; margin-bottom: 16px; display: none;
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app { display: none; position: relative; z-index: 1; min-height: 100vh; }
.app.active { display: block; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width .28s cubic-bezier(.4,0,.2,1), transform .28s cubic-bezier(.4,0,.2,1);
  z-index: 60; overflow: hidden;
}
body[data-collapsed="on"] .sidebar { width: var(--sidebar-cw); }

.sb-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px; min-height: 70px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.sb-logo { width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0; object-fit: contain; background: #0a0a14; box-shadow: 0 0 18px var(--glow); }
.sb-brand { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; overflow: hidden; }
.sb-brand b { font-size: .98rem; letter-spacing: -.01em; }
.sb-brand span { font-size: .68rem; color: var(--muted); }
body[data-collapsed="on"] .sb-brand { opacity: 0; width: 0; }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 10px; }
.sb-section { margin-bottom: 6px; }
.nav-parent {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 12px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--muted); font-size: .9rem; font-weight: 600;
  position: relative; transition: background .18s, color .18s;
}
.nav-parent:hover { background: var(--card-2); color: var(--text); }
.nav-parent .ico { width: 20px; height: 20px; flex-shrink: 0; }
.nav-parent .label { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; }
.nav-parent .chev { width: 16px; height: 16px; transition: transform .2s; opacity: .7; }
.nav-parent.open .chev { transform: rotate(90deg); }
body[data-rtl="on"] .nav-parent .label { text-align: right; }
body[data-collapsed="on"] .nav-parent .label,
body[data-collapsed="on"] .nav-parent .chev { opacity: 0; width: 0; }
body[data-collapsed="on"] .nav-parent { justify-content: center; padding: 11px 0; }

.submenu { overflow: hidden; max-height: 0; transition: max-height .26s ease; }
.submenu.open { max-height: 420px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px 9px 44px; border: none; background: transparent;
  color: var(--muted); font-size: .86rem; border-radius: var(--radius-sm);
  text-align: left; transition: background .16s, color .16s;
}
body[data-rtl="on"] .nav-item { padding: 9px 44px 9px 12px; text-align: right; }
.nav-item:hover { background: var(--card-2); color: var(--text); }
.nav-item.active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-bright));
  box-shadow: 0 8px 22px -10px var(--glow);
}
.nav-single .nav-parent.active {
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-bright));
  box-shadow: 0 8px 22px -10px var(--glow);
}
body[data-collapsed="on"] .submenu { position: absolute; left: var(--sidebar-cw); }
body[data-collapsed="on"] .submenu { max-height: 0; }

/* collapsed tooltip */
.nav-parent[data-tip]::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 10px); top: 50%;
  transform: translateY(-50%) scale(.9); transform-origin: left center;
  background: var(--card-2); color: var(--text); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 8px; font-size: .78rem; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 80;
  box-shadow: var(--shadow);
}
body[data-collapsed="on"] .nav-parent:hover[data-tip]::after { opacity: 1; transform: translateY(-50%) scale(1); }

/* user card */
.sb-user {
  border-top: 1px solid var(--border); padding: 14px; position: relative;
}
.user-row { display: flex; align-items: center; gap: 11px; }
.user-av {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-bright));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .95rem;
  box-shadow: 0 0 16px var(--glow);
}
.user-meta { flex: 1; overflow: hidden; }
.user-meta b { display: block; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { display: block; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-tag {
  display: inline-block; margin-top: 4px; font-size: .64rem; font-weight: 700;
  padding: 2px 8px; border-radius: 20px; letter-spacing: .04em;
  background: rgba(124,58,237,.18); color: var(--primary-bright); border: 1px solid rgba(124,58,237,.3);
}
.user-actions { display: flex; gap: 8px; margin-top: 12px; }
.ua-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card-2); color: var(--text); font-size: .76rem; font-weight: 600;
  transition: border-color .16s, background .16s;
}
.ua-btn:hover { border-color: var(--primary-bright); background: var(--card); }
.ua-btn .ico { width: 16px; height: 16px; }
body[data-collapsed="on"] .user-meta,
body[data-collapsed="on"] .ua-btn .txt { display: none; }
body[data-collapsed="on"] .user-row { justify-content: center; }
body[data-collapsed="on"] .user-actions { flex-direction: column; }
body[data-collapsed="on"] .ua-btn { padding: 8px 0; }

/* ---------- main ---------- */
.main {
  margin-left: var(--sidebar-w); transition: margin-left .28s cubic-bezier(.4,0,.2,1);
  min-height: 100vh; display: flex; flex-direction: column;
}
body[data-collapsed="on"] .main { margin-left: var(--sidebar-cw); }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 16px 26px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px); border-bottom: 1px solid var(--border);
}
.icon-btn {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 11px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); display: grid; place-items: center;
  transition: border-color .16s, transform .12s;
}
.icon-btn:hover { border-color: var(--primary-bright); }
.icon-btn:active { transform: scale(.94); }
.icon-btn .ico { width: 20px; height: 20px; }
.topbar h2 { font-size: 1.15rem; letter-spacing: -.01em; }
.topbar .greet { color: var(--muted); font-size: .82rem; }
.topbar-spacer { flex: 1; }

.search-global {
  display: flex; align-items: center; gap: 8px; padding: 9px 13px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  min-width: 200px;
}
.search-global input { background: transparent; border: none; color: var(--text); outline: none; flex:1; font-size:.86rem; }
.search-global .ico { width: 17px; height: 17px; color: var(--muted); }

/* date filter */
.date-filter { position: relative; }
.df-btn {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: .85rem; font-weight: 600;
}
.df-btn:hover { border-color: var(--primary-bright); }
.df-btn .ico { width: 17px; height: 17px; color: var(--primary-bright); }
.df-clear { display: none; margin-left: 4px; width: 18px; height: 18px; border-radius: 50%; font-size: .7rem;
  align-items: center; justify-content: center; color: var(--muted); background: var(--card-2); }
.df-btn.has-custom .df-clear { display: inline-flex; }
.df-clear:hover { color: var(--danger); }

.df-menu {
  position: absolute; top: calc(100% + 8px); right: 0; width: 320px;
  background: var(--card); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; z-index: 50; display: none;
}
.df-menu.open { display: block; animation: pop .16s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.df-view[hidden] { display: none; }

.df-section { font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 2px 6px 8px; }
.df-opt {
  display: block; width: 100%; text-align: left; padding: 11px 12px; border: none;
  background: transparent; color: var(--text); border-radius: 10px; font-size: .92rem; font-weight: 600;
  transition: background .12s;
}
.df-opt:hover { background: var(--card-2); }
.df-opt.active { background: var(--primary); color: #fff; }
.df-divider { height: 1px; background: var(--border); margin: 8px 0; }
.df-custom-trigger {
  display: block; width: 100%; text-align: center; padding: 12px; border: none;
  background: transparent; color: var(--text); border-radius: 10px; font-size: .92rem; font-weight: 700; cursor: pointer;
}
.df-custom-trigger:hover { background: var(--card-2); color: var(--primary-bright); }

/* calendar view */
.cal-topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.cal-back { background: transparent; border: none; color: var(--text); font-size: .9rem; font-weight: 600; cursor: pointer; padding: 4px 2px; }
.cal-back:hover { color: var(--primary-bright); }
.cal-month { font-weight: 700; font-size: .9rem; }
.cal-arrows { display: flex; gap: 6px; }
.cal-nav { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); background: var(--card-2); color: var(--text); cursor: pointer; font-size: 1.05rem; line-height: 1; }
.cal-nav:hover { border-color: var(--primary-bright); color: var(--primary-bright); }
.cal-step { font-size: .82rem; color: var(--muted); margin: 10px 2px 12px; }
.cal { user-select: none; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .68rem; color: var(--muted); font-weight: 700; padding: 2px 0 6px; }
.cal-day { aspect-ratio: 1; display: grid; place-items: center; font-size: .86rem; font-weight: 600; border-radius: 10px; cursor: pointer; color: var(--text); border: 1px solid transparent; background: var(--card-2); transition: background .12s, color .12s; }
.cal-day:hover { background: var(--primary); color: #fff; }
.cal-day.muted { color: var(--muted); opacity: .35; background: transparent; cursor: default; }
.cal-day.muted:hover { background: transparent; color: var(--muted); }
.cal-day.in-range { background: rgba(124,58,237,.22); border-radius: 4px; color: var(--text); }
.cal-day.range-start, .cal-day.range-end { background: #fff; color: #111; border-radius: 10px; }
.cal-day.today { border-color: var(--primary-bright); }
.cal-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; min-height: 20px; }
.cal-today { background: transparent; border: none; color: var(--muted); font-size: .82rem; font-weight: 600; cursor: pointer; margin-left: auto; }
.cal-today:hover { color: var(--primary-bright); }
.df-err { color: var(--danger); font-size: .78rem; display: none; }
.df-err.show { display: block; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: .84rem; font-weight: 600;
}
.btn-ghost:hover { border-color: var(--primary-bright); }
.btn-ghost .ico { width: 16px; height: 16px; }

/* content */
.content { padding: 26px; flex: 1; }
.page { display: none; animation: fade .25s ease; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.range-pill {
  display: inline-flex; align-items: center; gap: 7px; font-size: .78rem; color: var(--muted);
  background: var(--card); border: 1px solid var(--border); padding: 5px 12px; border-radius: 20px;
  margin-bottom: 18px;
}
.range-pill b { color: var(--primary-bright); }

/* grids */
.grid { display: grid; gap: 18px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }

/* cards */
.card {
  background: linear-gradient(160deg, var(--card), var(--card-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; position: relative; overflow: hidden;
  box-shadow: var(--shadow); transition: transform .2s, border-color .2s, box-shadow .2s;
}
.card::after {
  content:""; position: absolute; top: -40%; right: -20%; width: 200px; height: 200px;
  background: radial-gradient(circle, var(--glow), transparent 70%); opacity: .5; pointer-events: none;
}
.card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: 0 24px 60px -22px rgba(0,0,0,.7); }
.card h3 { font-size: .82rem; color: var(--muted); font-weight: 600; margin-bottom: 14px; display:flex; align-items:center; gap:8px; }
/* base icon size — prevents inline SVGs (e.g. in card titles) from blowing up */
.ico { width: 18px; height: 18px; flex-shrink: 0; }
.card h3 .ico, .card-head h3 .ico { width: 17px; height: 17px; color: var(--primary-bright); }
.card canvas { max-width: 100%; }
/* fixed height for chart canvases (Chart.js maintainAspectRatio:false needs it) */
.card > canvas { height: 260px !important; }
#chSales, #chGp, #cSales, #cGp { height: 260px !important; }

/* stat card */
.stat .label { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.stat .label .dot { width: 9px; height: 9px; border-radius: 4px; background: var(--primary-bright); box-shadow: 0 0 10px var(--primary-bright); }
.stat .value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; margin: 10px 0 4px; }
.stat .meta { font-size: .76rem; color: var(--muted); }
.stat .meta b { color: var(--success); }

.mini-icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: rgba(124,58,237,.14); color: var(--primary-bright); margin-bottom: 12px;
}
.mini-icon .ico { width: 20px; height: 20px; }

/* channel chips */
.chip-list { display: flex; flex-direction: column; gap: 11px; }
.chip-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chip-row .name { display: flex; align-items: center; gap: 9px; font-size: .85rem; }
.chip-row .name i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.chip-row .bar { flex: 1; height: 6px; background: var(--bg-2); border-radius: 6px; overflow: hidden; margin: 0 6px; }
.chip-row .bar > span { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg,var(--primary),var(--primary-bright)); }
.chip-row .val { font-size: .82rem; font-weight: 600; white-space: nowrap; }

/* insight cards */
.insight { display: flex; align-items: center; gap: 14px; }
.insight .ic { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; flex-shrink: 0; }
.insight .tx b { display: block; font-size: 1.02rem; letter-spacing: -.01em; }
.insight .tx span { font-size: .76rem; color: var(--muted); }

/* tables */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .84rem; min-width: 520px; }
table.tbl th {
  text-align: left; padding: 11px 14px; color: var(--muted); font-weight: 600;
  font-size: .76rem; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); cursor: pointer; white-space: nowrap;
}
table.tbl th:hover { color: var(--text); }
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl tbody tr:hover { background: var(--card-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
.rank-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: var(--card-2); font-size: .76rem; font-weight: 700; color: var(--primary-bright); }

.seg-tag { font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.seg-New     { background: rgba(34,211,238,.15); color: var(--accent); }
.seg-Repeat  { background: rgba(52,211,153,.15); color: var(--success); }
.seg-VIP     { background: rgba(167,139,250,.18); color: var(--primary-bright); }
.seg-Dormant { background: rgba(248,113,113,.15); color: var(--danger); }

/* toggle buttons */
.seg-ctl { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-ctl button { padding: 6px 13px; border: none; background: transparent; color: var(--muted); font-size: .78rem; font-weight: 600; border-radius: 8px; }
.seg-ctl button.active { background: var(--primary); color: #fff; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: .95rem; color: var(--text); }

canvas { max-width: 100%; }

/* pagination */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.pager .info { font-size: .8rem; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; }
.pager button { padding: 7px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: .82rem; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
.pager button:not(:disabled):hover { border-color: var(--primary-bright); }

/* table toolbar */
.tbl-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.tbl-tools .search-global { min-width: 180px; flex: 1; max-width: 320px; }
.select {
  padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: .84rem;
}

/* ============================================================
   SETTINGS DRAWER
   ============================================================ */
.overlay {
  position: fixed; inset: 0; background: rgba(5,5,15,.55); backdrop-filter: blur(3px);
  z-index: 90; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 92vw;
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border-left: 1px solid var(--border-strong); z-index: 95;
  transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer.show { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 20px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { font-size: 1.05rem; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.set-group { margin-bottom: 24px; }
.set-group > label { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: block; margin-bottom: 12px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--border); }
.toggle-row span { font-size: .88rem; }
.switch { position: relative; width: 44px; height: 25px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--bg-2); border: 1px solid var(--border); border-radius: 30px; transition: .2s; }
.slider::before { content:""; position: absolute; height: 17px; width: 17px; left: 3px; top: 3px; background: var(--muted); border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(19px); background: #fff; }

.opt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.opt-chip {
  padding: 9px; border-radius: 10px; border: 1px solid var(--border); background: var(--card-2);
  color: var(--text); font-size: .8rem; text-align: center; transition: border-color .15s;
}
.opt-chip.active { border-color: var(--primary-bright); background: rgba(124,58,237,.14); color: var(--primary-bright); }
.preset-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.preset-sw { aspect-ratio: 1; border-radius: 10px; border: 2px solid transparent; cursor: pointer; }
.preset-sw.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--primary); }
.range-input { width: 100%; accent-color: var(--primary); }
.drawer-foot { padding: 16px 20px; border-top: 1px solid var(--border); }
.btn-reset { width: 100%; padding: 11px; border-radius: var(--radius-sm); border: 1px solid var(--danger); background: transparent; color: var(--danger); font-weight: 600; font-size: .85rem; }
.btn-reset:hover { background: rgba(248,113,113,.1); }

/* ============================================================
   IMPORT
   ============================================================ */
.import-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 40px 24px; text-align: center; transition: border-color .2s, background .2s; cursor: pointer;
  min-height: 180px; width: 100%;
}
.import-zone:hover, .import-zone.drag { border-color: var(--primary-bright); background: rgba(124,58,237,.06); }
.import-zone .ico { width: 40px; height: 40px; color: var(--primary-bright); margin-bottom: 12px; }
.import-zone b { display: block; margin-bottom: 4px; }
.import-zone span { font-size: .82rem; color: var(--muted); }
.type-tabs { display: inline-flex; flex-wrap: wrap; background: var(--bg-2); border: 1px solid var(--border); border-radius: 11px; padding: 4px; gap: 4px; margin-bottom: 16px; max-width: 100%; }
.type-tabs button { padding: 9px 18px; border: none; background: transparent; color: var(--muted); font-weight: 600; font-size: .85rem; border-radius: 8px; }
.type-tabs button.active { background: var(--primary); color: #fff; }

.map-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.map-row .field-name { font-size: .85rem; font-weight: 600; }
.map-row .field-name small { display: block; color: var(--muted); font-weight: 400; font-size: .72rem; }

.result-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
.result-box { text-align: center; padding: 16px; border-radius: var(--radius-sm); background: var(--card-2); border: 1px solid var(--border); }
.result-box .n { font-size: 1.5rem; font-weight: 700; }
.result-box .l { font-size: .74rem; color: var(--muted); margin-top: 3px; }
.result-box.ok .n { color: var(--success); }
.result-box.dup .n { color: var(--warning); }
.result-box.err .n { color: var(--danger); }

/* status badges */
.badge { font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.badge.success, .badge.completed { background: rgba(52,211,153,.15); color: var(--success); }
.badge.failed { background: rgba(248,113,113,.15); color: var(--danger); }
.badge.pending { background: rgba(251,191,36,.15); color: var(--warning); }
.badge.reverted { background: rgba(148,163,184,.15); color: var(--muted); }
.undo-btn { display:inline-flex; align-items:center; gap:5px; padding:5px 11px; border-radius:8px;
  border:1px solid var(--border); background:var(--card-2); color:var(--text); font-size:.74rem; font-weight:600; cursor:pointer; white-space:nowrap; }
.undo-btn:hover { border-color:var(--danger); color:var(--danger); }
.undo-btn .ico { width:13px; height:13px; }
.undo-btn:disabled { opacity:.6; cursor:default; }

/* states */
.empty-state, .loading-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .ico { width: 40px; height: 40px; margin-bottom: 10px; opacity: .6; }
.skeleton { background: linear-gradient(90deg, var(--card-2) 25%, var(--card) 50%, var(--card-2) 75%); background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.sk-line { height: 14px; margin: 8px 0; }

/* toast */
.toast-wrap { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 11px; padding: 13px 18px; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  min-width: 250px; animation: slidein .25s ease; font-size: .86rem;
}
.toast .ico { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success { border-left: 3px solid var(--success); }
.toast.success .ico { color: var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.error .ico { color: var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
.toast.info .ico { color: var(--accent); }
@keyframes slidein { from { transform: translateX(120%); } to { transform: none; } }

/* mobile menu button */
.menu-toggle { display: none; }
.sb-backdrop { display: none; }

/* Hero stat tiles (Sales + Gross Profit at top of Summary/Channel/Projects) */
.hero-stat { padding:26px 26px 24px; background:linear-gradient(135deg, var(--card) 0%, rgba(124,58,237,.10) 100%); border:1px solid rgba(124,58,237,.28); }
.hero-stat .value { font-size:2.4rem; line-height:1.1; margin-top:6px; }
.hero-stat .label { font-size:.9rem; }
.hero-stat .mini-icon { width:38px; height:38px; }
.hero-stat .mini-icon .ico { width:19px; height:19px; }
@media (max-width:720px){ .hero-stat .value { font-size:1.9rem; } }

.modal-backdrop { position:fixed; inset:0; background:rgba(5,5,15,.65); z-index:200; display:flex; align-items:center; justify-content:center; padding:20px; backdrop-filter:blur(3px); }
.modal-card { background:var(--card); border:1px solid var(--border); border-radius:16px; width:100%; max-width:680px; max-height:88vh; display:flex; flex-direction:column; box-shadow:0 24px 60px rgba(0,0,0,.5); }
.modal-head { display:flex; align-items:center; justify-content:space-between; padding:18px 22px; border-bottom:1px solid var(--border); }
.modal-head h3 { font-size:1rem; display:flex; align-items:center; gap:8px; }
.modal-body { padding:20px 22px; overflow-y:auto; }
.modal-foot { display:flex; justify-content:flex-end; gap:10px; padding:16px 22px; border-top:1px solid var(--border); }
.modal-body .field input.input, .modal-body input.input { width:100%; padding:10px 12px; background:var(--bg-2); border:1px solid var(--border); border-radius:9px; color:var(--text); font-size:.9rem; }
.modal-body .field input.input:focus { outline:none; border-color:var(--primary-bright); }
.modal-foot .btn-primary { width:auto; padding:10px 22px; }
.modal-foot .btn-ghost { padding:10px 18px; }


.map-layout { display:grid; grid-template-columns: 1.6fr 1fr; gap:16px; }
.net-map { height:440px; border-radius:14px; overflow:hidden; border:1px solid var(--border); background:#0a0a14; z-index:1; }
.net-map .leaflet-popup-content-wrapper { background:var(--card); color:var(--text); border-radius:10px; }
.net-map .leaflet-popup-tip { background:var(--card); }
.net-map .leaflet-container { background:#0a0a14; font-family:inherit; }
.map-rank { max-height:440px; overflow-y:auto; padding-right:4px; }
.map-rank-head { font-size:.74rem; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); font-weight:700; margin-bottom:10px; }
.mr-item { display:flex; gap:10px; align-items:flex-start; padding:8px 6px; border-radius:9px; }
.mr-item:hover { background:var(--card-2); }
.mr-rank { flex:0 0 22px; height:22px; display:grid; place-items:center; border-radius:6px; background:var(--bg-2); border:1px solid var(--border); font-size:.72rem; font-weight:700; color:var(--primary-bright); margin-top:2px; }
.mr-body { flex:1; min-width:0; }
.mr-top { display:flex; justify-content:space-between; gap:8px; }
.mr-name { font-weight:600; font-size:.86rem; }
.mr-val { font-weight:700; font-size:.86rem; color:var(--primary-bright); white-space:nowrap; }
.mr-bar { height:5px; border-radius:4px; background:var(--bg-2); margin:5px 0; overflow:hidden; }
.mr-bar span { display:block; height:100%; background:linear-gradient(90deg,var(--primary),var(--primary-bright)); border-radius:4px; }
.mr-seg { font-size:.68rem; color:var(--muted); }
/* map heatmap legend */
.map-legend { background:rgba(15,15,23,.9); border:1px solid var(--border); border-radius:8px; padding:8px 10px; color:var(--text); font-size:.7rem; }
.map-legend .ml-title { font-weight:700; margin-bottom:5px; text-transform:uppercase; letter-spacing:.03em; color:var(--muted); }
.map-legend .ml-scale { display:flex; gap:0; }
.map-legend .ml-scale span { width:22px; height:10px; }
.map-legend .ml-scale span:first-child { border-radius:3px 0 0 3px; }
.map-legend .ml-scale span:last-child { border-radius:0 3px 3px 0; }
.map-legend .ml-labels { display:flex; justify-content:space-between; margin-top:3px; color:var(--muted); }

/* ============================================================
   DASHBOARD v2 COMPONENTS
   ============================================================ */
/* highlight top performer row */
.tbl tr.row-top td { background: rgba(124,58,237,.10); }
.tbl tr.row-top td:first-child { box-shadow: inset 3px 0 0 var(--primary-bright); }

/* segmented control (tabs) */
.seg-ctl { display:inline-flex; flex-wrap:wrap; gap:4px; background:var(--bg-2); border:1px solid var(--border); border-radius:11px; padding:4px; }
.seg-ctl button { padding:9px 16px; border:none; background:transparent; color:var(--muted); font-weight:600; font-size:.84rem; border-radius:8px; cursor:pointer; white-space:nowrap; transition:background .12s,color .12s; }
.seg-ctl button:hover { color:var(--text); }
.seg-ctl button.active { background:var(--primary); color:#fff; }

/* heatmap */
.heatmap-wrap { overflow-x:auto; padding-bottom:6px; }
.heatmap { display:inline-block; min-width:100%; }
.hm-row { display:flex; align-items:center; gap:3px; margin-bottom:3px; }
.hm-name {
  flex:0 0 120px; width:120px; font-size:.78rem; color:var(--text); white-space:nowrap;
  overflow:hidden; text-overflow:ellipsis; padding-right:8px;
  /* Freeze the name column so it stays visible when scrolling horizontally. */
  position: sticky; left: 0; z-index: 2;
  background: var(--card);
  box-shadow: 2px 0 4px -2px rgba(0,0,0,.15);
}
.hm-cell { flex:0 0 56px; width:56px; height:30px; border-radius:5px; border:1px solid var(--border); display:flex; align-items:center; justify-content:center; font-size:.62rem; font-weight:600; }
.hm-head .hm-cell { border:none; background:transparent !important; font-size:.6rem; color:var(--muted); }
.hm-head .hm-name { background: var(--card); box-shadow: none; }
.hm-dcol { width:56px; }

/* ranking page */
.rank-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:18px; }
.rank-grid > .card:last-child:nth-child(odd) { grid-column: span 2; }
.rank-list { display:flex; flex-direction:column; gap:4px; max-height:420px; overflow-y:auto; }
.rank-item { display:flex; align-items:center; gap:12px; padding:10px 8px; border-radius:10px; transition:background .12s; }
.rank-item:hover { background:var(--card-2); }
.rank-item.top3 { background:rgba(124,58,237,.08); }
.rank-pos { flex:0 0 32px; text-align:center; font-size:1.1rem; }
.rank-main { flex:1; min-width:0; }
.rank-name { font-weight:700; font-size:.9rem; display:flex; align-items:center; gap:8px; }
.rank-div { font-size:.66rem; font-weight:600; color:var(--muted); background:var(--bg-2); border:1px solid var(--border); padding:1px 7px; border-radius:20px; }
.rank-sub { font-size:.72rem; color:var(--muted); margin-top:2px; }
.rank-val { flex:0 0 auto; font-size:1.15rem; font-weight:800; white-space:nowrap; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .cols-4 { grid-template-columns: repeat(2,1fr); }
  .result-grid { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 1000px) {
  .cols-3 { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 860px) {
  .menu-toggle { display: grid; }
  #collapseBtn { display: none; }
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w); transition: transform .25s ease; z-index: 60; }
  /* always show full (expanded) sidebar contents in the mobile drawer,
     even if collapsed mode was toggled on desktop */
  body[data-collapsed="on"] .sidebar { width: var(--sidebar-w); }
  body[data-collapsed="on"] .sidebar .nav-parent .label,
  body[data-collapsed="on"] .sidebar .nav-parent .chev,
  body[data-collapsed="on"] .sidebar .sb-brand,
  body[data-collapsed="on"] .sidebar .user-meta,
  body[data-collapsed="on"] .sidebar .ua-btn .txt { opacity: 1 !important; width: auto !important; display: block; }
  body[data-collapsed="on"] .sidebar .nav-parent { justify-content: flex-start; padding: 11px 14px; }
  body[data-collapsed="on"] .sidebar .submenu { position: static; max-height: 0; }
  body[data-collapsed="on"] .sidebar .submenu.open { max-height: 600px; }
  body[data-collapsed="on"] .sidebar .user-row { justify-content: flex-start; }
  body[data-collapsed="on"] .sidebar .user-actions { flex-direction: row; }
  body[data-collapsed="on"] .sidebar .ua-btn { padding: 8px 10px; }
  .sidebar.mobile-open { transform: none; }
  .main { margin-left: 0 !important; }
  .sb-backdrop { position: fixed; inset: 0; background: rgba(5,5,15,.5); z-index: 55; display: none; }
  .sb-backdrop.show { display: block; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .rank-grid { grid-template-columns: 1fr; }
  .map-layout { grid-template-columns: 1fr; }
  .net-map { height: 320px; }
  .map-rank { max-height: none; }
  .rank-grid > .card:last-child:nth-child(odd) { grid-column: span 1; }
  .span-2 { grid-column: span 1; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .content { padding: 16px; }
  .search-global { order: 10; width: 100%; }
  .topbar h2 { font-size: 1.02rem; }
  /* date filter dropdown: keep on-screen */
  .date-filter { position: static; }
  .df-menu { position: fixed; top: auto; left: 12px; right: 12px; width: auto; max-width: none; }
}
@media (max-width: 560px) {
  .opt-grid { grid-template-columns: repeat(2,1fr); }
  .result-grid { grid-template-columns: 1fr 1fr; }
  .topbar { gap: 10px; }
  .df-menu { position: fixed; left: 12px; right: 12px; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Google-Sheet import format */
.gsheet-note { font-size:.8rem; color:var(--muted); background:var(--card-2); border:1px solid var(--border); border-radius:9px; padding:10px 12px; display:flex; align-items:center; gap:8px; }
.gsheet-note .ico { width:15px; height:15px; color:var(--primary-bright); flex-shrink:0; }
.import-errs { margin-top:12px; font-size:.75rem; color:var(--danger); max-height:160px; overflow-y:auto; }
.import-errs div { padding:2px 0; }

/* Projects page toolbar (period + project filter) */
.proj-toolbar { display:flex; align-items:center; gap:14px; flex-wrap:wrap; margin-bottom:18px; }
.proj-toolbar .range-pill { margin-bottom:0; padding:9px 14px; font-size:.82rem; }
.proj-filter { display:flex; align-items:center; gap:8px; }
.proj-filter label { display:flex; align-items:center; gap:6px; font-size:.82rem; color:var(--muted); font-weight:600; }
.proj-filter label .ico { width:15px; height:15px; }
.proj-filter .select { min-width:200px; padding:9px 12px; background:var(--card); border:1px solid var(--border); border-radius:20px; color:var(--text); font-size:.82rem; }
.proj-filter .select:focus { outline:none; border-color:var(--primary-bright); }

/* ============================================================
   CUSTOM REVIEW — filter chips + table
   ============================================================ */
.cr-filter { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.cr-filter-row { display: flex; align-items: flex-start; gap: 12px; }
.cr-filter-label {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 92px; padding-top: 6px;
  color: var(--muted); font-weight: 700; font-size: .8rem; white-space: nowrap;
}
.cr-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.cr-chip {
  padding: 6px 13px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--muted);
  font-size: .78rem; font-weight: 600; border-radius: 999px;
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.cr-chip:hover { color: var(--text); border-color: var(--border-strong); }
.cr-chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.cr-chip.cr-all { font-weight: 700; }
.cr-chip.cr-all.on { background: var(--accent); border-color: var(--accent); color: #04121a; }
.cr-total td { border-top: 2px solid var(--border-strong); background: var(--card-2); }

/* Conditional GP / POAS tags — soft tinted pills (works on Safari & Windows).
   Rendered as an inline span so the tint never bleeds across table borders.
   Default = dark theme (matches image 4). Light overrides below. */
.cr-tag {
  display: inline-block; min-width: 62px; text-align: center;
  padding: 5px 12px; border-radius: 8px;
  font-weight: 700; font-variant-numeric: tabular-nums;
}
/* Dark theme (default) — muted fill, bright text */
.cr-tag.cr-pos { background: rgba(52,211,153,.16); color: #6ee7b7; }
.cr-tag.cr-neg { background: rgba(248,113,113,.16); color: #fca5a5; }
/* Light theme — soft pastel fill, deep text */
[data-theme="light"] .cr-tag.cr-pos { background: #d6f0e0; color: #10633a; }
[data-theme="light"] .cr-tag.cr-neg { background: #f6dcdc; color: #a11d1d; }
.cr-total .cr-tag { min-width: 68px; }

/* Safari/WebKit fix: with border-collapse, solid td backgrounds bleed across
   cell borders. Clipping to padding-box keeps fills inside each cell so the
   TOTAL row, hover, and any tinted cells render cleanly on macOS. */
table.tbl td, table.tbl th { background-clip: padding-box; }
