/* ---------- Tokens ---------- */
:root {
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --bg: #f7f7f9;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e6e7eb;
  --border-strong: #d4d6dc;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #8a909c;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --green: #059669;  --green-soft: #e7f7f0;
  --blue: #2563eb;   --blue-soft: #e8f0fe;
  --red: #dc2626;    --red-soft: #fdeceb;
  --amber: #b45309;  --amber-soft: #fdf3e2;
  --gray-soft: #f0f1f3;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 4px 8px -4px rgba(16, 24, 40, .06);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 248px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d0f14;
  --surface: #151820;
  --surface-2: #1c2029;
  --border: #262b36;
  --border-strong: #343a47;
  --text: #eef0f4;
  --text-2: #a8afbd;
  --text-3: #6f7686;
  --accent: #6d67f0;
  --accent-hover: #7f7af4;
  --accent-soft: #23234a;
  --green: #34d399;  --green-soft: #12291f;
  --blue: #60a5fa;   --blue-soft: #14233b;
  --red: #f87171;    --red-soft: #341819;
  --amber: #fbbf24;  --amber-soft: #2f2410;
  --gray-soft: #222632;
  --shadow-sm: none;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv11', 'ss01';
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; z-index: 40;
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15.5px; padding: 4px 8px 22px; letter-spacing: -.01em; }
.brand b { color: var(--accent); font-weight: 700; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a .count { margin-left: auto; font-size: 11.5px; background: var(--red-soft); color: var(--red); padding: 1px 7px; border-radius: 99px; font-weight: 600; }
.sidebar-foot { margin-top: auto; }
.ai-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; font-size: 12.5px; color: var(--text-2); background: var(--surface-2); }
.ai-card strong { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin-bottom: 4px; }
.ai-card svg { width: 15px; height: 15px; color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--green); }
.dot.off { background: var(--text-3); }
.profile { display: flex; align-items: center; gap: 10px; padding: 12px 6px 0; margin-top: 12px; border-top: 1px solid var(--border); }
.profile-name { font-weight: 600; font-size: 13px; }
.profile-mail { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 60px;
  display: flex; align-items: center; gap: 12px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.search { position: relative; flex: 1; max-width: 420px; }
.search input {
  width: 100%; height: 36px; padding: 0 12px 0 36px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { position: absolute; left: 11px; top: 9px; color: var(--text-3); }
.search-icon svg { width: 17px; height: 17px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar .menu-btn { display: none; }
.content { padding: 28px; max-width: 1280px; width: 100%; margin: 0 auto; outline: none; }
.scrim { display: none; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { color: var(--text-2); margin-top: 3px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 500; margin-bottom: 10px; font-size: 13px; }
.back-link:hover { color: var(--text); }
.back-link svg { width: 16px; height: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-danger-solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-solid:hover { filter: brightness(.95); background: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-ai { color: var(--accent); }
.btn-ai:hover { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 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: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 15px; }
.card-head .link { color: var(--accent); font-weight: 500; font-size: 13px; }
.card-body { padding: 20px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.kpi { padding: 18px 20px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--text-2); font-weight: 500; font-size: 13px; }
.kpi-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin: 10px 0 4px; }
.kpi-meta { font-size: 12.5px; color: var(--text-3); }
.kpi-meta b { font-weight: 600; }
.up { color: var(--green); } .down { color: var(--red); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-blue { background: var(--blue-soft); color: var(--blue); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-accent { background: var(--accent-soft); color: var(--accent); }
.dash-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); margin-bottom: 16px; }

/* Chart */
.chart { width: 100%; height: 240px; display: block; stroke: none; stroke-width: 0; }
.chart text { stroke: none; fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .bar { fill: var(--accent); opacity: .9; transition: opacity .15s; }
.chart .bar.current { opacity: 1; }
.chart .bar.past { opacity: .55; }
.chart g:hover .bar { opacity: 1; }
.chart .bar-label { fill: var(--text-2); font-weight: 600; opacity: 0; transition: opacity .15s; }
.chart g:hover .bar-label { opacity: 1; }
.chart-summary { display: flex; gap: 28px; margin-bottom: 14px; flex-wrap: wrap; }
.chart-summary div span { display: block; font-size: 12px; color: var(--text-3); }
.chart-summary div b { font-size: 18px; font-weight: 600; }

.stack { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-2); gap: 2px; margin: 4px 0 18px; }
.stack span { display: block; height: 100%; }
.legend { display: flex; flex-direction: column; gap: 12px; }
.legend-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend-row .sw { width: 9px; height: 9px; border-radius: 3px; }
.legend-row .val { margin-left: auto; font-weight: 600; }
.legend-row .cnt { color: var(--text-3); width: 30px; text-align: right; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .sub { font-size: 12.5px; color: var(--text-3); }
a.list-item:hover { background: var(--surface-2); }

.avatar {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.avatar.lg { width: 42px; height: 42px; font-size: 14px; border-radius: 10px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-draft { background: var(--gray-soft); color: var(--text-2); }
.badge-sent { background: var(--blue-soft); color: var(--blue); }
.badge-paid { background: var(--green-soft); color: var(--green); }
.badge-overdue { background: var(--red-soft); color: var(--red); }
.chip { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table .right { text-align: right; }
.table .strong { font-weight: 600; }
.cell-client { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-client .avatar { width: 28px; height: 28px; font-size: 11px; border-radius: 7px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 8px; overflow-x: auto; max-width: 100%; }
.tab { border: 0; background: transparent; padding: 5px 11px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: 13px; white-space: nowrap; transition: background .15s, color .15s; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab .n { color: var(--text-3); margin-left: 4px; font-size: 12px; }
.toolbar .spacer { flex: 1; }
.toolbar .input, .toolbar .select { height: 32px; width: auto; }
.toolbar .search-sm { position: relative; }
.toolbar .search-sm svg { position: absolute; left: 9px; top: 8px; width: 16px; height: 16px; color: var(--text-3); }
.toolbar .search-sm .input { padding-left: 32px; width: 220px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 80px; line-height: 1.5; }
.select { appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a909c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 16px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.invalid, .select.invalid { border-color: var(--red); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-section + .form-section { margin-top: 16px; }
.input-group { display: flex; gap: 8px; }
.input-group .select { flex: 1; }
.input-suffix { position: relative; }
.input-suffix span { position: absolute; right: 11px; top: 9px; color: var(--text-3); pointer-events: none; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.editor-side { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 16px; }

/* Item rows */
.items-head, .item-row { display: grid; grid-template-columns: minmax(0, 1fr) 80px 110px 110px 34px; gap: 10px; align-items: start; }
.items-head { font-size: 12px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; padding: 0 0 8px; }
.item-row { padding: 10px 0; border-top: 1px solid var(--border); animation: fadeIn .2s ease; }
.item-desc { display: flex; flex-direction: column; gap: 6px; }
.item-desc .textarea { min-height: 38px; height: 38px; resize: none; overflow: hidden; padding-top: 8px; }
.item-desc-tools { display: flex; align-items: center; gap: 6px; }
.item-amount { height: 38px; display: flex; align-items: center; justify-content: flex-end; font-weight: 600; }
.items-head .r { text-align: right; }

.totals { display: flex; flex-direction: column; gap: 10px; }
.totals-row { display: flex; justify-content: space-between; align-items: center; color: var(--text-2); }
.totals-row b { color: var(--text); font-weight: 500; }
.totals-row.total { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 2px; color: var(--text); font-weight: 600; font-size: 16px; }
.totals-row.total b { font-weight: 700; font-size: 20px; }
.totals-row.balance b { color: var(--accent); font-weight: 700; }

/* ---------- Invoice paper ---------- */
.view-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.paper {
  background: #fff; color: #111827; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 48px 52px; font-size: 13.5px; position: relative; overflow: hidden;
}
.paper .muted { color: #6b7280; }
.paper-top { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 40px; }
.paper-brand { display: flex; gap: 12px; align-items: flex-start; }
.paper-brand .brand-mark { background: #4f46e5; }
.paper-brand h2 { font-size: 17px; }
.paper-title { text-align: right; }
.paper-title h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; color: #4f46e5; }
.paper-title .no { font-weight: 600; margin-top: 2px; }
.paper-meta { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 24px; margin-bottom: 32px; }
.paper-meta .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8a909c; font-weight: 600; margin-bottom: 6px; }
.paper-meta .v { line-height: 1.6; white-space: pre-line; }
.paper table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.paper th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8a909c; font-weight: 600; text-align: left; padding: 10px 0; border-bottom: 1.5px solid #111827; }
.paper td { padding: 14px 0; border-bottom: 1px solid #e6e7eb; vertical-align: top; }
.paper th.r, .paper td.r { text-align: right; padding-left: 16px; }
.paper-totals { margin-left: auto; width: 280px; display: flex; flex-direction: column; gap: 8px; }
.paper-totals div { display: flex; justify-content: space-between; }
.paper-totals .grand { border-top: 1.5px solid #111827; padding-top: 10px; font-weight: 700; font-size: 16px; }
.paper-totals .due { background: #f3f4f6; padding: 8px 10px; border-radius: 6px; font-weight: 700; margin-top: 4px; }
.paper-notes { margin-top: 36px; padding-top: 20px; border-top: 1px solid #e6e7eb; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.paper-notes .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8a909c; font-weight: 600; margin-bottom: 6px; }
.paper-notes p { white-space: pre-line; color: #4b5563; }
.stamp {
  display: inline-block; margin-top: 12px; padding: 3px 12px; border: 2px solid; border-radius: 6px;
  font-size: 13px; font-weight: 700; letter-spacing: .14em; transform: rotate(-6deg); opacity: .85;
}
.stamp.paid { color: #059669; }
.stamp.overdue { color: #dc2626; }

.timeline { display: flex; flex-direction: column; }
.pay-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.pay-row:last-child { border-bottom: 0; }
.pay-row .grow { flex: 1; min-width: 0; }
.pay-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--green-soft); color: var(--green); }
.pay-icon svg { width: 15px; height: 15px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 12px 0 4px; }
.progress span { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .4s ease; }
.action-list { display: flex; flex-direction: column; gap: 8px; }
.action-list .btn { justify-content: flex-start; width: 100%; }

/* ---------- Clients ---------- */
.client-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.client-card { padding: 18px; display: flex; flex-direction: column; gap: 14px; transition: border-color .15s, box-shadow .15s; }
.client-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.client-card-top { display: flex; gap: 12px; align-items: flex-start; }
.client-card-top .grow { flex: 1; min-width: 0; }
.client-card h3 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-card .sub { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px; background: var(--surface-2); border-radius: 8px; }
.client-stats span { display: block; font-size: 11.5px; color: var(--text-3); }
.client-stats b { font-size: 14px; font-weight: 600; }
.client-card-foot { display: flex; gap: 8px; }
.client-card-foot .btn { flex: 1; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 56px 24px; color: var(--text-2); }
.empty-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; margin: 0 auto 14px; background: var(--surface-2); color: var(--text-3); }
.empty h3 { color: var(--text); font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 18, .45); z-index: 100;
  display: grid; place-items: center; padding: 16px; animation: fadeIn .15s ease;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: pop .18s ease;
}
.modal.lg { max-width: 640px; }
.modal.sm { max-width: 420px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.modal-head h3 { font-size: 16px; }
.modal-head p { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
.ai-note { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.ai-note svg { width: 14px; height: 14px; color: var(--accent); }
.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 8px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 13px; color: var(--text-2); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Dropdown ---------- */
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 180px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 4px; display: none; animation: pop .12s ease;
}
.menu.open .menu-pop { display: block; }
.menu-pop button { display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left; color: var(--text); }
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop button.danger { color: var(--red); }
.menu-pop svg { width: 16px; height: 16px; color: var(--text-3); }
.menu-pop button.danger svg { color: var(--red); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px; min-width: 240px; max-width: 360px;
  background: #111827; color: #fff; box-shadow: var(--shadow-lg); font-weight: 500; font-size: 13.5px; animation: slideUp .2s ease;
}
:root[data-theme="dark"] .toast { background: #eef0f4; color: #111827; }
.toast svg { width: 17px; height: 17px; color: #34d399; }
.toast.error svg { color: #f87171; }
.toast.hide { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(4px); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } }
.view-enter { animation: viewIn .22s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-main, .editor, .view-layout { grid-template-columns: minmax(0, 1fr); }
  .editor-side { position: static; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(10, 12, 18, .4); z-index: 35; animation: fadeIn .2s; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; gap: 8px; }
  .content { padding: 20px 16px 40px; }
  .paper { padding: 32px 24px; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 20px; }
  .kpi-icon { display: none; }
  .topbar .btn-primary .btn-label { display: none; }
  .topbar .btn-primary { width: 36px; padding: 0; }
  .page-head h1 { font-size: 19px; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .card-head .ai-note { display: none; }
  .toolbar .search-sm, .toolbar .search-sm .input, .toolbar .select { width: 100%; }

  /* Tables become cards */
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 16px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
  .table.responsive tr:last-child { border-bottom: 0; }
  .table.responsive td { padding: 0; border: 0; }
  .table.responsive td[data-m="hide"] { display: none; }
  .table.responsive td[data-m="tl"] { grid-area: 1 / 1; min-width: 0; }
  .table.responsive td[data-m="tr"] { grid-area: 1 / 2; text-align: right; }
  .table.responsive td[data-m="bl"] { grid-area: 2 / 1; min-width: 0; font-size: 12.5px; color: var(--text-3); }
  .table.responsive td[data-m="br"] { grid-area: 2 / 2; text-align: right; }
  .table.responsive td[data-m="bl"] .avatar { display: none; }

  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr 34px; }
  .item-row .item-desc { grid-column: 1 / -1; }
  .item-row .item-amount { grid-column: 1 / 3; justify-content: flex-start; height: auto; }
  .item-row .item-amount::before { content: 'Amount:'; font-weight: 400; color: var(--text-3); margin-right: 6px; }
  .item-row .remove { grid-row: 3; grid-column: 3; }

  .paper { padding: 24px 18px; font-size: 12.5px; }
  .paper-top { flex-direction: column; gap: 16px; }
  .paper-title { text-align: left; }
  .paper-meta, .paper-notes { grid-template-columns: 1fr; gap: 16px; }
  .paper-totals { width: 100%; }
  .chart-summary { gap: 18px; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
}

/* ---------- Print ---------- */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  .sidebar, .topbar, .toasts, .no-print, .view-side, .back-link, .page-head { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .view-layout { display: block; }
  .paper { border: 0; box-shadow: none; padding: 0; font-size: 12.5px; }
  .paper .stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .paper-totals .due, .paper-brand .brand-mark { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
