:root {
  --bg: #f2f0eb;
  --surface: #fbfaf7;
  --fg: #1c1b19;
  --muted: #646058;
  --line: #dedad2;
  --accent: #c4161c;
  --accent-ink: #fff;
  --ok: #1f6b45;
  --warn: #b7791f;
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-size: 15px; line-height: 1.5; }
[hidden] { display: none !important; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(380px, 100%); display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: 0 12px 28px -18px rgba(0,0,0,.3); }
.login h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.02em; }
.login p { margin: 0; color: var(--muted); font-size: 14px; }

/* Shell */
header.top { display: flex; align-items: center; gap: 18px; padding: 12px 24px; background: var(--fg); color: #fff; flex-wrap: wrap; }
header.top .brand { font-weight: 700; letter-spacing: -0.01em; margin-right: 8px; }
header.top nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
header.top nav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; color: #d8d4cc; font-weight: 500; font-size: 14px; }
header.top nav a.active, header.top nav a:hover { background: #fff2; color: #fff; }
header.top button { background: none; border: 1px solid #fff4; color: #fff; border-radius: 999px; padding: 5px 14px; cursor: pointer; font-size: 13px; }
main { max-width: 1100px; margin: 0 auto; padding: 24px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }

/* Forms */
label.f { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, select, textarea { width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 14.5px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c4161c55; border-color: var(--accent); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.inline { display: flex; gap: 6px; }
.inline input { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 16px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #a3121a; }
.btn.danger { color: var(--accent); }
.btn.small { padding: 4px 11px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: progress; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 8px; }

.msg { padding: 9px 12px; border-radius: 9px; font-size: 14px; margin-bottom: 14px; white-space: pre-line; }
.msg.err { color: var(--accent); background: #c4161c12; border: 1px solid #c4161c44; }
.msg.ok { color: var(--ok); background: #1f6b4512; border: 1px solid #1f6b4544; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #00000006; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 28px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.draft { background: #e8e5de; color: var(--muted); }
.badge.sent { background: #b7791f22; color: var(--warn); }
.badge.paid { background: #1f6b4522; color: var(--ok); }
.badge.overdue { background: #c4161c1c; color: var(--accent); }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; min-width: 160px; }
.stat b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.filters { display: flex; gap: 6px; }
.filters button[aria-pressed="true"] { background: var(--fg); color: #fff; border-color: var(--fg); }

/* Line items */
.items td { padding: 5px 6px; }
.items input { padding: 6px 8px; }
.items .c-desc { width: 55%; }
.items .c-unit, .items .c-qty { width: 14%; }
.items .x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 0 6px; }
.items .x:hover { color: var(--accent); }
.totals { margin-left: auto; width: min(320px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin-top: 12px; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); padding-top: 6px; }
.totals .r { text-align: right; }

@media (max-width: 700px) {
  main { padding: 16px; }
  .hide-sm { display: none; }
  .items .c-desc { width: auto; }
}
