/* ════════════════════════════════════════════════════
   SoloLedger — Design System
   Principles: quiet, precise, data-forward
   Inspired by Stripe, Linear, Clerk, Vercel
   ════════════════════════════════════════════════════ */

/* ── Design tokens ─────────────────────────────────── */
:root {
  /* Brand */
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;

  /* Semantic */
  --success: #22c55e;
  --success-bg: #dcfce7;
  --success-border: #bbf7d0;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --warning-border: #fde68a;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --info: #3b82f6;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;

  /* Neutrals */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Spacing — 4px grid */
  --space-1:  4px;  --space-2:  8px;  --space-3: 12px;
  --space-4: 16px;  --space-5: 20px;  --space-6: 24px;
  --space-8: 32px;  --space-10: 40px; --space-12: 48px;

  /* Shadows — layered */
  --shadow-sm:  0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -4px rgba(0,0,0,0.05);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.05);
  --shadow-btn: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px -1px rgba(0,0,0,0.1);

  /* Typography — Inter for data, Fraunces for display, JetBrains for amounts */
  --font-sans: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', 'Newsreader', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  font-size: 0.875rem;  /* 14px base */
  line-height: 1.5;
  color: var(--gray-800);
  background: linear-gradient(180deg, #f8fafc 0%, var(--gray-50) 480px, var(--gray-50) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-wrap: pretty;
}

/* ── Type scale ── */
.text-xs    { font-size: 0.75rem; line-height: 1.5; }
.text-sm    { font-size: 0.875rem; line-height: 1.5; }
.text-base  { font-size: 1rem; line-height: 1.5; }
.text-lg    { font-size: 1.125rem; line-height: 1.5; }
.text-xl    { font-size: 1.25rem; line-height: 1.5; }
.text-2xl   { font-size: 1.5rem; line-height: 1.3; }
.text-3xl   { font-size: 2rem; line-height: 1.2; }
.font-normal  { font-weight: 400; }
.font-medium  { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold    { font-weight: 700; }

/* ── Colors ── */
.text-primary  { color: var(--primary); }
.text-success  { color: var(--success); }
.text-warning  { color: var(--warning); }
.text-danger   { color: var(--danger); }
.text-muted    { color: var(--gray-500); }
.text-subtle   { color: var(--gray-400); }

/* ── Layout ── */
body { display: flex; min-height: 100vh; }
.main,
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: var(--space-8) var(--space-10);
  max-width: 1200px;
  width: calc(100% - 240px);
  box-sizing: border-box;
}

.container { max-width: 1200px; }
.flex-row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.flex-col { display: flex; flex-direction: column; gap: var(--space-3); }
.flex-1 { flex: 1; }
.gap-1 { gap: var(--space-1); }  .gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }  .gap-4 { gap: var(--space-4); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mr-2 { margin-right: var(--space-2); }

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  background: var(--gray-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 40;
  overflow-y: auto;
}
.logo {
  padding: var(--space-6) var(--space-5) var(--space-4);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.logo span { color: var(--primary); }
.sidebar nav { flex: 1; padding: var(--space-2) 0; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  color: var(--gray-400);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.12s;
  border-left: 2px solid transparent;
}
.sidebar nav a:hover {
  color: var(--gray-200);
  background: rgba(255,255,255,0.03);
}
.sidebar nav a.active {
  color: #fff;
  background: rgba(59,130,246,0.08);
  border-left-color: var(--primary);
}
.sidebar-footer {
  padding: var(--space-4) var(--space-5);
  font-size: 0.7rem;
  color: var(--gray-600);
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ── Page header ── refined hierarchy: display face + weight contrast */
.page-header { margin-bottom: var(--space-6); }
.page-header h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 var(--space-1);
  color: var(--gray-900);
  text-wrap: balance;
}
.page-header p {
  margin: 0;
  color: var(--gray-500);
  font-size: 0.875rem;
  font-weight: 400;
}
.page-header .meta {
  display: flex;
  gap: var(--space-5);
  margin-top: var(--space-2);
  font-size: 0.8125rem;
  color: var(--gray-500);
}
.page-header .meta span {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-4);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--gray-300); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}
.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-700);
  margin: 0;
}
.card-row {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

/* ── Stat cards ── staggered reveal, tabular mono for values */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  flex: 1;
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: var(--space-4) var(--space-5);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  position: relative;
  overflow: hidden;
  /* staggered entrance — respects prefers-reduced-motion */
  animation: statIn 0.45s ease both;
  animation-delay: calc(var(--i, 0) * 60ms);
}
.stat-card:hover {
  border-color: var(--gray-300);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
@keyframes statIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.stat-card .label {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--gray-400);
  margin-bottom: var(--space-1);
}
.stat-card .value {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat-card .value.green  { color: var(--success); }
.stat-card .value.blue   { color: var(--primary); }
.stat-card .value.red    { color: var(--danger); }
.stat-card .delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: var(--space-1);
}
.stat-card .delta.up   { background: var(--success-bg); color: #15803d; }
.stat-card .delta.down { background: var(--danger-bg); color: #dc2626; }
.stat-card .sparkline {
  position: absolute;
  bottom: 0; right: 0;
  opacity: 0.08;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
thead { position: sticky; top: 0; z-index: 1; }
th {
  background: var(--gray-50);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--gray-500);
  border-bottom: 1px solid var(--gray-200);
}
td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }
.amount { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Tags / Badges ── */
.tag, .badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: #15803d; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger  { background: var(--danger-bg);  color: #991b1b; }
.badge-info    { background: var(--info-bg);    color: #1e40af; }

.tag-green  { background: var(--success-bg); color: #15803d; }
.tag-red    { background: var(--danger-bg);  color: #991b1b; }
.tag-blue   { background: var(--info-bg);    color: #1e40af; }
.tag-gray   { background: var(--gray-100);   color: var(--gray-600); }
.tag-yellow { background: var(--warning-bg); color: #92400e; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4);
  border-radius: 7px;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.12s;
  white-space: nowrap;
  line-height: 1.4;
}
@media (prefers-reduced-motion: no-preference) {
  .btn:active { transform: scale(0.97); }
}
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.form-input:focus-visible, .form-select:focus-visible, .form-textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.sidebar nav a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.mobile-nav a:focus-visible,
.mobile-drawer-item:focus-visible,
a.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.toast-close:focus-visible,
.confirm-ok:focus-visible,
.confirm-cancel:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.modal-close:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:active { background: var(--primary-dark); }
.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-success:hover { background: #16a34a; border-color: #16a34a; }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #dc2626; }
.btn-outline {
  background: #fff;
  color: var(--gray-700);
  border-color: var(--gray-200);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-300); }
.btn-ghost {
  background: transparent;
  color: var(--gray-500);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-700); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: 0.75rem; }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: 0.9375rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn .icon { font-size: 1.1em; }

/* ── Form elements ── */
.form-group { margin-bottom: var(--space-4); }
.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: var(--space-1);
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--gray-800);
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 7px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-input::placeholder { color: var(--gray-400); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
.form-hint { font-size: 0.75rem; color: var(--gray-400); margin-top: var(--space-1); }
.form-error { font-size: 0.75rem; color: var(--danger); margin-top: var(--space-1); }
.input-sm { padding: var(--space-1) var(--space-2); font-size: 0.8125rem; }

/* ── Deadline list ── */
.deadline-list { list-style: none; margin: 0; padding: 0; }
.deadline-list li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.8125rem;
}
.deadline-list li:last-child { border-bottom: none; }
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }

/* ── Summary card ── */
.summary-card {
  background: linear-gradient(135deg, var(--gray-50), #fff);
  border-color: var(--gray-200);
}
.big-number { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.875rem;
}

/* ── Loading / Skeleton ── */
.skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}
.skeleton-line {
  height: 12px;
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 6px;
}
.skeleton-line.w-1\/4 { width: 25%; }
.skeleton-line.w-1\/3 { width: 33%; }
.skeleton-line.w-1\/2 { width: 50%; }
.skeleton-line.w-2\/3 { width: 66%; }
.skeleton-line.h-4 { height: 16px; }
.skeleton-line.h-6 { height: 24px; }
.skeleton-line.h-8 { height: 32px; }
.skeleton-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-4);
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

.loading {
  text-align: center;
  padding: var(--space-10);
  color: var(--gray-400);
}
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: var(--space-2);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error / Empty states ── */
.error-block {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  padding: var(--space-5);
  color: var(--danger);
}
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--gray-400);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: var(--space-3); }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--gray-600); margin: 0 0 var(--space-1); }
.empty-state p { font-size: 0.8125rem; margin: 0 0 var(--space-4); }

/* ── Trust panel ── */
.trust-panel {
  background: linear-gradient(135deg, #f0f9ff, #ecfdf5);
  border: 1px solid #a7f3d0;
  border-radius: 10px;
  padding: var(--space-4) var(--space-5);
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.trust-panel .icon { font-size: 1.25rem; }
.trust-panel strong { color: var(--gray-800); }
.trust-detail { color: var(--gray-500); font-size: 0.75rem; }

/* ── Toast / Alert ── */
.toast {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  z-index: 100;
  animation: slideIn 0.2s ease-out;
  box-shadow: var(--shadow-lg);
}
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-info    { background: var(--primary); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Content transitions ── */
#page-content {
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Accessibility utilities ── */
.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 9999;
  background: var(--primary); color: #fff; padding: 8px 16px;
  border-radius: 6px; font-size: 0.875rem; font-weight: 600;
  transform: translateY(-120%); transition: transform 0.15s;
  text-decoration: none;
}
.skip-link:focus {
  transform: translateY(0);
}
.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;
}

/* ── Color utility classes (replace hardcoded hex in JS inline styles) ── */
.text-error { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--gray-500); }
.text-muted-light { color: var(--gray-400); }
.text-body { color: var(--gray-600); }
.border-default { border-color: var(--gray-200); }
.bg-error { background: var(--danger-bg); }
.bg-success { background: var(--success-bg); }
.bg-warning { background: var(--warning-bg); }
.badge-danger { color: #dc2626; background: #fef2f2; }
.badge-success { color: #15803d; background: #f0fdf4; }
.badge-warning { color: #92400e; background: #fffbeb; }
.badge-info { color: #1e40af; background: #eff6ff; }
.border { border: 1px solid var(--gray-200); }
.border-error { border-color: var(--danger-border); }
.border-success { border-color: var(--success-border); }

/* ── Helper utilities ── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
code, .code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 1px 4px;
  background: var(--gray-100);
  border-radius: 4px;
}

/* ── Responsive: tablet ── */
@media (max-width: 1024px) {
  .sidebar { width: 60px; }
  .sidebar .logo { font-size: 0; padding: var(--space-4) 0; text-align: center; }
  .sidebar .logo::before { content: "SL"; font-size: 1rem; font-weight: 800; color: var(--primary); }
  .sidebar .logo span { display: none; }
  .sidebar nav a { padding: var(--space-3) 0; justify-content: center; font-size: 0; gap: 0; }
  .sidebar nav a::after { content: attr(data-label); font-size: 0; }
  .sidebar-footer { display: none; }
  .main,
  .main-content { margin-left: 60px; padding: var(--space-5) var(--space-5); width: calc(100% - 60px); }
  .stat-card { min-width: 140px; }
}

/* ── Responsive: mobile ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main,
  .main-content { margin-left: 0; padding: var(--space-4) var(--space-3) 70px; width: 100%; max-width: 100%; }
  .page-header { padding: 0 0 var(--space-3); }
  .page-header h1 { font-size: 1.125rem; }
  .page-header p { font-size: 0.8rem; }

  /* Cards */
  .card { padding: var(--space-4); }
  .card-row { flex-direction: column; gap: var(--space-2); }
  .stat-card { min-width: 100%; }
  .stat-card .value { font-size: 1.25rem; }

  /* Tables — horizontal scroll on mobile */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 0.7rem; min-width: 520px; }
  th, td { padding: var(--space-2) var(--space-2); white-space: nowrap; }

  /* Buttons — larger touch targets */
  .btn { padding: var(--space-3) var(--space-4); font-size: 0.8rem; min-height: 40px; }
  .btn-sm { padding: var(--space-2) var(--space-3); min-height: 36px; font-size: 0.75rem; }

  /* Inline flex wraps */
  .flex-row { flex-direction: column; align-items: stretch; }
  .flex-row > * { width: 100%; }

  /* Forms */
  .form-input, .form-select { font-size: 16px !important; /* prevent iOS zoom */ padding: 10px 12px; }

  /* Modal — full screen on mobile */
  .modal { max-width: 100%; width: 100%; border-radius: 12px 12px 0 0; margin-top: auto; max-height: 90vh; padding: 24px; }
  .modal-overlay { align-items: flex-end; }

  /* Stats inline */
  .stat { padding: var(--space-2) 0; }
  .stat .value { font-size: 1.1rem; }
  .stat .label { font-size: 0.7rem; }

  /* Trust panel */
  .trust-panel { flex-direction: column; text-align: center; gap: 4px; padding: var(--space-3); }

  /* Deadline list */
  .deadline-list li { flex-wrap: wrap; gap: 4px; }

  /* Summary card */
  .summary-card .big-number { font-size: 1.3rem; }

  /* Danger/error boxes */
  .error { padding: var(--space-3); font-size: 0.8rem; }

  /* Onboarding wizard */
  [id^="page-content"] .card[style*="max-width:560px"] { margin: 16px auto !important; }
  [id^="page-content"] .card[style*="max-width:560px"] .card[style*="padding:32px"] { padding: 20px !important; }

  /* Mobile bottom nav */
  .mobile-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    border-top: 1px solid var(--gray-200);
    z-index: 50;
    padding: var(--space-1) 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mobile-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-1) var(--space-1);
    font-size: 0.6rem;
    color: var(--gray-400);
    text-decoration: none;
    transition: color 0.12s;
    min-height: 44px;
    justify-content: center;
  }
  .mobile-nav a.active { color: var(--primary); }
  .mobile-nav a .icon { font-size: 1.2rem; }
  .mobile-nav a .nav-label { margin-top: 1px; }
}

.mobile-nav { display: none; }

/* ── Auth Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-xl);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--gray-100);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  transition: background 0.12s;
}

.modal-close:hover { background: var(--gray-200); }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--gray-400);
  font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}

/* ── Sidebar User ───────────────────────────────────────── */
.sidebar-user {
  padding: 12px 16px;
  border-top: 1px solid var(--gray-200);
  margin-top: auto;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  flex: 1;
  font-weight: 500;
  color: var(--gray-700);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-signin {
  font-size: 0.85rem;
}

.btn-ghost {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--gray-500);
  transition: background 0.12s;
}

.btn-ghost:hover { background: var(--gray-100); }

/* ── Mobile drawer ──────────────────────────────────────────── */
.mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  display: flex;
  justify-content: flex-end;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
}
.mobile-drawer-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.mobile-drawer {
  width: 280px;
  max-width: 82vw;
  height: 100vh;
  height: 100dvh;
  background: #fff;
  box-shadow: var(--shadow-xl);
  padding: 16px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
}
.mobile-drawer-overlay.visible .mobile-drawer {
  transform: translateX(0);
}
.mobile-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.mobile-drawer-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mobile-drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--gray-700);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.12s;
}

.mobile-drawer-item:hover { background: var(--gray-100); }
.mobile-drawer-item span { font-size: 1.1rem; }

/* ════════════════════════════════════════════════════
   Dark Mode
   ════════════════════════════════════════════════════ */
/* Dark theme is applied via data-theme="dark" on <html>, resolved by the
   app (system mode follows prefers-color-scheme through matchMedia). */
[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-hover: #93bbfd;
  --primary-light: #1e3a5f;
  --primary-dark: #3b82f6;

  --success: #4ade80;
  --success-bg: #14532d;
  --success-border: #166534;
  --warning: #fbbf24;
  --warning-bg: #451a03;
  --warning-border: #78350f;
  --danger: #f87171;
  --danger-bg: #450a0a;
  --danger-border: #7f1d1d;
  --info: #60a5fa;
  --info-bg: #1e3a5f;
  --info-border: #1e40af;

  --gray-50:  #111827;
  --gray-100: #1f2937;
  --gray-200: #374151;
  --gray-300: #4b5563;
  --gray-400: #6b7280;
  --gray-500: #9ca3af;
  --gray-600: #d1d5db;
  --gray-700: #e5e7eb;
  --gray-800: #f3f4f6;
  --gray-900: #f9fafb;

  --shadow-sm:  0 1px 2px 0 rgba(0,0,0,0.3);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,0.3);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.4);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.5);
  --shadow-btn: 0 1px 3px 0 rgba(0,0,0,0.4);

  background: #0f172a;
  color: var(--gray-800);
}
[data-theme="dark"] body { background: #0f172a; color: var(--gray-800); }
/* The sidebar is intentionally dark in BOTH themes; the flipped gray scale
   (--gray-900 → near-white) would otherwise blow it out to white-on-white. */
[data-theme="dark"] .sidebar { background: #0f172a; }
[data-theme="dark"] .sidebar nav a { color: #9ca3af; }
[data-theme="dark"] .sidebar nav a:hover { color: #e2e8f0; background: rgba(255,255,255,0.06); }
[data-theme="dark"] .sidebar nav a.active { color: #fff; background: rgba(59,130,246,0.18); border-left-color: var(--primary); }
[data-theme="dark"] .sidebar-footer { color: #64748b; }
[data-theme="dark"] .logo { color: #fff; border-bottom-color: rgba(255,255,255,0.08); }
[data-theme="dark"] .card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .skeleton-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .card:hover { border-color: #475569; }
[data-theme="dark"] .stat-card:hover { border-color: #475569; }
[data-theme="dark"] .page-header h1 { color: #f1f5f9; }
[data-theme="dark"] .btn-outline { background: transparent; color: #e2e8f0; border-color: #475569; }
[data-theme="dark"] .btn-outline:hover { background: #1e293b; border-color: #64748b; }
[data-theme="dark"] table { color: #e2e8f0; }
[data-theme="dark"] th { background: #1e293b; color: #94a3b8; border-bottom-color: #334155; }
[data-theme="dark"] td { border-bottom-color: #1e293b; color: #cbd5e1; }
[data-theme="dark"] tr:hover td { background: #0f172a; }
[data-theme="dark"] .table-wrap { border-color: #334155; }
[data-theme="dark"] .form-input, [data-theme="dark"] .form-select, [data-theme="dark"] .form-textarea {
  background: #0f172a; color: #e2e8f0; border-color: #334155;
}
[data-theme="dark"] .form-label { color: #94a3b8; }
[data-theme="dark"] .summary-card { background: linear-gradient(135deg, #1e293b, #0f172a); }
[data-theme="dark"] .summary-row { border-bottom-color: #1e293b; }
[data-theme="dark"] .trust-panel { background: linear-gradient(135deg, #0c3d3c, #1a2e3a); border-color: #166534; }
[data-theme="dark"] .trust-panel strong { color: #e2e8f0; }
[data-theme="dark"] .modal { background: #1e293b; }
[data-theme="dark"] .modal-close { background: #374151; color: #94a3b8; }
[data-theme="dark"] .auth-divider::before,
[data-theme="dark"] .auth-divider::after { background: #334155; }
[data-theme="dark"] .sidebar { background: #0f172a; }
[data-theme="dark"] .deadline-list li { border-bottom-color: #1e293b; }
[data-theme="dark"] .tag-gray { background: #374151; color: #94a3b8; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { color-scheme: dark; }
[data-theme="dark"] .mobile-nav { background: #0f172a; border-top-color: #334155; }
[data-theme="dark"] .mobile-nav a { color: #64748b; }
[data-theme="dark"] .mobile-nav a.active { color: var(--primary); }
[data-theme="dark"] .code { background: #374151; color: #e2e8f0; }
[data-theme="dark"] .toast { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.6); }
[data-theme="dark"] .sidebar-user { border-top-color: #334155; }
[data-theme="dark"] .user-name { color: #e2e8f0; }
[data-theme="dark"] .btn-ghost { color: #94a3b8; }
[data-theme="dark"] .btn-ghost:hover { background: #1e293b; color: #e2e8f0; }
[data-theme="dark"] .mobile-drawer { background: #1e293b; }
[data-theme="dark"] .mobile-drawer-item { color: #e2e8f0; }
[data-theme="dark"] .mobile-drawer-item:hover { background: #334155; }
[data-theme="dark"] .mobile-drawer-header { color: #f1f5f9; }
[data-theme="dark"] .stat-card .delta.up { background: #14532d; color: #4ade80; }
[data-theme="dark"] .stat-card .delta.down { background: #450a0a; color: #f87171; }
[data-theme="dark"] .badge-success { background: #14532d; color: #4ade80; }
[data-theme="dark"] .badge-warning { background: #451a03; color: #fbbf24; }
[data-theme="dark"] .badge-danger { background: #450a0a; color: #f87171; }
[data-theme="dark"] .badge-info { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .tag-green { background: #14532d; color: #4ade80; }
[data-theme="dark"] .tag-red { background: #450a0a; color: #f87171; }
[data-theme="dark"] .tag-blue { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .tag-yellow { background: #451a03; color: #fbbf24; }

/* ── Improved Toast System ── */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  position: relative;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  animation: slideIn 0.2s ease-out;
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 420px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-info    { background: var(--primary); color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }
.toast-close {
  margin-left: auto;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 2px 6px;
  opacity: 0.7;
  transition: opacity 0.12s;
  line-height: 1;
}
.toast-close:hover { opacity: 1; }

/* ── Confirm Modal ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.12s ease-out;
}
.confirm-modal {
  background: #fff;
  border-radius: 12px;
  padding: var(--space-6);
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-xl);
}
[data-theme="dark"] .confirm-modal { background: #1e293b; }
.confirm-modal h3 {
  margin: 0 0 var(--space-2);
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
}
.confirm-modal p {
  margin: 0 0 var(--space-5);
  font-size: 0.875rem;
  color: var(--gray-500);
  line-height: 1.5;
}
.confirm-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* ── Icon button (theme toggle + drawer close) ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--gray-500);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.icon-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[data-theme="dark"] .icon-btn { color: #94a3b8; }
[data-theme="dark"] .icon-btn:hover { background: #334155; color: #e2e8f0; }

/* ── Dark mode toggle ── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: rgba(255,255,255,0.06);
  color: var(--gray-400);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.12s;
  margin-right: var(--space-2);
}
.theme-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }
[data-theme="dark"] .theme-toggle { color: #fbbf24; }
[data-theme="dark"] .theme-toggle:hover { background: rgba(255,255,255,0.1); }

/* ── Loading Bar ── */
.loading-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  z-index: 9999;
  width: 0%;
  opacity: 0;
  transition: width 0.3s ease, opacity 0.2s ease;
}
.loading-bar.active {
  opacity: 1;
  animation: loading-progress 1.5s ease-in-out forwards;
}
@keyframes loading-progress {
  0% { width: 0%; }
  30% { width: 30%; }
  60% { width: 65%; }
  85% { width: 85%; }
  100% { width: 90%; }
}
.loading-bar.done {
  opacity: 1;
  width: 100% !important;
  transition: width 0.15s ease;
}
.loading-bar.fade-out {
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* ── Scrollbar gutter stability ── */
html { scrollbar-gutter: stable; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Print styles ── */
@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  .sidebar, .mobile-nav, .mobile-drawer-overlay, .modal-overlay,
  .loading-bar, .toast-container, .confirm-overlay,
  .btn, .btn-primary, .btn-outline, .btn-danger, .btn-success,
  .btn-ghost, button, .theme-toggle, .sidebar-signin, .sidebar-user,
  [onclick] { display: none !important; }
  .main,
  .main-content { margin-left: 0 !important; padding: 0 !important; max-width: 100% !important; width: 100% !important; }
  .card { break-inside: avoid; box-shadow: none !important; border: 1px solid #ddd !important; }
  table { break-inside: auto; }
  tr { break-inside: avoid; }
  .stat-card, .stat { break-inside: avoid; }
  .page-header { margin-bottom: 12pt; }
  h1 { font-size: 16pt; }
  h2 { font-size: 13pt; }
  a { color: #000 !important; text-decoration: underline; }
  .tag { border: 1px solid #999 !important; background: transparent !important; color: #000 !important; }
  .trust-panel, .summary-card { break-inside: avoid; }
}
