:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --card-2: #fafbfc;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e2e5ea;
  --input: #ffffff;
  --brand: #e4007c;
  --brand-dark: #b8005f;
  --brand-ring: #f6bfe0;
  --accent: #0098d8;
  --ok: #157347; --ok-bg: #ecf8f1; --ok-line: #bfe6cf;
  --err: #b42318; --err-bg: #fdf2f1; --err-line: #f1c2bd;
  --warn: #b7791f; --warn-bg: #fff4d6;
  --void-bg: #eeeeee;
  --login-bg: linear-gradient(135deg, #fde8f3 0%, #e3f2fb 50%, #fff6d9 100%);
  --shadow: 0 10px 30px rgba(0,0,0,.08);
  --radius: 8px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1c2029;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --line: #2a2f3a;
  --input: #11141a;
  --brand: #ff2d95;
  --brand-dark: #e4007c;
  --brand-ring: #5a1a3f;
  --accent: #5cc3ff;
  --ok: #4ade80; --ok-bg: #0f2a1b; --ok-line: #1f5a36;
  --err: #ff7b6b; --err-bg: #2d1512; --err-line: #6b2a24;
  --warn: #fbbf24; --warn-bg: #2d230c;
  --void-bg: #2a2f3a;
  --login-bg: radial-gradient(1200px 600px at 20% 10%, #2a0f22 0%, transparent 60%), radial-gradient(900px 500px at 90% 90%, #0b2538 0%, transparent 60%), #0f1115;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.r { text-align: right; }
.c { text-align: center; }

/* top bar */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 24px;
  flex-wrap: wrap;
}
.brand img { height: 42px; display: block; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 8px 12px; border-radius: 6px; color: var(--text); font-weight: 500; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: var(--brand); color: #fff; }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.topbar .user > a:first-child { color: var(--text); }

.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px; border-top: 1px solid var(--line); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* buttons */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--err); border-color: var(--err-line); }
.btn-danger:hover { background: var(--err-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* flash */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.flash-error { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat .num { display: block; font-size: 28px; font-weight: 600; }
.stat .lbl { color: var(--muted); font-size: 13px; }

/* tables */
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: var(--card-2); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--card-2); }
.table .inactive { color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.badge-draft { background: var(--warn-bg); color: var(--warn); }
.badge-issued { background: var(--ok-bg); color: var(--ok); }
.badge-void { background: var(--void-bg); color: var(--muted); text-decoration: line-through; }

/* forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card h2 { margin-top: 0; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--input);
}
label input:focus, label select:focus, label textarea:focus, .lines input:focus { outline: 2px solid var(--brand-ring); border-color: var(--brand); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
label.check input { width: auto; margin: 0; }
textarea { min-height: 72px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 20px; }
@media (max-width: 720px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.searchbar { display: flex; gap: 8px; margin-bottom: 14px; }
.searchbar input { flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: var(--input); color: var(--text); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }

/* invoice lines editor */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 12px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 4px 6px; }
.lines td { padding: 3px 4px; vertical-align: middle; }
.lines input { width: 100%; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--input); color: var(--text); }
.lines input.num { text-align: right; }
.lines .amount { text-align: right; white-space: nowrap; padding-right: 10px; }
.lines .remove { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; }
.lines .remove:hover { color: var(--err); }
.totals { display: flex; justify-content: flex-end; margin-top: 10px; }
.totals table td { padding: 4px 12px; }
.totals .grand { font-size: 18px; font-weight: 700; }

/* invoice view */
.doc-head { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.doc-head dl { margin: 0; }
.doc-head dt { font-size: 12px; text-transform: uppercase; color: var(--muted); margin-top: 8px; }
.doc-head dd { margin: 0; white-space: pre-line; }

/* login */
.login-body { align-items: center; justify-content: center; background: var(--login-bg); }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 32px; width: 360px; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.login-logo { display: block; width: 220px; margin: 0 auto 12px; }
.login-card h1 { text-align: center; font-size: 20px; margin-bottom: 16px; }

/* theme toggle */
.theme-toggle { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; line-height: 1; }
.theme-toggle:hover { border-color: var(--brand); }
:root[data-theme="dark"] .theme-toggle .sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
.theme-toggle .sun { display: none; }
.brand img, .login-logo { background: #fff; border-radius: 6px; padding: 3px 6px; }
.login-card .theme-toggle { position: absolute; top: 12px; right: 12px; }
.login-card { position: relative; }
