:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #dbe2ea;
  --text: #172033;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { height: 60px; display: flex; align-items: center; gap: 24px; padding: 0 28px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { color: var(--text); font-weight: 800; font-size: 18px; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.topbar nav a { color: var(--muted); padding: 8px 10px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: #eef4ff; color: var(--primary); text-decoration: none; }
.shell { width: min(1180px, calc(100vw - 32px)); margin: 28px auto 56px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; margin-bottom: 14px; }
p { color: var(--muted); margin: 6px 0; }

.panel, .stats > div { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: 0 1px 2px rgb(15 23 42 / 0.04); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stats span { display: block; color: var(--muted); font-size: 13px; }
.stats strong { display: block; margin-top: 8px; font-size: 24px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 700; padding: 0 10px 10px; border-bottom: 1px solid var(--line); }
td { padding: 12px 10px; border-bottom: 1px solid #edf1f5; vertical-align: top; }
td small { display: block; color: var(--muted); margin-top: 3px; }
tr:last-child td { border-bottom: 0; }
.right { text-align: right; }
.actions { text-align: right; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 30px; }
.muted-row { opacity: 0.65; }

.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 999px; background: #eef4ff; color: #1e40af; font-size: 12px; font-weight: 700; }
.toolbar { display: flex; gap: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

button, .button, .buttonish { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; border: 1px solid var(--primary); background: var(--primary); color: #fff; border-radius: 6px; padding: 0 13px; font: inherit; font-weight: 700; cursor: pointer; }
button:hover, .button:hover, .buttonish:hover { background: var(--primary-dark); text-decoration: none; }
.ghost { background: #fff; border-color: var(--line); color: var(--text); }
.ghost:hover { background: #f8fafc; color: var(--text); }
.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.danger-text { color: var(--danger); }

.stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 6px; color: #334155; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; color: var(--text); font: inherit; padding: 9px 10px; }
textarea { resize: vertical; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }
.inline-form { display: flex; gap: 8px; align-items: center; }

.item-editor { display: grid; gap: 14px; }
.item-row { display: grid; grid-template-columns: 1fr 2fr 0.65fr 0.65fr 0.85fr 0.65fr 1.6fr auto; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfdff; }
.item-row .wide { min-width: 0; }
.line-total { display: grid; gap: 6px; justify-items: end; font-weight: 800; }

.totals { margin-left: auto; width: min(360px, 100%); display: grid; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.totals div { display: flex; justify-content: space-between; gap: 14px; padding: 10px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.totals div:last-child { border-bottom: 0; }
.totals .grand { background: #eef4ff; color: var(--primary); font-size: 18px; }

.login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg, #edf4ff, #f8fafc); }
.login-panel { width: min(420px, calc(100vw - 32px)); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 26px; box-shadow: 0 20px 50px rgb(15 23 42 / 0.12); }
.login-panel h1 { margin-bottom: 18px; }
.alert { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 6px; padding: 10px 12px; margin-bottom: 14px; }

@media (max-width: 900px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 14px 16px; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  .stats, .split, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .page-head { flex-direction: column; }
  .item-row { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}
