/* ─── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --green-900: #14532d;
  --green-700: #15803d;
  --green-600: #16a34a;
  --green-500: #22c55e;
  --green-100: #dcfce7;
  --green-50:  #f0fdf4;

  --gray-950: #0a0f0b;
  --gray-900: #111827;
  --gray-700: #374151;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50:  #f9fafb;

  --red-600:  #dc2626;
  --red-100:  #fee2e2;
  --red-700:  #b91c1c;

  --amber-500: #f59e0b;
  --amber-100: #fef3c7;

  --blue-600:  #2563eb;
  --blue-100:  #dbeafe;

  --white: #ffffff;
  --ink:   var(--gray-900);
  --muted: var(--gray-500);
  --line:  var(--gray-200);
  --bg:    var(--gray-50);

  --radius-sm: 0.375rem;
  --radius:    0.625rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.06);
  --shadow:    0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 10px 15px rgba(0,0,0,0.07), 0 4px 6px rgba(0,0,0,0.05);

  --sidebar-w: 220px;
  --topbar-h:  60px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
h1,h2,h3,h4 { margin: 0; font-weight: 700; line-height: 1.25; }
p { margin: 0 0 0.5rem; }
a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

/* ─── Auth screens ───────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--green-50) 0%, var(--white) 60%, var(--gray-100) 100%);
  padding: 1.5rem;
}

.auth-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  max-width: 460px;
  width: 100%;
  padding: 2.5rem;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.auth-logo-mark {
  width: 44px;
  height: 44px;
  background: var(--green-700);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.35rem;
  font-weight: 900;
  flex-shrink: 0;
}

.auth-logo h1 {
  font-size: 1.5rem;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.auth-card h2 {
  font-size: 1.2rem;
  color: var(--ink);
  margin-bottom: 0.4rem;
}

.auth-card p { color: var(--muted); font-size: 0.9rem; }

.auth-card .hint {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--gray-400);
}

.auth-error {
  background: var(--red-100);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  color: var(--red-700);
  font-size: 0.85rem;
  padding: 0.65rem 0.85rem;
  margin-top: 1rem;
}

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

/* sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 20;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.sidebar-logo-mark {
  width: 34px;
  height: 34px;
  background: var(--green-700);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  font-weight: 900;
  flex-shrink: 0;
}

.sidebar-logo span {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-400);
  padding: 0.5rem 0.5rem 0.25rem;
  margin-top: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  color: var(--gray-700);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.nav-item:hover { background: var(--gray-100); color: var(--ink); }

.nav-item.active {
  background: var(--green-50);
  color: var(--green-700);
  font-weight: 700;
}

.nav-item .icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--green-100);
  color: var(--green-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.8rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--muted); text-transform: capitalize; }

/* main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.topbar-right { display: flex; align-items: center; gap: 0.65rem; }

.page { padding: 1.75rem; flex: 1; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  line-height: 1;
  transition: background 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}

.btn-primary   { background: var(--green-700); color: white; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--green-900); }

.btn-secondary { background: var(--white); color: var(--gray-700); border: 1px solid var(--line); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--gray-50); }

.btn-danger    { background: var(--red-100); color: var(--red-700); }
.btn-danger:hover { background: #fecaca; }

.btn-ghost     { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--gray-100); color: var(--ink); }

.btn-sm { font-size: 0.8rem; padding: 0.35rem 0.7rem; }
.btn-xs { font-size: 0.75rem; padding: 0.25rem 0.55rem; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { display: grid; gap: 0.3rem; }

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-700);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  transition: border-color 0.12s, box-shadow 0.12s;
  appearance: auto;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}

textarea { min-height: 5rem; resize: vertical; }

.form-grid { display: grid; gap: 1rem; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

.form-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.25rem 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding-top: 1rem;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.card-title { font-size: 1rem; font-weight: 700; color: var(--ink); }
.card-sub   { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }

/* ─── Stat cards ─────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1rem; margin-bottom: 1.5rem; }

.stat-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1;
}

.stat-value.positive { color: var(--green-700); }
.stat-value.negative { color: var(--red-600); }

.stat-card.accent-green { border-top: 3px solid var(--green-600); }
.stat-card.accent-blue  { border-top: 3px solid var(--blue-600); }
.stat-card.accent-amber { border-top: 3px solid var(--amber-500); }
.stat-card.accent-red   { border-top: 3px solid var(--red-600); }

/* ─── Grids ──────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 1.25rem; }

/* ─── Toolbar ────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.toolbar .form-group { flex: 1; min-width: 180px; }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875rem;
}

thead th {
  background: var(--gray-50);
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.85rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
}

tbody td {
  border-bottom: 1px solid var(--line);
  padding: 0.8rem 0.85rem;
  vertical-align: middle;
  color: var(--ink);
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--green-50); }
tbody tr.vehicleRow:hover td { cursor: pointer; }

.td-primary   { font-weight: 600; color: var(--ink); }
.td-secondary { font-size: 0.78rem; color: var(--muted); margin-top: 0.1rem; }
.td-actions   { display: flex; align-items: center; gap: 0.4rem; }

/* ─── Badges / status pills ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-purchased { background: var(--gray-100);  color: var(--gray-700); }
.badge-listed    { background: var(--blue-100);   color: var(--blue-600); }
.badge-sold      { background: var(--green-100);  color: var(--green-700); }
.badge-archived  { background: var(--gray-100);   color: var(--gray-500); }
.badge-overdue   { background: var(--red-100);    color: var(--red-700); }
.badge-pending   { background: var(--amber-100);  color: #92400e; }

.role-badge {
  background: var(--green-100);
  color: var(--green-700);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  text-transform: capitalize;
}

/* ─── Money values ───────────────────────────────────────────────────────── */
.money-pos { color: var(--green-700); font-weight: 700; }
.money-neg { color: var(--red-600);   font-weight: 700; }

/* ─── Documents / thumbs ─────────────────────────────────────────────────── */
.thumbs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.thumb-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
}

.thumb-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background: var(--gray-100);
}

.thumb-file {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--gray-50);
  color: var(--gray-400);
}

.thumb-body {
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.thumb-type  { font-size: 0.75rem; font-weight: 700; color: var(--green-700); }
.thumb-note  { font-size: 0.78rem; color: var(--muted); }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--gray-900);
  color: white;
  border-radius: var(--radius);
  padding: 0.75rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 999;
  animation: toast-in 0.2s ease;
}

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

/* ─── Misc helpers ───────────────────────────────────────────────────────── */
.muted    { color: var(--muted); }
.hidden   { display: none !important; }
.mt-1     { margin-top: 0.5rem; }
.mt-2     { margin-top: 1rem; }
.mt-3     { margin-top: 1.5rem; }
.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state .empty-icon { font-size: 2rem; margin-bottom: 0.5rem; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    transform: translateX(-220px);
    transition: transform 0.22s ease;
    width: 220px;
  }

  .sidebar.open { transform: translateX(0); }

  .main-content { margin-left: 0; }

  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  .form-grid-2,
  .form-grid-3,
  .form-grid-4 { grid-template-columns: 1fr; }

  .page { padding: 1rem; }

  .topbar { padding: 0 1rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
