:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1c2430; --muted: #667085; --line: #e3e7ee;
  --pri: #1f3a5f; --pri2: #2d5a8c; --ok: #157a4a; --warn: #b54708; --bad: #b42318;
  --r: 10px; --side: 220px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
a { color: var(--pri2); }
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin-bottom: 10px; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: var(--pri); color: #dbe5f1; display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 650; color: #fff; }
.logo { background: #fff; color: var(--pri); border-radius: 8px; width: 32px; height: 32px; display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none; }
.cosel { display: flex; flex-direction: column; gap: 4px; padding: 0 16px 12px; font-size: 12px; color: #9fb3cc; }
.cosel select { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); font-weight: 600; padding: 8px; }
.cosel option { color: var(--ink); }
.cotag { display: inline-block; font-size: 11px; color: var(--muted); }
#brandName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav { display: flex; flex-direction: column; padding: 4px 8px; flex: 1; overflow-y: auto; }
nav a { color: inherit; text-decoration: none; padding: 10px 12px; border-radius: 8px; margin: 1px 0; }
nav a:hover { background: rgba(255,255,255,.08); }
nav a.on { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.me { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.me .link { color: #fff; }
main { flex: 1; margin-left: var(--side); min-width: 0; }
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); display: flex; align-items: center; gap: 12px; padding: 16px 24px 12px; flex-wrap: wrap; }
.top h1 { font-size: 1.35rem; flex: 1; min-width: 0; }
.menu { display: none; background: none; border: 0; font-size: 22px; padding: 4px 8px; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view { padding: 0 24px 40px; }
.scrim { display: none; }

@media (max-width: 860px) {
  .side { transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  main { margin-left: 0; }
  .menu { display: block; }
  .top { padding: 12px 14px 10px; }
  .top h1 { font-size: 1.15rem; flex-basis: calc(100% - 60px); overflow-wrap: anywhere; }
  .actions { width: 100%; }
  .actions:empty { display: none; }
  .view { padding: 0 12px 32px; }
}

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.two { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .two { grid-template-columns: 1fr; } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 1.35rem; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.ok .v { color: var(--ok); } .stat.bad .v { color: var(--bad); }

.btn { appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: #c5ccd8; }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.pri:hover { background: var(--pri2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--pri2); cursor: pointer; font: inherit; text-decoration: underline; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 160px; }

label.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 550; }
input, select, textarea { font: inherit; color: var(--ink); padding: 9px 10px; border: 1px solid #cfd5df; border-radius: 8px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b7cdea; border-color: var(--pri2); }
textarea { resize: vertical; min-height: 64px; }
.form { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.form .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }

.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f7f9fc; }
tfoot td { font-weight: 650; background: #fafbfc; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef2f7; color: var(--muted); }
.tag.bad { background: #fde8e6; color: var(--bad); }
.tag.ok { background: #e3f4ea; color: var(--ok); }
.tag.warn { background: #fdf0e1; color: var(--warn); }
.pos { color: var(--bad); } .neg { color: var(--ok); }

/* line editor */
.lines td { padding: 6px; }
.lines input, .lines select { padding: 7px 8px; }
.lines .w-item { min-width: 200px; }
.lines .w-num { width: 90px; }
.lines .w-sm { width: 70px; }
.totals { margin-left: auto; max-width: 340px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 1.2rem; font-weight: 700; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
@media (max-width: 700px) {
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
  .lines td, .lines td.n { border: 0; padding: 0; text-align: left; }
  .lines td.c-item { grid-column: 1 / -1; }
  .lines td::before { content: attr(data-l); display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
  .lines .w-item, .lines .w-num, .lines .w-sm { width: 100%; min-width: 0; }
  .lines td.c-amt { align-self: end; font-weight: 650; }
}

/* dialog */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(620px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.dh { padding: 16px 18px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 1.05rem; }
.db { padding: 16px 18px; overflow-y: auto; }
.df { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.err { color: var(--bad); font-size: 14px; margin-top: 10px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #1f3a5f, #2d5a8c); }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth h1 { font-size: 1.4rem; margin-bottom: 4px; }
.auth form { display: grid; gap: 12px; margin-top: 18px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2430; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: 70px 1fr; gap: 10px; align-items: center; font-size: 13px; }
.bar .t { display: flex; flex-direction: column; gap: 3px; }
.bar .s, .bar .p { height: 10px; border-radius: 4px; min-width: 2px; }
.bar .s { background: var(--pri2); } .bar .p { background: #e0a458; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
