:root {
  --navy: #1F3864; --navy-2: #2c4a80; --ink: #1b1f27; --muted: #667085; --line: #e3e7ee; --bg: #f6f7fa;
  --card: #fff; --accent: #EDF1F8; --ok: #1f7a4d; --okbg: #e7f5ee; --err: #b42318; --errbg: #fdecea; --warn: #b54708;
  --r: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--navy-2); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 2px 0; } h3 { font-size: 15px; margin: 20px 0 8px; }
small { display: block; color: var(--muted); font-size: 12px; }

header.top { display: flex; align-items: center; gap: 24px; background: var(--navy); color: #fff; padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 20; }
header.top a { color: #dfe6f3; }
.brand { font-weight: 700; font-size: 16px; color: #fff !important; display: flex; align-items: center; gap: 8px; }
.logo { background: #fff; color: var(--navy); border-radius: 6px; padding: 2px 6px; font-size: 13px; }
header nav { display: flex; gap: 4px; flex: 1; }
header nav a { padding: 6px 12px; border-radius: 6px; }
header nav a.on, header nav a:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.me { font-size: 13px; color: #c7d2e6; }

main { padding: 20px 24px 80px; max-width: 1600px; margin: 0 auto; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.crumbs { font-size: 13px; color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; }
.notes { background: #fffbea; border: 1px solid #f1e3a6; padding: 8px 12px; border-radius: var(--r); margin-bottom: 12px; font-size: 13px; }

.btn { display: inline-block; border: 1px solid #cfd6e2; background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 6px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f5f9; text-decoration: none; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; } .btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--err); border-color: #f1b8b2; } .btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.sm { padding: 3px 9px; font-size: 13px; }
form.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: var(--r); margin-bottom: 12px; background: var(--okbg); color: var(--ok); }
.flash.err { background: var(--errbg); color: var(--err); }
.notice { background: #fff4e5; border: 1px solid #f7d3a1; color: #7a4a0a; padding: 10px 14px; border-radius: var(--r); margin-bottom: 14px; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; font-weight: normal; }
.empty { color: var(--muted); padding: 18px; text-align: center; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; color: var(--ink); }
.stat b { font-size: 24px; display: block; } .stat span { color: var(--muted); font-size: 13px; } .stat:hover { text-decoration: none; border-color: #b9c4d8; }

.filters, .toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
input, select, textarea { font: inherit; border: 1px solid #cfd6e2; border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--ink); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd0f2; border-color: #7c9bd1; }
input.warn { border-color: #f0b26b; background: #fff8ef; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #344054; }
.form .wide { grid-column: 1 / -1; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; }
.form.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.form h3 { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: 0; background: rgba(246,247,250,.96); padding: 10px 0; border-top: 1px solid var(--line); margin-top: 10px; z-index: 5; }
.danger-zone { margin-top: 30px; }
details.add summary { list-style: none; } details.add summary::-webkit-details-marker { display: none; }
details.add[open] { flex-basis: 100%; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; align-items: start; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 6px 0 14px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--navy); border-color: var(--navy); font-weight: 600; } .tabs a:hover { text-decoration: none; color: var(--ink); }

table.grid { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
table.grid th { background: var(--navy); color: #fff; font-weight: 600; font-size: 12.5px; text-align: left; padding: 8px; position: sticky; top: 52px; z-index: 2; }
table.grid td { padding: 7px 8px; border-top: 1px solid var(--line); vertical-align: top; }
table.grid tr:hover td { background: #fafbfd; }
table.grid tr.hl td { background: #fffbe6; }
td.n, th.n { text-align: right; white-space: nowrap; } td.r { text-align: right; } td.small, .small { font-size: 12.5px; color: #475467; }
td.late { color: var(--err); font-weight: 600; } .nowrap { white-space: nowrap; }
table.edit input, table.edit textarea { width: 100%; padding: 4px 6px; font-size: 13px; }
table.edit textarea { resize: vertical; min-height: 30px; }
table.edit td:nth-child(1) { width: 60px; } table.edit td:nth-child(4) { width: 90px; } table.edit td:nth-child(5) { width: 110px; }
.itemname { min-width: 220px; max-width: 380px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f6; color: #344054; white-space: nowrap; }
.st-new { background: #eef4ff; color: #3538cd; } .st-collecting { background: #fff4e5; color: #b54708; } .st-quoted { background: #f0e9ff; color: #6927da; }
.st-won { background: var(--okbg); color: var(--ok); } .st-lost { background: var(--errbg); color: var(--err); } .st-cancelled { background: #f2f4f7; color: #667085; }

.scroll { overflow-x: auto; border-radius: var(--r); }
table.compare th { top: 0; }
table.compare th.sup { min-width: 120px; background: #34507f; } table.compare th.sup small { color: #c9d4ea; font-weight: normal; }
table.compare th.calc { background: #14284a; }
table.compare td.calc { background: #f7f9fc; }
table.compare td.price { white-space: nowrap; }
table.compare td.price label { cursor: pointer; display: flex; gap: 5px; align-items: center; }
table.compare td.best { background: #e7f5ee; } table.compare td.best label { color: var(--ok); font-weight: 600; }
table.compare input[type=text], table.compare input:not([type]) { padding: 3px 5px; font-size: 13px; }
table.compare .margin.neg { color: var(--err); }
table.compare tr.unpriced .itemname { color: var(--muted); }
table.compare tfoot td { border-top: 2px solid var(--navy); font-weight: 600; background: var(--accent); padding: 8px; }

.login { max-width: 360px; margin: 10vh auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login h1 { margin-bottom: 16px; } .login form { display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

dialog.paste { border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(480px, 92vw); }
dialog.paste textarea { width: 100%; font-family: ui-monospace, Menlo, monospace; margin: 8px 0 12px; }
dialog::backdrop { background: rgba(16, 24, 40, .35); }

@media (max-width: 700px) {
  main { padding: 14px 12px 80px; }
  header.top { gap: 10px; padding: 0 12px; } .me { display: none; }
  table.grid th { top: 0; }
}
table.compare input.pct { width: 58px; } table.compare input.fixed { width: 72px; } table.compare input.sell { width: 92px; }
table.compare td.calc, table.compare th.calc { white-space: nowrap; }
table.compare td.price small { white-space: normal; max-width: 170px; }
