:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1b2330; --muted: #5d6878; --line: #dfe4ec;
  --accent: #1f5fd1; --accent-ink: #ffffff; --accent-soft: #e6eefc;
  --ok: #18794e; --ok-soft: #e3f4ea; --warn: #9a5b00; --warn-soft: #fff3db; --bad: #b4232c; --bad-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d; --panel: #1b212b; --ink: #e6eaf0; --muted: #9aa5b5; --line: #2c3442;
    --accent: #5b8ef0; --accent-ink: #0d1320; --accent-soft: #1f2d48;
    --ok: #5fd197; --ok-soft: #173326; --warn: #f0b44c; --warn-soft: #3a2d12; --bad: #f37b7b; --bad-soft: #3d1a1c;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.top { display: flex; align-items: center; gap: 22px; padding: 0 20px; height: 54px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-size: 15px; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.top nav a.on { background: var(--accent-soft); color: var(--accent); }
.who { color: var(--muted); white-space: nowrap; }
main { padding: 20px; max-width: 1500px; margin: 0 auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { padding: 12px 18px; font-size: 15px; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
input[type=text], input[type=password], input[type=email], input[type=search], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 120px; }
label.f { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 16px; }
.muted { color: var(--muted); }
.show-sm { display: none; }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
input[type=color] { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 3px; cursor: pointer; }
.brandband { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 84px; padding: 0 18px; border-radius: 10px 10px 0 0; margin-top: 10px; }
.brandband img { max-height: 64px; max-width: 45%; }
.brandband b { color: #f2f5fa; letter-spacing: .04em; font-size: 15px; white-space: nowrap; }
.brandstripe { height: 4px; border-radius: 0 0 4px 4px; }

/* login */
.login { max-width: 360px; margin: 10vh auto; }
.login .card { padding: 26px; }
.login h1 { margin-bottom: 16px; display: flex; gap: 10px; align-items: center; }
.login .field { margin-bottom: 12px; }
.err { color: var(--bad); min-height: 20px; margin: 6px 0; }

/* board */
.boardhead { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }
.tabs .n { font-size: 11px; background: var(--line); color: var(--ink); border-radius: 9px; padding: 0 6px; margin-left: 4px; }
.search { max-width: 280px; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--bg); }
.list td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--accent-soft); }
.list .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-new { background: var(--accent-soft); color: var(--accent); }
.b-signed { background: var(--ok-soft); color: var(--ok); }
.b-disputed { background: var(--warn-soft); color: var(--warn); }
.b-archived, .b-sending { background: var(--line); color: var(--muted); }
.mailstate { font-size: 12px; color: var(--muted); }
.mailstate.bad { color: var(--bad); }

/* detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 18px; align-items: start; }
.viewer { background: #525659; border-radius: 12px; padding: 14px; min-height: 70vh; max-height: calc(100vh - 110px); overflow: auto; position: relative; }
.viewer .bar { position: sticky; top: -14px; margin: -14px -14px 12px; padding: 8px 14px; background: rgba(40,42,46,.92); color: #fff; display: flex; gap: 10px; align-items: center; z-index: 2; font-size: 13px; }
.viewer .bar .btn { padding: 4px 10px; background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.viewer .bar .btn.on { background: #f0b44c; color: #222; border-color: #f0b44c; }
.pg { position: relative; margin: 0 auto 14px; box-shadow: 0 2px 10px rgba(0,0,0,.4); background: #fff; width: fit-content; }
.pg canvas { display: block; }
.pg.placing { cursor: crosshair; }
.spot { position: absolute; border: 2px dashed #e8890c; background: rgba(240,180,76,.18); border-radius: 4px; pointer-events: none; }
.spot span { position: absolute; top: -20px; left: -2px; background: #e8890c; color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 74px; max-height: calc(100vh - 94px); overflow: auto; padding-bottom: 6px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; word-break: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--ink); border-radius: 14px; padding: 3px 4px 3px 10px; font-size: 13px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 5px; border-radius: 10px; }
.chip button:hover { background: var(--bad-soft); color: var(--bad); }
.chip.sugg { background: none; border: 1px dashed var(--line); padding-right: 10px; cursor: pointer; color: var(--muted); }
.addrin { flex: 1; min-width: 160px; border: 0 !important; padding: 4px 2px !important; outline: none !important; background: transparent !important; }
.recips { border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.note { border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.info { background: var(--accent-soft); color: var(--accent); }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions .row .btn { flex: 1; }
.history { font-size: 12px; color: var(--muted); margin: 0; padding-left: 16px; }
.history li { margin-bottom: 3px; }
details summary { cursor: pointer; color: var(--accent); font-size: 13px; }
pre.mail { white-space: pre-wrap; font: 12px/1.45 ui-monospace, Consolas, monospace; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; }

/* profile / admin */
.narrow { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.sigpad { border: 1px dashed var(--muted); border-radius: 10px; background: #fff; touch-action: none; width: 100%; height: 170px; display: block; cursor: crosshair; }
.sigshow { max-width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 90px; }
.users td, .users th { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.users { width: 100%; border-collapse: collapse; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.bad { background: var(--bad); color: #fff; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal .card { width: min(560px, 100%); max-height: 90vh; overflow: auto; }

@media (max-width: 980px) {
  .detail { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; order: -1; }
  .viewer { max-height: 80vh; min-height: 50vh; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .top { gap: 10px; padding: 0 12px; }
  .top nav a { padding: 6px 8px; }
  .who span { display: none; }
  .brand { font-size: 0; }
  .list .hide-sm { display: none; }
  .show-sm { display: inline; }
  .tabs { overflow-x: auto; max-width: 100%; }
  .top nav a { white-space: nowrap; font-size: 13px; }
  .who .link { white-space: nowrap; font-size: 13px; }
  .list td, .list th { padding: 9px 8px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

/* sent rate cons (suite) */
.narrow.wide { max-width: 1040px; }
.grid3b { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
.stopcard { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 12px; margin-top: 10px; background: var(--bg); }
.stopcard.delivery { border-left-color: var(--ok); }
.stickybar { position: sticky; bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; z-index: 5; }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.link.danger { color: var(--bad); }
.link:disabled { color: var(--muted); cursor: default; }
details > summary { margin-top: 2px; }
@media (max-width: 640px) {
  .grid3b { grid-template-columns: 1fr 1fr 1fr; }
  .stickybar { bottom: 8px; }
  .stickybar .grow { flex-basis: 100%; }
}
