:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1b2230; --muted: #667085; --line: #e3e6eb; --soft: #f0f2f5;
  --accent: #0f6e66; --accent-ink: #fff; --accent-soft: #e3f2f0;
  --danger: #b4322a; --danger-soft: #fbeceb; --warn: #9a5b00; --warn-soft: #fff4e0; --ok: #127a52; --ok-soft: #e5f5ee;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }
.top { grid-column: 1 / 3; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; }
.brand span { color: var(--accent); }
.top .rest { color: var(--muted); }
.top .grow { flex: 1; }
.pubbar { display: flex; align-items: center; gap: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 8px; overflow-y: auto; }
.side .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.side a { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.side a:hover { background: var(--soft); }
.side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side a .n { color: var(--muted); font-size: 12px; }
main { overflow-y: auto; padding: 20px 24px 60px; }
.head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.head .grow { flex: 1; }

/* Controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5cad3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; padding: 4px 6px; color: var(--accent); }
.btn.tiny { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 4px; }
label.field > input[type=text], label.field > input[type=number], label.field > input[type=password], label.field > select { width: 100%; }
label.field > small { display: block; color: var(--muted); margin-top: 3px; }
label.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.row { display: flex; gap: 12px; align-items: flex-start; }
.row > * { flex: 1; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { width: 260px; }

/* Cards and tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--ink); }
.stat b { display: block; font-size: 26px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
.tablewrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 12px; background: #fafbfc; border-bottom: 1px solid var(--line); position: sticky; top: 0; }
td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 1px 7px; margin: 1px 2px 1px 0; border-radius: 4px; background: var(--soft); font-size: 12px; }
.tag.off { text-decoration: line-through; color: var(--muted); }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0,0,0,.1); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.list li { margin: 4px 0; }
.problem { padding: 6px 10px; border-radius: 6px; margin: 4px 0; }
.problem.block { background: var(--danger-soft); color: var(--danger); }
.problem.warn { background: var(--warn-soft); color: var(--warn); }

/* Side panel editor */
.scrim { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: var(--panel); z-index: 11; display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(16,24,40,.15); }
.drawer header { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.drawer header h2 { margin: 0; flex: 1; }
.drawer .body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.drawer footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.drawer footer .grow { flex: 1; }
.dialog { position: fixed; top: 12vh; left: 50%; transform: translateX(-50%); width: min(560px, 94vw); max-height: 76vh; overflow-y: auto; background: var(--panel); border-radius: 10px; z-index: 21; padding: 20px; box-shadow: 0 20px 50px rgba(16,24,40,.25); }
.dialog.wide { width: min(760px, 94vw); }
.scrim.top { z-index: 20; }

/* Ordered lists inside editors */
.olist { border: 1px solid var(--line); border-radius: 6px; }
.olist .li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.olist .li:last-child { border-bottom: 0; }
.olist .li .grow { flex: 1; min-width: 0; }
.olist .li .grow small { display: block; color: var(--muted); }
.arrows { display: flex; gap: 2px; }
.arrows .btn { padding: 0 6px; }
.opts td { padding: 4px 6px; }
.opts input[type=text] { width: 100%; }
.opts input.money { width: 84px; text-align: right; }
.picker { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 8px; }
.picker label { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.picker label:hover { background: var(--soft); }
.picker label small { color: var(--muted); margin-left: auto; }

/* Display group layout */
.dg { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.dglist .li { cursor: pointer; }
.dglist .li.on { background: var(--accent-soft); }
.palette { display: flex; gap: 6px; flex-wrap: wrap; }
.palette button { width: 26px; height: 26px; border-radius: 5px; border: 2px solid transparent; cursor: pointer; }
.palette button.on { border-color: var(--ink); }
.pos { background: #1e1f22; border-radius: 10px; padding: 12px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pos .b { min-height: 64px; border-radius: 6px; padding: 8px; color: #fff; font-weight: 600; font-size: 13px; display: flex; flex-direction: column; justify-content: space-between; text-shadow: 0 1px 1px rgba(0,0,0,.35); }
.pos .b small { font-weight: 400; opacity: .9; }
.pos .b.out { opacity: .45; text-decoration: line-through; }

/* Sign-in and toast */
.signin { max-width: 380px; margin: 14vh auto; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1b2230; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 40; box-shadow: var(--shadow); }
.toast.bad { background: var(--danger); }
.keybox { font-family: ui-monospace, Menlo, monospace; background: var(--soft); padding: 8px 10px; border-radius: 6px; word-break: break-all; }
ol.steps li { margin: 6px 0; }
