/* ================================================================
   EV Showroom Manager — design tokens
   Palette follows the validated categorical/status set (see project
   memory: blue / orange / aqua / yellow / violet + fixed status hues).
   ================================================================ */
:root {
  color-scheme: light;
  --page:            #f6f7fb;
  --page-tint-a:     rgba(42,120,214,0.08);
  --page-tint-b:     rgba(74,58,167,0.07);
  --surface-1:        #ffffff;
  --surface-1-rgb:     255,255,255;
  --surface-2:         #f1f2f8;
  --text-primary:    #101322;
  --text-secondary:  #565b72;
  --text-muted:      #8a8fa3;
  --gridline:        #e6e7f0;
  --baseline:        #cfd1e0;
  --border:          rgba(16,19,34,0.09);

  --series-1:        #2a78d6; /* blue      — stock */
  --series-2:        #eb6834; /* orange    — expenses */
  --series-3:        #1baf7a; /* aqua      — sales */
  --series-4:        #eda100; /* yellow    — profit accent */
  --series-7:        #4a3aa7; /* violet    — purchases */

  --good:            #0ca30c;
  --critical:        #d03b3b;
  --warning:         #fab219;
  --serious:         #ec835a;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(16,19,34,0.06);
  --shadow-md: 0 8px 24px -8px rgba(16,19,34,0.16);
  --shadow-lg: 0 20px 48px -16px rgba(16,19,34,0.28);

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:            #0b0d14;
    --page-tint-a:     rgba(57,135,229,0.10);
    --page-tint-b:     rgba(144,133,233,0.08);
    --surface-1:        #151826;
    --surface-1-rgb:     21,24,38;
    --surface-2:         #1d2133;
    --text-primary:    #f5f6fb;
    --text-secondary:  #b3b7ce;
    --text-muted:      #82869e;
    --gridline:        #262a3d;
    --baseline:        #363b53;
    --border:          rgba(255,255,255,0.09);
    --series-1:        #3987e5;
    --series-2:        #d95926;
    --series-3:        #199e70;
    --series-4:        #c98500;
    --series-7:        #9085e9;
    --shadow-md: 0 8px 28px -8px rgba(0,0,0,0.55);
    --shadow-lg: 0 24px 56px -16px rgba(0,0,0,0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0b0d14;
  --page-tint-a:     rgba(57,135,229,0.10);
  --page-tint-b:     rgba(144,133,233,0.08);
  --surface-1:        #151826;
  --surface-1-rgb:     21,24,38;
  --surface-2:         #1d2133;
  --text-primary:    #f5f6fb;
  --text-secondary:  #b3b7ce;
  --text-muted:      #82869e;
  --gridline:        #262a3d;
  --baseline:        #363b53;
  --border:          rgba(255,255,255,0.09);
  --series-1:        #3987e5;
  --series-2:        #d95926;
  --series-3:        #199e70;
  --series-4:        #c98500;
  --series-7:        #9085e9;
  --shadow-md: 0 8px 28px -8px rgba(0,0,0,0.55);
  --shadow-lg: 0 24px 56px -16px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(760px 480px at 8% -6%, var(--page-tint-a), transparent 60%),
    radial-gradient(680px 520px at 100% 0%, var(--page-tint-b), transparent 55%),
    var(--page);
  background-attachment: fixed;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: rgba(var(--surface-1-rgb), 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 26px;
  font-weight: 800;
  font-size: 16.5px;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 10px rgba(74,58,167,0.4));
}
.brand-mark svg { width: 100%; height: 100%; }
.brand-word { color: var(--text-primary); }
.brand-accent { color: var(--series-7); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, transform .15s ease;
}
.nav-item .icon { color: inherit; opacity: 0.85; }
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.active {
  background: linear-gradient(135deg, var(--series-1), var(--series-7));
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(42,120,214,0.55);
}
.nav-item.active .icon { opacity: 1; }
.nav-label { white-space: nowrap; }

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.currency-field { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.currency-field input {
  width: 48px;
  padding: 5px 6px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: inherit;
  text-align: center;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: inline-flex; }

.main {
  flex: 1;
  min-width: 0;
  padding: 30px 34px 60px;
  max-width: 1240px;
}

.tab-panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.panel-header h1 { margin: 0 0 4px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { margin: 0; color: var(--text-secondary); font-size: 13.5px; }

.month-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--series-7);
  background: color-mix(in srgb, var(--series-7) 14%, transparent);
}
.month-badge .icon { width: 13px; height: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease, background-color .12s ease;
}
.btn-primary {
  background: linear-gradient(135deg, var(--series-1), var(--series-7));
  color: #fff;
  box-shadow: 0 8px 20px -8px rgba(42,120,214,0.6);
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: var(--surface-1); color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); }
.btn-sm { padding: 7px 11px; font-size: 12.5px; }
.btn-danger { background: transparent; color: var(--critical); border-color: var(--border); }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 12%, transparent); }

/* ---------- stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent, var(--series-1)), transparent 60%);
  opacity: 0.06;
  pointer-events: none;
}
.stat-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent, var(--series-1)), color-mix(in srgb, var(--accent, var(--series-1)) 60%, #000 18%));
  color: #fff;
  box-shadow: 0 6px 14px -4px color-mix(in srgb, var(--accent, var(--series-1)) 70%, transparent);
  margin-bottom: 12px;
}
.stat-card--stock     { --accent: var(--series-1); }
.stat-card--purchase  { --accent: var(--series-7); }
.stat-card--sales     { --accent: var(--series-3); }
.stat-card--expenses  { --accent: var(--series-2); }
.stat-card--profit    { --accent: var(--series-4); }

.stat-card-label { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card-value { font-size: 25px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: proportional-nums; }
.stat-card-value.good { color: var(--good); }
.stat-card-value.critical { color: var(--critical); }
.stat-card-sub { margin-top: 6px; font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }

/* ---------- cards / grid ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-header h2 { margin: 0 0 2px; font-size: 15.5px; font-weight: 800; }
.card-sub { margin: 0; font-size: 12px; color: var(--text-muted); }
.card-header-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: color-mix(in srgb, var(--accent, var(--series-1)) 16%, transparent);
  color: var(--accent, var(--series-1));
}

/* ---------- stock flow stepper ---------- */
.stepper {
  display: flex;
  align-items: stretch;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.stepper-step {
  flex: 1 1 0;
  min-width: 118px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 14px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.stepper-step .stepper-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: color-mix(in srgb, var(--accent, var(--series-1)) 18%, transparent);
  color: var(--accent, var(--series-1));
}
.stepper-step.opening   { --accent: var(--text-muted); }
.stepper-step.purchased { --accent: var(--series-7); }
.stepper-step.sold      { --accent: var(--series-2); }
.stepper-step.closing   {
  --accent: var(--series-1);
  background: linear-gradient(135deg, color-mix(in srgb, var(--series-1) 14%, var(--surface-2)), var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--series-1) 30%, transparent);
}
.stepper-value { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.stepper-label { font-size: 11.5px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.stepper-arrow { display: flex; align-items: center; justify-content: center; color: var(--text-muted); flex: 0 0 22px; }

/* ---------- inventory value & expected profit ---------- */
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}
.inventory-item { padding: 4px 0; }
.inventory-item-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }
.inventory-item-value { font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.inventory-item-sub { margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.inventory-note {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warning) 14%, transparent);
  color: var(--text-secondary);
  font-size: 12.5px;
}
.inventory-note .icon { color: var(--warning); flex-shrink: 0; }

/* ---------- revenue breakdown bar ---------- */
.breakdown-track {
  display: flex;
  height: 22px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
  gap: 2px;
}
.breakdown-seg { height: 100%; min-width: 3px; }
.breakdown-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; font-size: 12.5px; color: var(--text-secondary); }
.breakdown-legend span { display: inline-flex; align-items: center; gap: 6px; }
.breakdown-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.breakdown-legend b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.breakdown-total { margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.breakdown-total b { color: var(--text-primary); }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.toolbar input[type="search"], .toolbar select {
  font-family: inherit;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.toolbar input[type="search"] { width: 100%; padding-left: 34px; }
.toolbar select { cursor: pointer; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-1); }
.segmented-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 15px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}
.segmented-btn + .segmented-btn { border-left: 1px solid var(--border); }
.segmented-btn.active { background: linear-gradient(135deg, var(--series-1), var(--series-7)); color: #fff; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-1); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 13px 14px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--gridline); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.actions-col, td.actions-col { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  font-family: inherit;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}
.icon-btn .icon { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.icon-btn.danger:hover { color: var(--critical); background: color-mix(in srgb, var(--critical) 12%, transparent); }
.icon-btn.accent:hover { color: var(--series-1); background: color-mix(in srgb, var(--series-1) 12%, transparent); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.profit-pos { color: var(--good); font-weight: 700; }
.profit-neg { color: var(--critical); font-weight: 700; }

.vehicle-cell { display: flex; align-items: center; gap: 10px; }
.vehicle-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: color-mix(in srgb, var(--series-1) 15%, transparent);
  color: var(--series-1);
}
.vehicle-avatar .icon { width: 15px; height: 15px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.badge-instock { background: color-mix(in srgb, var(--series-1) 16%, transparent); color: var(--series-1); }
.badge-sold { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }

.empty-state { text-align: center; color: var(--text-muted); font-size: 13.5px; padding: 34px 0; }
.empty-state.hidden { display: none; }

/* ---------- mini table (dashboard recent sales) ---------- */
.mini-table-wrap table { min-width: 0; font-size: 13px; }
.mini-table-wrap thead th { padding: 8px 4px; }
.mini-table-wrap tbody td { padding: 9px 4px; }
.mini-empty { color: var(--text-muted); font-size: 13px; padding: 12px 2px; }

/* ---------- dialogs ---------- */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface-1);
  color: var(--text-primary);
  width: min(560px, 92vw);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(8,10,18,0.55); backdrop-filter: blur(2px); }
.dlg-form { padding: 24px 26px 22px; display: flex; flex-direction: column; gap: 14px; }
.dlg-form h2 { margin: 0 0 4px; font-size: 18px; font-weight: 800; }
.dlg-subhead { margin: 4px 0 -6px; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid label.full, label.full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--series-1) 55%, transparent); outline-offset: 1px; }
textarea { resize: vertical; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---------- chart ---------- */
.chart-wrap { position: relative; overflow-x: auto; }
.chart-wrap svg { display: block; }
.chart-tooltip {
  position: fixed;
  z-index: 50;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -110%);
  box-shadow: var(--shadow-md);
}
.chart-tooltip.hidden { display: none; }
.chart-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}
.toast.hidden { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .main { padding: 18px 16px 88px; }

  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 66px;
    flex-direction: row;
    align-items: center;
    padding: 6px 8px;
    gap: 4px;
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px -12px rgba(16,19,34,0.25);
  }
  .brand { display: none; }
  .nav { flex-direction: row; flex: 1; gap: 2px; }
  .nav-item {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    flex: 1;
    padding: 7px 2px;
    font-size: 9.5px;
    text-align: center;
    border-radius: 10px;
  }
  .nav-item .icon { width: 19px; height: 19px; }
  .nav-label { white-space: normal; line-height: 1.1; }
  .sidebar-footer { flex-direction: row; border-top: none; padding-top: 0; gap: 6px; flex: 0 0 auto; }
  .currency-field { display: none; }
  .theme-toggle span:not(.sr-only) { display: none; }
  .theme-toggle { width: 40px; height: 40px; padding: 0; border-radius: 10px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stepper { flex-direction: column; }
  .stepper-arrow { transform: rotate(90deg); flex: 0 0 auto; padding: 2px 0; }
}

@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 14px 12px; }
  .stat-card-value { font-size: 21px; }
}
