/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --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;
  --green-50:  #f0fdf4;
  --green-100: #dcfce7;
  --green-600: #16a34a;
  --green-700: #15803d;
  --red-50:   #fef2f2;
  --red-100:  #fee2e2;
  --red-600:  #dc2626;
  --red-700:  #b91c1c;
  --yellow-50:  #fefce8;
  --yellow-100: #fef9c3;
  --yellow-600: #ca8a04;
  --sidebar-w: 240px;
  --header-h:  56px;
  --radius:    6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 1px 4px rgba(0,0,0,.10);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--gray-200);
}
.sidebar-logo .company-name {
  font-size: .85rem;
  font-weight: 700;
  color: var(--gray-800);
  letter-spacing: .02em;
  text-transform: uppercase;
}
.sidebar-logo .app-name {
  font-size: .75rem;
  color: var(--gray-500);
  margin-top: 2px;
}

.sidebar-nav { padding: 12px 0; flex: 1; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  font-size: .875rem;
  color: var(--gray-600);
  border-radius: 0;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: var(--gray-50); color: var(--gray-900); text-decoration: none; }
.sidebar-nav a.active { background: var(--blue-50); color: var(--blue-700); font-weight: 600; }
.sidebar-nav .nav-section {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: 16px 20px 4px;
}
.sidebar-nav .nav-icon { width: 16px; text-align: center; opacity: .7; }

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--gray-200);
  font-size: .8rem;
  color: var(--gray-500);
}
.sidebar-footer a { color: var(--gray-500); }
.sidebar-footer a:hover { color: var(--gray-800); }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1rem; font-weight: 600; color: var(--gray-800); }
.topbar-user { font-size: .8rem; color: var(--gray-500); display: flex; align-items: center; gap: 12px; }

.page-content { padding: 28px; flex: 1; max-width: 1200px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: .9rem; font-weight: 600; color: var(--gray-800); }
.card-body { padding: 20px; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .75rem; color: var(--gray-500); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--gray-900); margin-top: 4px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--gray-50); }
tfoot td {
  padding: 10px 14px;
  font-weight: 600;
  color: var(--gray-800);
  border-top: 2px solid var(--gray-200);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--blue-600); color: #fff; border-color: var(--blue-600); }
.btn-primary:hover { background: var(--blue-700); border-color: var(--blue-700); }
.btn-secondary { background: #fff; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-danger    { background: var(--red-600); color: #fff; border-color: var(--red-600); }
.btn-danger:hover { background: var(--red-700); }
.btn-success   { background: var(--green-600); color: #fff; border-color: var(--green-600); }
.btn-success:hover { background: var(--green-700); }
.btn-sm { padding: 4px 10px; font-size: .78rem; }
.btn-xs { padding: 2px 8px; font-size: .72rem; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .8rem; font-weight: 600; color: var(--gray-700); margin-bottom: 5px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--gray-800);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-control::placeholder { color: var(--gray-400); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .75rem; color: var(--gray-500); margin-top: 4px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--blue-600); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ── Alerts / Flash ───────────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-success { background: var(--green-50); border-color: var(--green-100); color: var(--green-700); }
.alert-error   { background: var(--red-50);   border-color: var(--red-100);   color: var(--red-700); }
.alert-info    { background: var(--blue-50);  border-color: var(--blue-100);  color: var(--blue-700); }
.alert-warning { background: var(--yellow-50); border-color: var(--yellow-100); color: var(--yellow-600); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-blue   { background: var(--blue-100);  color: var(--blue-700); }
.badge-green  { background: var(--green-100); color: var(--green-700); }
.badge-red    { background: var(--red-100);   color: var(--red-700); }
.badge-gray   { background: var(--gray-100);  color: var(--gray-600); }
.badge-yellow { background: var(--yellow-100); color: var(--yellow-600); }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 1.25rem; font-weight: 700; color: var(--gray-900); }
.page-header p  { font-size: .85rem; color: var(--gray-500); margin-top: 2px; }

/* ── Dashboard grid ───────────────────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  margin-top: 20px;
}
@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* ── Timeline ─────────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 9px; top: 0; bottom: 0;
  width: 2px;
  background: var(--gray-200);
}
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-dot {
  position: absolute;
  left: -24px;
  top: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--blue-600);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--blue-200);
}
.timeline-dot.green  { background: var(--green-600); box-shadow: 0 0 0 2px var(--green-100); }
.timeline-dot.red    { background: var(--red-600);   box-shadow: 0 0 0 2px var(--red-100); }
.timeline-dot.yellow { background: var(--yellow-600); box-shadow: 0 0 0 2px var(--yellow-100); }
.timeline-dot.gray   { background: var(--gray-400);  box-shadow: 0 0 0 2px var(--gray-200); }
.timeline-date { font-size: .75rem; color: var(--gray-400); margin-bottom: 2px; }
.timeline-title { font-size: .875rem; font-weight: 600; color: var(--gray-800); }
.timeline-desc  { font-size: .8rem; color: var(--gray-500); margin-top: 2px; }

/* ── Login page ───────────────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
}
.auth-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .company { font-size: 1.1rem; font-weight: 700; color: var(--gray-900); }
.auth-logo .subtitle { font-size: .8rem; color: var(--gray-500); margin-top: 4px; }
.auth-card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.auth-card p  { font-size: .85rem; color: var(--gray-500); margin-bottom: 20px; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--gray-500); font-size: .8rem; }
.text-sm     { font-size: .8rem; }
.font-mono   { font-family: "SF Mono", "Fira Code", monospace; font-size: .82rem; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.w-full { width: 100%; }

/* ── HTMX loading indicator ───────────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--gray-300);
  border-top-color: var(--blue-600);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pie chart container ──────────────────────────────────────────────────── */
#ownership-chart { width: 100%; height: 300px; }

/* ── Percent bar ──────────────────────────────────────────────────────────── */
.pct-bar-wrap { background: var(--gray-100); border-radius: 999px; height: 6px; width: 100px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.pct-bar { height: 6px; border-radius: 999px; background: var(--blue-600); }
