/* =====================================================================
   shadcn/ui design system — 用车统计 (EV Charging Stats)
   Tokens mirror shadcn "new-york / zinc" theme. Dark is the default.
   ===================================================================== */

/* Inter font is loaded via <link> in index.html */

/* ---------- Light theme tokens (default reference) ---------- */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;

  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;

  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;

  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;

  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;

  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;

  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;

  --destructive: 0 72.2% 50.6%;
  --destructive-foreground: 0 0% 98%;

  --success: 142 71% 45%;
  --success-foreground: 0 0% 98%;

  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;

  --radius: 0.5rem;

  /* chart palette (reads well on both themes) */
  --chart-1: 142 71% 40%;   /* green  */
  --chart-2: 221 83% 53%;   /* blue   */
  --chart-3: 25 95% 53%;    /* orange */
  --chart-4: 262 83% 58%;   /* purple */
  --chart-5: 330 81% 60%;   /* pink   */
}

/* ---------- Dark theme tokens ---------- */
.dark {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;

  --card: 240 10% 5.9%;
  --card-foreground: 0 0% 98%;

  --popover: 240 10% 5.9%;
  --popover-foreground: 0 0% 98%;

  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;

  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;

  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;

  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;

  --destructive: 0 62.8% 45%;
  --destructive-foreground: 0 0% 98%;

  --success: 142 71% 45%;
  --success-foreground: 0 0% 98%;

  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;

  --chart-1: 142 70% 50%;
  --chart-2: 217 91% 65%;
  --chart-3: 32 95% 58%;
  --chart-4: 262 83% 68%;
  --chart-5: 330 81% 68%;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: hsl(var(--muted-foreground)); }
a { color: inherit; }

/* ---------- focus ring (shadcn) ---------- */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring));
  border-radius: var(--radius);
}

/* =====================================================================
   Buttons  (shadcn .btn variants)
   ===================================================================== */
.btn,
.primary, .ghost, .secondary, .outline, .destructive {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, opacity .15s ease;
  user-select: none;
}
.btn:disabled, .primary:disabled, .ghost:disabled { opacity: .5; pointer-events: none; }

/* primary (neutral, canonical shadcn) */
.primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.primary:hover { background-color: hsl(var(--primary) / 0.9); }

/* ghost */
.ghost {
  background-color: transparent;
  color: hsl(var(--foreground));
}
.ghost:hover { background-color: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

/* danger ghost */
.ghost.danger { color: hsl(var(--destructive)); }
.ghost.danger:hover { background-color: hsl(var(--destructive) / 0.12); }

/* small variant (row ops) */
.mini {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; padding: 0 10px; font-size: 12px; font-weight: 500;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--border));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer; transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.mini:hover { background-color: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.mini.danger { color: hsl(var(--destructive)); }
.mini.danger:hover { background-color: hsl(var(--destructive) / 0.12); border-color: hsl(var(--destructive) / 0.4); }

.row-ops { white-space: nowrap; }
.row-ops .mini + .mini { margin-left: 4px; }

/* =====================================================================
   Header / topbar
   ===================================================================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px;
  background-color: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border));
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px;
  background-color: hsl(var(--accent)); color: hsl(var(--accent-foreground));
  font-size: 20px; flex: none;
}
.topbar h1 { font-size: 16px; line-height: 1.2; }
.tagline { margin: 2px 0 0; color: hsl(var(--muted-foreground)); font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* =====================================================================
   Tabs — shadcn segmented tablist
   ===================================================================== */
.tabs {
  display: flex; gap: 2px;
  padding: 10px 24px;
  background-color: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border));
}
.tab-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: hsl(var(--muted-foreground));
  font-size: 13px; font-weight: 500;
  padding: 8px 14px;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.tab-btn:hover { color: hsl(var(--foreground)); }
.tab-btn.active {
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.12), 0 0 0 1px hsl(var(--border));
}

main { padding: 24px; max-width: 1180px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.panel-head h2 { font-size: 18px; }

/* =====================================================================
   Card
   ===================================================================== */
.card {
  background-color: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

/* =====================================================================
   KPI cards
   ===================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.kpi {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  padding: 18px 20px;
  transition: box-shadow .2s ease, border-color .2s ease;
}
.kpi:hover { box-shadow: 0 4px 10px -2px rgb(0 0 0 / 0.12); border-color: hsl(var(--ring) / 0.5); }
.kpi-title { color: hsl(var(--muted-foreground)); font-size: 12.5px; font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 8px 0 4px; letter-spacing: -0.02em; }
.kpi-sub { color: hsl(var(--muted-foreground)); font-size: 12px; }
.kpi-delta { font-weight: 600; margin-left: 2px; }
.kpi-delta.up { color: hsl(var(--success)); }
.kpi-delta.down { color: hsl(var(--destructive)); }

/* =====================================================================
   Charts
   ===================================================================== */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  padding: 16px 18px 18px;
}
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.chart-wrap { position: relative; height: 260px; }

/* =====================================================================
   Tables — shadcn style
   ===================================================================== */
#records-table, #purchase-table, #products-table { overflow-x: auto; }

.grid {
  width: 100%;
  border-collapse: collapse;
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}
.grid thead { border-bottom: 1px solid hsl(var(--border)); }
.grid th {
  text-align: left;
  padding: 10px 14px;
  color: hsl(var(--muted-foreground));
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  background-color: hsl(var(--muted) / 0.4);
}
.grid tbody tr { border-bottom: 1px solid hsl(var(--border)); transition: background-color .15s ease; }
.grid tbody tr:last-child { border-bottom: none; }
.grid tbody tr:hover { background-color: hsl(var(--muted) / 0.4); }
.grid td { padding: 10px 14px; text-align: left; white-space: nowrap; }
.grid .empty { text-align: center; color: hsl(var(--muted-foreground)); padding: 32px; }
.grid tfoot td { font-weight: 600; background-color: hsl(var(--muted) / 0.4); border-top: 1px solid hsl(var(--border)); padding: 10px 14px; }

/* =====================================================================
   Inputs / forms
   ===================================================================== */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }

.inline-form input,
.settings-row input,
.charge-form input {
  display: flex;
  height: 36px;
  width: 100%;
  min-width: 130px;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 12px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.inline-form input::placeholder,
.charge-form input::placeholder { color: hsl(var(--muted-foreground)); }
.inline-form input:focus,
.settings-row input:focus,
.charge-form input:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 1px hsl(var(--ring));
}

.settings-row { margin-bottom: 18px; color: hsl(var(--muted-foreground)); font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.settings-row input { width: 96px; min-width: 0; }

/* =====================================================================
   Modal / Dialog — shadcn
   ===================================================================== */
.modal {
  display: none;
  position: fixed; inset: 0; z-index: 50;
  background-color: rgb(0 0 0 / 0.8);
}
.modal.show {
  display: flex;
  align-items: flex-start; justify-content: center;
  padding: 3rem 1rem; overflow: auto;
}
.modal-box {
  width: 100%; max-width: 720px;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 10px 38px -10px rgb(0 0 0 / 0.5);
  padding: 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; }

.charge-form .form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.charge-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; color: hsl(var(--foreground)); }
.charge-form input { width: 100%; }

.preview {
  margin-top: 16px;
  background-color: hsl(var(--muted) / 0.4);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 14px;
}
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 16px; }
.preview-grid div { display: flex; flex-direction: column; gap: 2px; }
.preview-grid span { color: hsl(var(--muted-foreground)); font-size: 11.5px; }
.preview-grid b { font-size: 14px; font-weight: 600; }

.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* =====================================================================
   Theme toggle icon
   ===================================================================== */
#btn-theme { width: 36px; padding: 0; }
#btn-theme svg { width: 16px; height: 16px; }

/* =====================================================================
   Badge (optional accents)
   ===================================================================== */
.badge {
  display: inline-flex; align-items: center;
  border-radius: 9999px; border: 1px solid hsl(var(--border));
  padding: 1px 9px; font-size: 11px; font-weight: 500;
  color: hsl(var(--muted-foreground)); background-color: hsl(var(--background));
}

/* =====================================================================
   Selects (form + filters)
   ===================================================================== */
select {
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 10px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select:focus { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 1px hsl(var(--ring)); }
.charge-form select { width: 100%; }

/* =====================================================================
   Records filter bar
   ===================================================================== */
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar select, .filter-bar input[type="month"] {
  height: 36px; min-width: 130px;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 10px; font-size: 13px; font-family: inherit;
}
.filter-bar select:focus, .filter-bar input[type="month"]:focus {
  outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 1px hsl(var(--ring));
}

/* =====================================================================
   Compare tab
   ===================================================================== */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.compare-card { padding: 16px 18px 18px; }
.compare-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.compare-card .chart-wrap { height: 260px; margin-top: 14px; }

/* =====================================================================
   Settings modal
   ===================================================================== */
.settings-section { margin-bottom: 20px; }
.settings-section h4 { font-size: 13px; font-weight: 600; margin: 0 0 10px; }
.settings-section .field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; }
.field input { width: 100%; min-width: 0; }

.manage-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.manage-row { display: flex; align-items: center; gap: 8px; }
.manage-row .grow { flex: 1; font-size: 13px; font-weight: 500; }
.mini-input {
  height: 30px; width: 120px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 8px; font-size: 12px; font-family: inherit;
}
.mini-input:focus { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 1px hsl(var(--ring)); }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 720px) {
  .charts { grid-template-columns: 1fr; }
  .compare-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .topbar-actions { width: 100%; }
  .tabs { overflow-x: auto; }
  main { padding: 16px; }
}
