:root {
  --bg: #0c0e12;
  --bg-elevated: #13161d;
  --bg-card: #181c26;
  --bg-hover: #1e2330;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #e8eaef;
  --text-muted: #8b92a5;
  --text-dim: #5c6378;
  --accent: #c9a962;
  --accent-soft: rgba(201, 169, 98, 0.15);
  --accent-glow: rgba(201, 169, 98, 0.35);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: 'DM Sans', system-ui, sans-serif;
  --font-display: 'Instrument Serif', Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Auth */
.auth-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, rgba(201,169,98,0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(99,102,241,0.06) 0%, transparent 50%),
              var(--bg);
}

.auth-card {
  width: 100%; max-width: 380px; padding: 2.5rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}

.auth-logo {
  font-family: var(--font-display);
  font-size: 2rem; font-weight: 400; color: var(--accent);
  margin-bottom: 0.25rem;
}

.auth-sub { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

.auth-card input {
  width: 100%; padding: 0.75rem 1rem; margin-bottom: 0.75rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; transition: border-color 0.2s;
}

.auth-card input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; text-align: center; }

/* Layout */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex; flex-direction: column; gap: 1.5rem;
  position: sticky; top: 0; height: 100vh;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 0.5rem;
}

.brand-mark {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; font-size: 1rem;
}

.sidebar-brand h1 {
  font-family: var(--font-display);
  font-size: 1.35rem; font-weight: 400; line-height: 1.2;
}

.brand-tag { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.65rem 0.85rem; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  font: inherit; font-size: 0.9rem; cursor: pointer;
  transition: all 0.15s; text-align: left; width: 100%;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-item:hover { background: var(--bg-hover); color: var(--text); }

.nav-item.active {
  background: var(--accent-soft); color: var(--accent);
}

.sidebar-cta { margin-top: auto; }

.main {
  padding: 1.75rem 2rem 3rem;
  overflow-y: auto;
  max-height: 100vh;
}

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1.5rem; margin-bottom: 2rem; flex-wrap: wrap;
}

.topbar h2 {
  font-family: var(--font-display);
  font-size: 1.75rem; font-weight: 400;
}

.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.15rem; }

.topbar-search {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.5rem 1rem;
  min-width: 260px;
}

.topbar-search svg { width: 16px; height: 16px; color: var(--text-dim); flex-shrink: 0; }

.topbar-search input {
  border: none; background: transparent; color: var(--text);
  font: inherit; width: 100%; outline: none;
}

.topbar-search input::placeholder { color: var(--text-dim); }

/* Views */
.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.35rem;
}

.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.stat-value {
  font-family: var(--font-display);
  font-size: 2.25rem; font-weight: 400; line-height: 1;
}

.stat-success { border-color: rgba(74, 222, 128, 0.2); background: linear-gradient(135deg, var(--bg-card), var(--success-soft)); }
.stat-success .stat-value { color: var(--success); }

.stat-warn { border-color: rgba(251, 191, 36, 0.2); background: linear-gradient(135deg, var(--bg-card), var(--warn-soft)); }
.stat-warn .stat-value { color: var(--warn); }

/* Panel */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h3 { font-size: 0.95rem; font-weight: 600; }

.badge {
  background: var(--accent-soft); color: var(--accent);
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
}

/* Dealer cards (dashboard) */
.dealer-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1px;
  background: var(--border);
}

.dealer-card {
  background: var(--bg-card);
  padding: 1.25rem;
  cursor: pointer;
  transition: background 0.15s;
}

.dealer-card:hover { background: var(--bg-hover); }

.dealer-card h4 { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }

.dealer-card .meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }

.todo-progress {
  display: flex; gap: 0.35rem; flex-wrap: wrap;
}

.todo-dot {
  width: 28px; height: 6px; border-radius: 3px;
  background: var(--border-strong);
}

.todo-dot.done { background: var(--success); }

/* Table */
.dealer-table-wrap { overflow-x: auto; }

.dealer-table {
  width: 100%; border-collapse: collapse;
}

.dealer-table th, .dealer-table td {
  padding: 0.85rem 1.25rem;
  text-align: left; border-bottom: 1px solid var(--border);
}

.dealer-table th {
  font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-dim);
  font-weight: 600;
}

.dealer-table tr { cursor: pointer; transition: background 0.12s; }
.dealer-table tbody tr:hover { background: var(--bg-hover); }

.dealer-table .name-cell { font-weight: 500; }

.progress-bar {
  display: flex; align-items: center; gap: 0.5rem;
}

.progress-track {
  flex: 1; height: 4px; background: var(--border-strong);
  border-radius: 2px; overflow: hidden; max-width: 80px;
}

.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }

.progress-text { font-size: 0.75rem; color: var(--text-muted); min-width: 32px; }

.empty-state {
  padding: 3rem; text-align: center; color: var(--text-muted);
}

.empty-state p { margin-bottom: 1rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem; border-radius: var(--radius-sm);
  font: inherit; font-size: 0.875rem; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent); color: #1a1510;
}
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 0 20px var(--accent-glow); }

.btn-accent {
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid rgba(201, 169, 98, 0.25);
  width: 100%;
}
.btn-accent:hover { background: rgba(201, 169, 98, 0.22); }

.btn-ghost {
  background: transparent; color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

.btn-danger-outline {
  background: transparent; color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
}
.btn-danger-outline:hover { background: var(--danger-soft); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* Form */
.dealer-form { max-width: 960px; }

.form-actions-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.75rem;
}

.form-actions-right { display: flex; gap: 0.5rem; }

.form-grid { display: flex; flex-direction: column; gap: 1.25rem; }

.form-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  border: none;
  margin: 0;
}

.form-section legend {
  font-size: 0.85rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--accent);
  padding: 0 0 0.75rem;
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.field { display: flex; flex-direction: column; gap: 0.35rem; position: relative; }
.field.span-2 { grid-column: span 2; }

.field span {
  font-size: 0.75rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}

.field input, .field select {
  padding: 0.6rem 0.85rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; transition: border-color 0.2s;
}

.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.toggle-sensitive {
  position: absolute; right: 8px; bottom: 8px;
  background: none; border: none; cursor: pointer;
  font-size: 0.85rem; opacity: 0.5; padding: 0.2rem;
}
.toggle-sensitive:hover { opacity: 1; }

/* Bank accounts */
.bank-list { display: flex; flex-direction: column; gap: 0.75rem; }

.bank-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto auto;
  gap: 0.65rem; align-items: end;
  padding: 0.85rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}

.bank-row .field input, .bank-row .field select { width: 100%; }

.btn-remove-bank {
  background: var(--danger-soft); color: var(--danger);
  border: none; border-radius: var(--radius-sm);
  width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
  margin-bottom: 1px;
}

/* Todo checklist */
.todo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
}

.todo-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.85rem 1rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all 0.15s; user-select: none;
}

.todo-item input { display: none; }

.todo-check {
  width: 20px; height: 20px; border-radius: 6px;
  border: 2px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}

.todo-item input:checked + .todo-check {
  background: var(--success); border-color: var(--success);
}

.todo-item input:checked + .todo-check::after {
  content: '✓'; color: #0c0e12; font-size: 0.75rem; font-weight: 700;
}

.todo-item:has(input:checked) {
  border-color: rgba(74, 222, 128, 0.25);
  background: var(--success-soft);
}

.todo-item:has(input:checked) span:last-child {
  text-decoration: line-through; color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000;
  padding: 0.75rem 1.25rem;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 0.875rem; animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    height: auto; flex-direction: row; padding: 0.5rem;
    border-right: none; border-top: 1px solid var(--border);
    z-index: 100; gap: 0.5rem;
  }
  .sidebar-brand, .sidebar-cta { display: none; }
  .sidebar-nav { flex-direction: row; flex: 1; }
  .nav-item { flex: 1; justify-content: center; padding: 0.6rem; font-size: 0.75rem; }
  .nav-item span { display: none; }
  .main { padding-bottom: 5rem; max-height: none; }
  .field-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }
  .bank-row { grid-template-columns: 1fr; }
}
