:root {
  --navy: #10233F; --navy-2: #1F3864; --ink: #1a2333; --muted: #6B7A90; --line: #DDE3EC; --bg: #F4F6FA; --card: #fff;
  --accent: #2F5BEA; --ok: #1E8E5A; --warn: #B7791F; --bad: #C0392B;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }

.nav { background: var(--navy); color: #cfd8e8; padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; color: #fff; }
.brand .mark { width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--navy); font-weight: 800; display: grid; place-items: center; font-size: 18px; }
.brand small { display: block; color: #8fa2c3; font-size: 11px; }
.nav nav { display: flex; flex-direction: column; gap: 2px; }
.nav nav a { color: #cfd8e8; padding: 9px 10px; border-radius: 7px; }
.nav nav a:hover { background: rgba(255,255,255,.07); }
.nav nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; font-size: 12px; padding: 0 6px; }
.nav-foot a, .linklike { color: #8fa2c3; cursor: pointer; }
.nav-foot a:hover, .linklike:hover { color: #fff; }

main { padding: 22px 28px 60px; min-width: 0; }
h1 { font-size: 20px; margin: 0; }
.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.bar .grow { flex: 1; }

button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 7px; cursor: pointer; }
button:hover { border-color: #b8c3d6; }
button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.primary:hover { background: var(--navy-2); }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,91,234,.25); border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
input[type=checkbox] { width: auto; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.f > :not(span) { color: var(--ink); font-size: 14px; }
label.check { display: flex; align-items: center; gap: 7px; font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.chips { display: flex; gap: 6px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }

table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 12px; background: #FAFBFD; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px 12px; border-bottom: 1px solid #EEF1F6; vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr.click { cursor: pointer; } table.list tbody tr.click:hover { background: #F7F9FD; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .3px; }
.t-PR { background: #EAF0FF; color: #2A4FC2; } .t-PO { background: #E7F6EE; color: #17754A; } .t-PI { background: #FFF1DD; color: #9A5B0A; }
.s-draft { background: #EEF1F6; color: #55627A; } .s-sent { background: #E4F1FF; color: #1D64B8; } .s-converted, .s-confirmed { background: #E7F6EE; color: #17754A; } .s-cancelled { background: #FBE7E4; color: #B03325; }

/* editor */
.editor { display: grid; grid-template-columns: minmax(470px, 540px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1180px) { .editor { grid-template-columns: 1fr; } .preview-col { position: static; } .pv-wrap { height: 80vh; } }
.form { display: flex; flex-direction: column; gap: 14px; }
.form h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.preview-col { position: sticky; top: 14px; }
.preview-tabs { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 4px; display: flex; gap: 8px; flex-wrap: wrap; }

table.items { width: 100%; border-collapse: collapse; }
table.items th { font-size: 10.5px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 4px 4px; }
table.items td { padding: 3px 3px; vertical-align: top; }
table.items input, table.items select { padding: 5px 6px; font-size: 13px; }
.line-total { padding-top: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13px; text-align: right; }
.pack-row td { padding: 0 3px 8px; }
.pack { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; background: #F7F9FC; padding: 8px; border-radius: 7px; }
.pack label { font-size: 10.5px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.totals-box { margin-top: 10px; margin-left: auto; width: 280px; font-variant-numeric: tabular-nums; }
.totals-box div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.totals-box .grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 7px; color: var(--ink); font-weight: 700; font-size: 15px; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.warn { background: #FFF6E5; border: 1px solid #F1D9A8; color: #7A5510; padding: 8px 12px; border-radius: 8px; font-size: 13px; }

dialog { border: none; border-radius: 12px; padding: 0; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(16,35,63,.35); }
dialog::backdrop { background: rgba(16,35,63,.45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: 88vh; overflow: auto; }
dialog h2 { margin: 0; font-size: 17px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

#userbox { display: flex; flex-direction: column; gap: 4px; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.12); }
#userbox .who b { color: #fff; font-size: 13px; } #userbox .who small { display: block; color: #8fa2c3; }
body.anon { display: block; } body.anon .nav { display: none; } body.anon main { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(360px, 92vw); display: flex; flex-direction: column; gap: 14px; padding: 26px; }
.brand-lg { display: flex; gap: 10px; align-items: center; } .brand-lg small { display: block; color: var(--muted); font-size: 12px; }
.brand-lg .mark { width: 38px; height: 38px; border-radius: 9px; background: var(--navy); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 19px; }
.account { display: grid; gap: 16px; max-width: 760px; } .account h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
code.tok { display: block; margin-top: 6px; padding: 8px; background: #fff; border-radius: 6px; word-break: break-all; user-select: all; }

.todo { border-left: 4px solid var(--warn); } .todo.done { border-left-color: var(--ok); }
.todo ul { margin: 6px 0; padding-left: 18px; color: #7A5510; } .todo code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; }

input.bad { border-color: var(--bad); background: #FFF5F4; }

.preview-tabs .grow { flex: 1; }
.pv-wrap { position: relative; height: calc(100vh - 92px); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #525659; }
iframe.preview { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; opacity: 0; pointer-events: none; background: #525659; }
iframe.preview.on { opacity: 1; pointer-events: auto; }
.pv-msg { position: absolute; left: 10px; right: 10px; bottom: 10px; background: #FFF6E5; border: 1px solid #F1D9A8; color: #7A5510; padding: 8px 12px; border-radius: 8px; font-size: 12px; }
