/* Accounthinx — Master Plan 5 · Clean SMB SaaS Design System
   Exact Online / Moneybird / Silverfin language
   Inter + JetBrains Mono · 8px cards · white canvas
*/

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --primary: #1e3a5f;
  --primary-600: #162c4a;
  --primary-700: #0e1e34;
  --accent: #2563eb;
  --canvas: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --subtle: #94a3b8;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #2563eb;
  --sidebar: #0f172a;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

html.dark {
  --canvas: #0b1220;
  --surface: #111827;
  --border: #1f2937;
  --border-strong: #374151;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --subtle: #64748b;
  --sidebar: #020617;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--canvas);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.font-mono, .mono, [data-money] {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

[x-cloak] { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 999;
  padding: 0.5rem 1rem; background: var(--primary); color: #fff; font-size: 12px;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.875rem 1rem; border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 {
  margin: 0; font-size: 13px; font-weight: 600; color: var(--text);
}
.card-body { padding: 1rem; }
.card-link { text-decoration: none; color: inherit; display: block; transition: border-color 150ms ease, box-shadow 150ms ease; }
.card-link:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }

/* ── KPI ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.125rem;
}
.kpi-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  text-transform: uppercase; color: var(--muted); margin: 0;
}
.kpi-value {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--text); margin: 0.25rem 0 0; letter-spacing: -0.02em;
}
.kpi-value.success { color: var(--success); }
.kpi-value.warning { color: var(--warning); }
.kpi-value.danger { color: var(--danger); }
.kpi-delta { font-size: 11px; color: var(--subtle); margin: 0.2rem 0 0; }

/* ── Page chrome ── */
.page { max-width: 1280px; margin: 0 auto; }
.page-title { font-size: 18px; font-weight: 700; color: var(--text); margin: 0; letter-spacing: -0.02em; }
.page-sub { font-size: 12px; color: var(--muted); margin: 0.2rem 0 0; }
.section-header {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.section-header h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.5rem 0.875rem; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  text-decoration: none; transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--canvas); border-color: var(--border-strong); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn-secondary { background: #eff6ff; color: var(--accent); border-color: #bfdbfe; }
.btn-secondary:hover { background: #dbeafe; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--canvas); color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-sm { padding: 0.3rem 0.625rem; font-size: 11px; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; padding: 0.15rem 0.5rem;
  border-radius: 9999px; font-size: 11px; font-weight: 600; line-height: 1.4;
}
.badge-success { background: #ecfdf5; color: var(--success); }
.badge-warn { background: #fffbeb; color: var(--warning); }
.badge-danger { background: #fef2f2; color: var(--danger); }
.badge-info { background: #eff6ff; color: var(--info); }
.badge-default { background: #f1f5f9; color: var(--muted); }

html.dark .badge-success { background: rgba(5,150,105,.15); }
html.dark .badge-warn { background: rgba(217,119,6,.15); }
html.dark .badge-danger { background: rgba(220,38,38,.15); }
html.dark .badge-info { background: rgba(37,99,235,.15); }
html.dark .badge-default { background: rgba(148,163,184,.12); }

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  text-align: left; padding: 0.55rem 0.875rem;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
html.dark .data-table thead th { background: #0f172a; }
.data-table tbody td {
  padding: 0.65rem 0.875rem; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
html.dark .data-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.data-table .col-money {
  text-align: right;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums; font-weight: 500;
}
.data-table .credit { color: var(--success); }
.data-table .debit { color: var(--danger); }

/* ── Forms ── */
.form-label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text);
  margin-bottom: 0.35rem;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 0.55rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 13px;
  font-family: inherit; transition: border-color 120ms ease, box-shadow 120ms ease;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
}
.form-textarea { min-height: 88px; resize: vertical; }
.form-grid {
  display: grid; grid-template-columns: 1fr; gap: 0.875rem 1rem;
}
@media (min-width: 768px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .full { grid-column: 1 / -1; }
}

/* ── Layout helpers ── */
.split-layout { display: grid; gap: 1rem; }
@media (min-width: 1024px) {
  .split-layout { grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr); }
  .split-layout.split-7-5 { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
}
.split-main, .split-aside { min-width: 0; }

.doc-header {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: 0.75rem; padding: 1.125rem 1.25rem; margin-bottom: 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.doc-header-title {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 1.15rem; font-weight: 600; color: var(--text); margin: 0;
}
.doc-header-meta { font-size: 12px; color: var(--muted); margin: 0.3rem 0 0; }
.doc-header-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.filter-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  margin-bottom: 0.875rem; padding: 0.625rem 0.875rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-search {
  flex: 1; min-width: 160px; max-width: 280px;
  padding: 0.45rem 0.75rem 0.45rem 2rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--canvas); font-size: 12px; color: var(--text);
}
.filter-search:focus { outline: none; border-color: var(--primary); background: var(--surface); }

.tab-bar {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  margin-bottom: 1rem; overflow-x: auto;
}
.tab {
  padding: 0.6rem 0.9rem; font-size: 12px; font-weight: 600;
  color: var(--muted); border-bottom: 2px solid transparent;
  background: none; border-top: none; border-left: none; border-right: none;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Timeline ── */
.timeline { position: relative; padding-left: 1rem; }
.timeline::before {
  content: ''; position: absolute; left: 3px; top: 4px; bottom: 4px;
  width: 1px; background: var(--border);
}
.timeline-item { position: relative; padding: 0 0 0.85rem 0.85rem; }
.timeline-item::before {
  content: ''; position: absolute; left: -1rem; top: 5px;
  width: 7px; height: 7px; border-radius: 9999px;
  background: var(--primary); border: 2px solid var(--surface);
}
.timeline-time {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px; color: var(--subtle);
}
.timeline-actor { font-size: 11px; font-weight: 600; color: var(--muted); }
.timeline-action { font-size: 12px; color: var(--text); margin-top: 0.1rem; }

/* ── Sidebar ── */
.sidebar-shell {
  background: var(--sidebar);
  color: #e2e8f0;
}
.sidebar-group-label {
  padding: 0.5rem 0.875rem 0.25rem;
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #64748b;
}
.sidebar-link {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.45rem 0.875rem; margin: 0 0.5rem;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  color: #94a3b8; text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #f1f5f9; }
.sidebar-link.active {
  background: rgba(37, 99, 235, 0.2); color: #fff;
}
.sidebar-link .badge-count {
  margin-left: auto; font-size: 10px; font-weight: 700;
  background: #2563eb; color: #fff; padding: 0.1rem 0.4rem; border-radius: 9999px;
}

/* ── Totals / empty / misc ── */
.totals-box {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
html.dark .totals-box { background: #0f172a; }
.totals-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.3rem 0; font-size: 13px; color: var(--muted);
}
.totals-row.is-total {
  border-top: 1px solid var(--border); margin-top: 0.4rem; padding-top: 0.55rem;
  font-weight: 700; color: var(--text); font-size: 15px;
}
.totals-row .val {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text);
}

.empty-state {
  text-align: center; padding: 2.5rem 1rem; color: var(--muted); font-size: 13px;
}

.sticky-footer {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem;
  padding: 0.875rem 1rem; margin-top: 1rem;
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(15,23,42,0.04);
}

.insight-row {
  display: flex; align-items: flex-start; gap: 0.75rem;
  padding: 0.75rem 0; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
}
.insight-row:last-child { border-bottom: none; }
.insight-row:hover .insight-title { color: var(--accent); }
.insight-icon {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 14px;
}
.insight-title { font-size: 13px; font-weight: 600; color: var(--text); margin: 0; }
.insight-sub { font-size: 12px; color: var(--muted); margin: 0.15rem 0 0; }

.health-ring {
  width: 88px; height: 88px; border-radius: 9999px;
  display: flex; align-items: center; justify-content: center;
  background: conic-gradient(var(--success) calc(var(--pct, 72) * 1%), #e2e8f0 0);
}
.health-ring-inner {
  width: 68px; height: 68px; border-radius: 9999px;
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 1.25rem; font-weight: 700; color: var(--text);
}

.line-items { width: 100%; border-collapse: collapse; font-size: 13px; }
.line-items th {
  text-align: left; padding: 0.45rem 0.5rem; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  border-bottom: 1px solid var(--border); background: #f8fafc;
}
.line-items td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); }
.line-items input, .line-items select {
  width: 100%; padding: 0.4rem 0.5rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 12px; background: var(--surface);
}

.toast-enter { animation: toastIn 200ms ease; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast-progress { animation: toastBar 3s linear forwards; }
@keyframes toastBar {
  from { width: 100%; }
  to { width: 0%; }
}

@media print {
  .no-print, .sidebar-shell, header { display: none !important; }
  main { padding: 0 !important; }
}

@media (max-width: 640px) {
  input, select, textarea { font-size: 16px !important; }
}
