/* ============================================================
   clientauto247 — Admin Dashboard
   Design tokens + base styles
   ============================================================ */

:root {
  /* Surfaces & ink */
  --bg:        #F4F2FB;
  --bg-tint:   #EEEBFA;
  --surface:   #FFFFFF;
  --surface-2: #F7F5FD;
  --surface-3: #F0EDFA;
  --ink:       #1C1733;
  --ink-soft:  #565070;
  --muted:     #8C86A3;
  --line:      #EAE6F6;
  --line-soft: #F1EEF9;

  /* Brand accent (driven by tweaks) */
  --primary:      #6C4DF6;
  --primary-ink:  #4B2BD6;
  --primary-soft: #ECE7FF;
  --primary-tint: #F4F1FF;

  /* Categorical accents */
  --coral:   #FF6B5C;
  --coral-soft:  #FFE9E5;
  --amber:   #FFA51F;
  --amber-soft:  #FFF1DC;
  --mint:    #12B886;
  --mint-soft:   #DCF7EC;
  --sky:     #1FA8FF;
  --sky-soft:    #E1F2FF;
  --pink:    #FF5DA2;
  --pink-soft:   #FFE6F1;
  --violet:  #6C4DF6;
  --violet-soft: #ECE7FF;

  /* Status */
  --ok:      #12B886;
  --ok-soft: #DCF7EC;
  --err:     #F5524C;
  --err-soft:#FFE3E1;
  --warn:    #FFA51F;
  --warn-soft:#FFF1DC;
  --idle:    #9A94AD;
  --idle-soft:#EFEDF5;

  /* Radii & shadows */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(28,23,51,.05), 0 1px 3px rgba(28,23,51,.04);
  --shadow-md: 0 4px 14px rgba(45,28,120,.07), 0 2px 6px rgba(45,28,120,.04);
  --shadow-lg: 0 18px 48px rgba(45,28,120,.14), 0 6px 16px rgba(45,28,120,.07);
  --shadow-pop: 0 24px 64px rgba(28,23,51,.20);

  /* Layout */
  --sidebar-w: 256px;
  --gap: 20px;

  /* Typography */
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-ui: "Plus Jakarta Sans", system-ui, sans-serif;

  /* Density (driven by tweaks) */
  --pad-card: 22px;
  --row-h: 56px;
}

/* Density variants */
[data-density="compact"] { --pad-card: 16px; --row-h: 46px; --gap: 14px; }
[data-density="comfy"]   { --pad-card: 28px; --row-h: 64px; --gap: 26px; }

/* Dark theme */
[data-theme="dark"] {
  --bg:        #14111F;
  --bg-tint:   #1A1530;
  --surface:   #1E1A2E;
  --surface-2: #25203A;
  --surface-3: #2B2543;
  --ink:       #F3F1FB;
  --ink-soft:  #B6AFD0;
  --muted:     #7C76A0;
  --line:      #2E2848;
  --line-soft: #272140;
  --primary-soft:#2A2358;
  --primary-tint:#231D49;
  --coral-soft:  #3A2230;
  --amber-soft:  #3A2E1C;
  --mint-soft:   #16352C;
  --sky-soft:    #16293D;
  --pink-soft:   #3A2233;
  --violet-soft: #2A2358;
  --ok-soft:#16352C; --err-soft:#3A2026; --warn-soft:#3A2E1C; --idle-soft:#272140;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 14px rgba(0,0,0,.35);
  --shadow-lg: 0 18px 48px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#root { min-height: 100vh; }

h1,h2,h3,h4 { font-family: var(--font-display); margin: 0; letter-spacing: -.01em; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
::selection { background: var(--primary-soft); }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns .25s ease;
}
.app[data-nav="top"] { grid-template-columns: 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  gap: 4px;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 6px 8px 18px;
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--pink));
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 6px 16px rgba(108,77,246,.35);
  flex: none;
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 18px; line-height: 1; }
.brand-name .dot { color: var(--primary); }
.brand-sub { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

.nav-group-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); padding: 16px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-md);
  color: var(--ink-soft); font-weight: 600; font-size: 14px;
  border: none; background: transparent; width: 100%; text-align: left;
  position: relative; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--primary-tint); color: var(--primary-ink); }
[data-theme="dark"] .nav-item.active { color: #C9BCFF; }
.nav-item .ico { flex: none; width: 20px; height: 20px; }
.nav-item .badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--coral); color: #fff; border-radius: var(--r-pill);
  min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
}
.nav-item .badge.muted { background: var(--idle-soft); color: var(--ink-soft); }

.sidebar-foot { margin-top: auto; }
.upgrade-card {
  background: linear-gradient(150deg, var(--primary), #8B5CF6 60%, var(--pink));
  color: #fff; border-radius: var(--r-lg); padding: 16px;
  position: relative; overflow: hidden;
}
.upgrade-card h4 { font-size: 14px; }
.upgrade-card p { font-size: 12px; opacity: .85; margin: 6px 0 12px; line-height: 1.4; }
.upgrade-card .mini-btn {
  background: #fff; color: var(--primary-ink); border: none;
  border-radius: var(--r-pill); padding: 7px 14px; font-weight: 700; font-size: 12.5px;
}

/* ---------- Main column ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 22px; font-weight: 700; }
.topbar .crumb { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.search {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 9px 15px; min-width: 220px;
  color: var(--muted); font-size: 13.5px;
}
.search input { border: none; background: none; outline: none; color: var(--ink); width: 100%; font-size: 13.5px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--ink-soft);
  position: relative; transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: scale(.95); }
.icon-btn .dot-alert {
  position: absolute; top: 8px; right: 8px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--coral); border: 2px solid var(--surface);
}
.avatar {
  width: 40px; height: 40px; border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--sky), var(--mint));
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  flex: none;
}

.content { padding: 24px 28px 56px; }
.content-inner { max-width: 1320px; margin: 0 auto; }

/* ---------- Generic card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--pad-card);
  box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-head h3 { font-size: 16px; font-weight: 700; }
.card-head .sub { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.card-head .spacer { flex: 1; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(4, 1fr);
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--pad-card);
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat .stat-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.stat .stat-ico {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; flex: none;
}
.stat .stat-label { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.stat .stat-val { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.stat .stat-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12.5px; }
.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; border-radius: var(--r-pill); padding: 2px 8px; font-size: 12px; }
.trend.up { color: var(--mint); background: var(--mint-soft); }
.trend.down { color: var(--err); background: var(--err-soft); }
.trend.flat { color: var(--ink-soft); background: var(--idle-soft); }
.stat .stat-foot .muted { color: var(--muted); font-weight: 500; }
.stat .spark { position: absolute; right: 0; bottom: 0; opacity: .9; }

/* ---------- Status pill ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; border-radius: var(--r-pill);
  padding: 4px 10px; white-space: nowrap;
}
.pill .pdot { width: 7px; height: 7px; border-radius: 50%; }
.pill.ok    { background: var(--ok-soft);   color: var(--ok); }
.pill.err   { background: var(--err-soft);  color: var(--err); }
.pill.warn  { background: var(--warn-soft); color: #B5740A; }
.pill.idle  { background: var(--idle-soft); color: var(--ink-soft); }
.pill.info  { background: var(--sky-soft);  color: #0E7CC2; }
.pill.primary { background: var(--primary-soft); color: var(--primary-ink); }
[data-theme="dark"] .pill.warn { color: var(--warn); }
[data-theme="dark"] .pill.info { color: var(--sky); }
[data-theme="dark"] .pill.primary { color: #C9BCFF; }

/* ---------- Plan tag ---------- */
.plan-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: var(--r-sm); }
.plan-tag .pdot { width: 7px; height: 7px; border-radius: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: var(--r-pill); padding: 10px 18px;
  font-weight: 700; font-size: 13.5px; border: 1px solid transparent;
  transition: transform .1s, filter .15s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(108,77,246,.3); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-soft { background: var(--primary-soft); color: var(--primary-ink); }
.btn-soft:hover { filter: brightness(.98); }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 6px 14px; border-radius: var(--r-pill); font-weight: 600; font-size: 12.5px; color: var(--ink-soft); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; min-width: 720px; }
table.tbl th {
  text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); padding: 0 14px 12px; white-space: nowrap;
}
table.tbl td { padding: 13px 14px; border-top: 1px solid var(--line-soft); font-size: 13.5px; vertical-align: middle; }
table.tbl tbody tr { transition: background .12s; cursor: pointer; }
table.tbl tbody tr:hover { background: var(--surface-2); }
.cell-name { display: flex; align-items: center; gap: 11px; }
.client-logo {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #fff;
}
.cell-name .nm { font-weight: 700; color: var(--ink); }
.cell-name .em { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- Health bar ---------- */
.health { display: flex; align-items: center; gap: 9px; }
.health .track { width: 64px; height: 7px; border-radius: var(--r-pill); background: var(--idle-soft); overflow: hidden; }
.health .fill { height: 100%; border-radius: var(--r-pill); }
.health .pct { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }

/* ---------- Layout grids ---------- */
.row { display: grid; gap: var(--gap); }
.grid-2 { grid-template-columns: 1.6fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.mt { margin-top: var(--gap); }

/* ---------- Donut legend ---------- */
.legend { display: flex; flex-direction: column; gap: 11px; }
.legend-item { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend-item .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend-item .lv { margin-left: auto; font-weight: 700; }
.legend-item .lk { color: var(--ink-soft); font-weight: 600; }

/* ---------- Activity feed ---------- */
.feed { display: flex; flex-direction: column; gap: 2px; }
.feed-item { display: flex; gap: 13px; padding: 11px 6px; border-radius: var(--r-md); }
.feed-item:hover { background: var(--surface-2); }
.feed-dot { width: 34px; height: 34px; border-radius: 11px; flex: none; display: grid; place-items: center; }
.feed-body { flex: 1; min-width: 0; }
.feed-body .ft { font-size: 13.5px; line-height: 1.35; }
.feed-body .ft b { font-weight: 700; }
.feed-body .fm { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Alerts ---------- */
.alert-row { display: flex; gap: 13px; padding: 13px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); margin-bottom: 10px; align-items: flex-start; }
.alert-row.sev-err  { border-left: 4px solid var(--err); }
.alert-row.sev-warn { border-left: 4px solid var(--warn); }
.alert-row .a-ico { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; }
.alert-row .a-title { font-weight: 700; font-size: 13.5px; }
.alert-row .a-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.alert-row .a-time { font-size: 12px; color: var(--muted); white-space: nowrap; font-weight: 600; }

/* ---------- Automation card ---------- */
.auto-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(3, 1fr); }
.auto-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s; }
.auto-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.auto-card .ac-top { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.auto-card .ac-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.auto-card .ac-name { font-weight: 700; font-size: 14.5px; line-height: 1.2; }
.auto-card .ac-client { font-size: 12px; color: var(--muted); font-weight: 600; }
.auto-card .ac-stats { display: flex; gap: 18px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.auto-card .ac-stat .v { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.auto-card .ac-stat .k { font-size: 11px; color: var(--muted); font-weight: 600; }

/* ---------- Drawer ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(20,15,40,.42); backdrop-filter: blur(2px); z-index: 90; animation: fade .2s ease; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 92vw; background: var(--bg); z-index: 91; box-shadow: var(--shadow-pop); overflow-y: auto; animation: slidein .28s cubic-bezier(.2,.8,.2,1); }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer-head { position: sticky; top: 0; background: var(--bg); padding: 22px 24px 16px; border-bottom: 1px solid var(--line); z-index: 2; }
.drawer-body { padding: 20px 24px 40px; }

/* ---------- Mini KPI inside drawer ---------- */
.mini-kpis { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; }
.mini-kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; }
.mini-kpi .k { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.mini-kpi .v { font-family: var(--font-display); font-size: 22px; font-weight: 700; margin-top: 4px; }

/* ---------- Mobile nav ---------- */
.mobile-bar { display: none; }
.scrim-mobile { display: none; }

@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .auto-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 95; width: 270px;
    transform: translateX(-100%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: none; }
  .scrim-mobile.show { display: block; position: fixed; inset: 0; background: rgba(20,15,40,.4); z-index: 94; }
  .topbar { padding: 14px 16px; }
  .content { padding: 18px 16px 90px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .auto-grid { grid-template-columns: 1fr; }
  .search { display: none; }
  .hamburger { display: grid !important; }
  .topbar h1 { font-size: 18px; }
  .drawer { width: 100vw; }
}
.hamburger { display: none; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--line); margin: var(--gap) 0; }
.scroll-thin::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll-thin::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px; font-size: 13.5px; }
.kbd { font-size: 11px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; color: var(--ink-soft); font-weight: 700; }
.fade-in { animation: fade .3s ease; }
