:root {
    --paper: #f5f4ef;
    --card: #ffffff;
    --ink: #1c2230;
    --ink-2: #5b6272;
    --line: #e2dfd6;
    --head: #ffffff;
    --brand-red: #e30613;
    --primary: #33358f;
    --ok: #1f6b4f;
    --primary-ink: #ffffff;
    --pending: #9a5b00;
    --pending-bg: #fff1d6;
    --edit: #2b5aa8;
    --edit-bg: #e3ecfb;
    --ok-bg: #dff1e7;
    --danger: #b3261e;
    --danger-bg: #fde4e1;
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--font); }
a { color: var(--primary); }
h1 { font-size: 1.75rem; line-height: 1.2; margin: .2em 0 .3em; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 1.6em 0 .6em; }
h3 { font-size: 1rem; margin: 0 0 .3em; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 560px; }
.muted { color: var(--ink-2); }
.small, .small-v { font-size: .875rem; }
.strong { font-weight: 600; }
[hidden] { display: none !important; }

/* Header */
.top { background: var(--head); color: var(--ink); border-bottom: 4px solid var(--brand-red); box-shadow: 0 1px 0 var(--line); }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 78px; flex-wrap: wrap; }
.brand { color: var(--ink); text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.brand img { height: 60px; width: auto; display: block; border-radius: 4px; }
.brand .sub { font-size: .95rem; color: var(--ink-2); border-left: 1px solid var(--line); padding-left: 12px; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { color: var(--ink-2); font-weight: 600; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .95rem; }
.top nav a:hover, .top nav a.on { background: #f1f0eb; color: var(--ink); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand-red); color: #fff; font-size: .75rem; font-weight: 700; text-align: center; line-height: 20px; vertical-align: 1px; }
h2 .count { background: var(--line); color: var(--ink); }
main.wrap { padding-top: 24px; padding-bottom: 40px; }
.foot { color: var(--ink-2); font-size: .8rem; padding-bottom: 24px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9c5b9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #efc2bd; }
.btn.danger:hover { background: var(--danger-bg); }
.small-btn { padding: 5px 10px; font-size: .85rem; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--danger); font: inherit; font-size: .8rem; cursor: pointer; text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; background: var(--ok-bg); border: 1px solid #b9dfc9; }
.flash.error { background: var(--danger-bg); border-color: #f2bdb7; color: #6d150f; }
.flash.info { background: var(--pending-bg); border-color: #f0d394; color: #5c3a00; }
.flash ul { margin: 0; padding-left: 18px; }

/* Cards & forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.form { display: grid; gap: 14px; }
.form h2 { margin: 6px 0 -4px; font-size: 1rem; }
label { display: grid; gap: 5px; font-weight: 600; font-size: .92rem; }
input, textarea { width: 100%; font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #cfcbbf; border-radius: 8px; padding: 9px 11px; }
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row2.align-top { align-items: start; }
.money { position: relative; display: block; }
.money::before { content: "$"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-2); font-weight: 400; }
.money input { padding-left: 24px; font-family: var(--mono); }
.form > .btn { justify-self: start; }
.back { margin: 0 0 6px; font-size: .9rem; }
.back a { text-decoration: none; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2 { display: inline; margin: 0; }
details > summary::before { content: "▸"; display: inline-block; width: 1.2em; color: var(--ink-2); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
details[open] > summary { margin-bottom: 14px; }

/* List */
.list-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; }
.list-head p { margin: 0; }
.search { display: flex; gap: 8px; margin: 16px 0; }
.search input { font-size: 1.05rem; padding: 11px 14px; }
table.list { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); padding: 10px 14px; border-bottom: 1px solid var(--line); background: #faf9f6; }
.list td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list tbody tr:last-child td { border-bottom: 0; }
#list tbody tr { cursor: pointer; }
#list tbody tr:hover td { background: #fbfaf6; }
.list .name a { color: var(--ink); font-weight: 600; text-decoration: none; }
.list .name a:hover { text-decoration: underline; }
.list .price { font-family: var(--mono); font-size: .95rem; }
.list .n { text-align: center; color: var(--ink-2); width: 60px; }
.list tr.is-pending .name a { color: var(--ink-2); }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; vertical-align: 2px; }
.badge.pending { background: var(--pending-bg); color: var(--pending); }
.badge.edit { background: var(--edit-bg); color: var(--edit); margin-left: 6px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.empty { text-align: center; padding: 28px; margin-top: 12px; }
.empty p { margin: 0 0 14px; }

/* Detail page */
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.title-row h1 { margin-right: 4px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 10px 0 8px; }
.fact { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.fact .k { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); font-weight: 600; }
.fact .v { font-size: 1.6rem; font-weight: 700; font-family: var(--mono); }
.fact .v.small-v { font-family: var(--font); font-size: 1.1rem; padding-top: 6px; }
section { margin-top: 8px; }
.suggestion { margin-bottom: 12px; display: grid; gap: 10px; }
.card-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.card-head .muted { font-size: .85rem; }
table.diff { width: 100%; border-collapse: collapse; font-size: .92rem; }
.diff th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); padding: 4px 8px; }
.diff td { padding: 6px 8px; border-top: 1px solid var(--line); }
.diff .old { color: var(--ink-2); text-decoration: line-through; }
.diff .new { font-weight: 700; color: var(--ok); }
.reason { margin: 0; font-size: .92rem; }
.note-form { gap: 10px; margin-bottom: 14px; }
.note-row { display: flex; gap: 8px; }
.note-row input { max-width: 260px; }
ul.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.notes li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.notes li.sys { background: transparent; border-style: dashed; font-size: .88rem; color: var(--ink-2); }
.notes li.sys .note-body { font-family: var(--mono); font-size: .82rem; }
.note-meta { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: .85rem; margin-bottom: 4px; }
.note-meta form.inline { margin-left: auto; }
.note-body { white-space: normal; overflow-wrap: anywhere; }
.danger-zone { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); }
.login { margin: 4vh auto 0; }
.login-logo { display: block; width: 100%; max-width: 360px; height: auto; margin: 0 auto 20px; border-radius: 6px; }

/* Phones: tables become stacked cards */
@media (max-width: 720px) {
    h1 { font-size: 1.45rem; }
    .brand img { height: 44px; }
    .brand .sub { display: none; }
    .row2, .facts { grid-template-columns: 1fr; }
    .fact { grid-template-columns: 1fr auto; align-items: center; }
    .fact .v { font-size: 1.25rem; text-align: right; }
    .fact .v.small-v { padding-top: 0; }
    .search .btn { display: none; }
    table.list, .list tbody, .list tr, .list td { display: block; width: 100%; }
    .list thead { display: none; }
    table.list { background: transparent; border: 0; }
    .list tbody tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 0; }
    .list td { border: 0; padding: 4px 14px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .list td::before { content: attr(data-label); color: var(--ink-2); font: .8rem var(--font); text-align: left; }
    .list td.name { font-size: 1.05rem; text-align: left; display: block; padding-bottom: 6px; }
    .list td.name::before, .list td.actions-cell::before { content: none; }
    .list .n { width: auto; text-align: right; }
    .list td.n:empty { display: none; }
    .note-row { flex-direction: column; }
    .note-row input { max-width: none; }
}
