:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232c;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #9aa7b4;
  --dim: #6e7d8d;
  --accent: #34d399;
  --accent-dim: rgba(52, 211, 153, .12);
  --danger: #f87171;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
h3 { font-size: 13px; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ── chrome ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); }
.brand span { color: var(--accent); }
.topnav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topnav a {
  padding: 6px 10px; border-radius: var(--radius); color: var(--muted); font-size: 13px;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topnav a.active { background: var(--accent-dim); color: var(--accent); }
.topright { display: flex; align-items: center; gap: 12px; }
.who { color: var(--dim); font-size: 12px; }

.wrap { padding: 24px; max-width: 1400px; margin: 0 auto; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.pagehead .actions { display: flex; gap: 10px; align-items: center; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.flash.ok { background: var(--accent-dim); color: var(--accent); }
.flash.err { background: rgba(248, 113, 113, .12); color: var(--danger); }

/* ── controls ───────────────────────────────────────────────────────────── */
button, .btn {
  background: var(--accent); color: #06281c; border: 0; border-radius: var(--radius);
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 6px 10px; border-radius: var(--radius); font-size: 12px; font-weight: 500;
  display: inline-block; cursor: pointer;
}
.ghost:hover { color: var(--text); border-color: var(--dim); text-decoration: none; }
.ghost.danger:hover { color: var(--danger); border-color: var(--danger); }
.inline { display: inline; }

input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.6; }
label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
label input, label select, label textarea { margin-top: 5px; color: var(--text); }
label.check { display: inline-flex; align-items: center; gap: 6px; width: auto; margin: 0; }
label.check input { width: auto; margin: 0; }
.hint { color: var(--dim); font-size: 11px; font-weight: 400; }

/* the provider on/off switch: one click, and it reads as a switch even in the
   middle of a dense table */
.switch {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--dim);
  padding: 3px 10px 3px 4px; border-radius: 999px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
}
.switch .knob {
  width: 26px; height: 14px; border-radius: 999px; background: var(--line);
  position: relative; transition: background .15s;
}
.switch .knob::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--dim); transition: transform .15s, background .15s;
}
.switch.on { background: var(--accent-dim); border-color: rgba(52, 211, 153, .35); color: var(--accent); }
.switch.on .knob { background: rgba(52, 211, 153, .35); }
.switch.on .knob::after { transform: translateX(12px); background: var(--accent); }
.switch:hover { filter: none; border-color: var(--dim); }

/* one-row-per-field editors that sit under a list (providers) */
.editor-inline { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-start; }
.editor-inline label { width: 190px; margin: 0; }
.editor-inline label.narrow { width: 90px; }
.editor-inline label.wide { width: 100%; max-width: 620px; }
.editor-inline input[readonly] { color: var(--muted); background: var(--bg); cursor: not-allowed; }
.editor-inline-actions { display: flex; align-items: center; gap: 14px; width: 100%; }
tr.editing > td { background: var(--accent-dim); }
/* the CMS row and the exchange disagreeing is worth seeing before the
   calculator tells you */
.drift { color: var(--danger); font-size: 11px; margin-top: 4px; }

/* a partner's api key: readable — the exchange stores it in plain text — but
   not sitting uncovered on a screen that is being shared */
.keycell { white-space: nowrap; }
.keycell .key {
  display: inline-block; max-width: 24ch; overflow: hidden; text-overflow: ellipsis;
  vertical-align: middle; background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 8px; margin-right: 6px;
  filter: blur(4px); user-select: none;
}
.keycell .key.shown { filter: none; user-select: all; max-width: none; }

.filters, .rowform { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input, .filters select, .rowform input, .rowform select { width: auto; min-width: 150px; }
.stack label { max-width: 560px; }

/* ── tables ─────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--dim); font-weight: 500; font-size: 11px;
     text-transform: uppercase; letter-spacing: .06em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: var(--surface); }
td.right { text-align: right; white-space: nowrap; }
.dim { color: var(--dim); }
.err-text { color: var(--danger); }
table.wide { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
table.kv th { width: 140px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
        background: var(--surface-2); color: var(--muted); }
.pill.s-published, .pill.s-finished, .pill.s-completed { background: var(--accent-dim); color: var(--accent); }
.pill.s-draft, .pill.s-waiting, .pill.s-new { background: rgba(250, 204, 21, .12); color: #facc15; }
.pill.s-failed, .pill.s-expired, .pill.s-error { background: rgba(248, 113, 113, .12); color: var(--danger); }

/* Exchange and Pay statuses arrive uppercase from the API (DONE, WAIT_DEPOSIT,
   OPEN…). The set above only matched the CMS's own lowercase ones, so every
   order and payment pill rendered the same neutral grey. */
.pill.s-DONE, .pill.s-PAID { background: var(--accent-dim); color: var(--accent); }
.pill.s-NEW, .pill.s-OPEN, .pill.s-WAIT_DEPOSIT, .pill.s-CONFIRMING,
.pill.s-EXCHANGING, .pill.s-SENDING { background: rgba(250, 204, 21, .12); color: #facc15; }
.pill.s-FAILED, .pill.s-TIME_EXPIRED, .pill.s-EXPIRED, .pill.s-CANCELED,
.pill.s-REFUNDED { background: rgba(248, 113, 113, .12); color: var(--danger); }

/* Partner lifecycle. A self-registered partner is holding a key that does not
   work and has been told to write to support, so "pending" has to read as
   something waiting for an answer rather than as another grey label. */
.pill.s-pending  { background: rgba(250, 204, 21, .12); color: #facc15; }
.pill.s-rejected { background: rgba(248, 113, 113, .12); color: var(--danger); }
.pill.s-active   { background: var(--accent-dim); color: var(--accent); }
.pending-partners { box-shadow: inset 3px 0 0 #facc15; }

/* ── Pay ────────────────────────────────────────────────────────────────── */
.flash.warn, .warn-text { color: #facc15; }
.flash.warn { background: rgba(250, 204, 21, .12); }
.flash { background: var(--surface-2); color: var(--muted); }
.warn-text { font-size: 12px; }
h2.section-h { margin: 26px 0 12px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between;
              gap: 12px; margin-bottom: 12px; }
.panel-head h3 { margin: 0; text-transform: none; letter-spacing: 0;
                 font-size: 15px; color: var(--text); }
.panel-head h3 .pill { margin-left: 8px; vertical-align: middle; }
table.kv th.kv-head { width: auto; color: var(--muted); text-transform: uppercase;
                      font-size: 11px; letter-spacing: .06em; }
.filters label.check { display: flex; align-items: center; gap: 6px; color: var(--muted);
                       font-size: 13px; }
.filters label.check input { width: auto; min-width: 0; }
details.raw { margin-top: 14px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.raw pre { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
                  padding: 12px; overflow-x: auto; font-size: 12px;
                  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── panels & cards ─────────────────────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
         padding: 18px; margin-bottom: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 16px; display: flex; flex-direction: column; gap: 4px; color: var(--text); }
.card:hover { border-color: var(--accent); text-decoration: none; }
.card .n { font-size: 26px; font-weight: 700; }
.card .l { color: var(--dim); font-size: 12px; }

/* ── editor ─────────────────────────────────────────────────────────────── */
.editor { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.editor-main, .editor-side .box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
}
.editor-side .box { margin-bottom: 16px; }
.editor-side .btn { width: 100%; margin-bottom: 14px; }

/* the body editor: three views of one field, so they share its footprint */
.field { margin-bottom: 12px; }
.field-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.rte { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); overflow: hidden; }
.rte-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 6px 8px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.rte-tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.rte-tools.dim { color: var(--dim); font-size: 12px; padding-left: 4px; }
.rte-tools button {
  background: transparent; color: var(--muted); border: 0; border-radius: 6px;
  padding: 4px 8px; font-size: 12px; min-width: 28px; font-weight: 500;
}
.rte-tools button:hover { background: var(--surface); color: var(--text); filter: none; }
.rte-sep { width: 1px; height: 16px; background: var(--line); margin: 0 5px; }
.rte-modes { display: flex; gap: 2px; }
.rte-modes button {
  background: transparent; color: var(--dim); border: 0; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; font-weight: 500;
}
.rte-modes button:hover { color: var(--text); filter: none; }
.rte-modes button.on { background: var(--accent-dim); color: var(--accent); }

.rte-rich, .rte-source, .rte-frame { display: none; width: 100%; }
.rte[data-mode="rich"] .rte-rich { display: block; }
.rte[data-mode="html"] .rte-source { display: block; }
.rte[data-mode="preview"] .rte-frame { display: block; }

.rte-rich {
  min-height: 420px; max-height: 70vh; overflow-y: auto; padding: 18px 20px;
  color: var(--text); font-size: 15px; line-height: 1.7;
}
.rte-rich:focus { outline: 0; }
.rte-rich > :first-child { margin-top: 0; }
.rte-rich h2 { font-size: 20px; color: var(--text); text-transform: none; letter-spacing: 0; margin: 24px 0 8px; }
.rte-rich h3 { font-size: 16px; color: var(--text); text-transform: none; letter-spacing: 0; margin: 20px 0 6px; }
.rte-rich blockquote { margin: 16px 0; padding-left: 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.rte-rich code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.rte-rich img { max-width: 100%; height: auto; border-radius: var(--radius); }
.rte-rich a { color: var(--accent); }
.rte-rich hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.rte-source { border: 0; border-radius: 0; min-height: 420px; }
.rte-source:focus { outline: 0; }
.rte-frame { min-height: 560px; height: 70vh; border: 0; background: #fff; }

/* image picker */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; width: min(860px, 100%); max-height: 84vh; display: flex; flex-direction: column;
}
.modal-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px;
  overflow-y: auto; margin: 4px 0 14px; color: var(--dim); font-size: 13px;
}
.modal-cell {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px; height: 110px; display: grid; place-items: center; overflow: hidden;
}
.modal-cell:hover { border-color: var(--accent); filter: none; }
.modal-cell img { max-width: 100%; max-height: 96px; object-fit: contain; }
.modal-file { color: var(--muted); font-size: 11px; word-break: break-all; }
.modal-foot { display: flex; justify-content: space-between; gap: 10px; }

.flash.restore { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.flash.restore button { padding: 4px 10px; font-size: 12px; }
.thumb { width: 100%; border-radius: var(--radius); margin-bottom: 12px; }

/* ── media ──────────────────────────────────────────────────────────────── */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.media-item { margin: 0; background: var(--surface); border: 1px solid var(--line);
              border-radius: var(--radius); overflow: hidden; }
.media-item img { width: 100%; height: 120px; object-fit: cover; display: block; background: var(--bg); }
.media-item figcaption { padding: 8px; font-size: 11px; display: flex; flex-direction: column; gap: 4px; }
img.logo { height: 16px; vertical-align: middle; }

/* providers the exchange quotes that have no row here — and so no logo */
.unlisted { font-size: 12px; color: var(--muted); margin: 10px 2px 0; line-height: 1.6; }
.unlisted code { font-size: 12px; }

/* provider logo field: preview, the path, the file picker, one row */
.logo-field { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.logo-field input[name="logo"] { width: 190px; }
.logo-field input[type="file"] { flex: 1; min-width: 200px; }
img.logo-preview { width: 24px; height: 24px; object-fit: contain; border-radius: 4px;
                   background: var(--bg); border: 1px solid var(--line); padding: 2px; }

/* ── chat thread ────────────────────────────────────────────────────────── */
.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); max-width: 70%; }
.msg.operator { align-self: flex-end; background: var(--accent-dim); }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 4px; }

.pager { display: flex; gap: 14px; align-items: center; justify-content: center;
         margin: 20px 0; color: var(--dim); font-size: 13px; }

/* ── login ──────────────────────────────────────────────────────────────── */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
              padding: 28px; width: 340px; }
.login-card h1 { margin-bottom: 20px; }
.login-card h1 span { color: var(--accent); }
.login-card button { width: 100%; margin-top: 6px; }

@media (max-width: 1000px) {
  .editor, .grid2 { grid-template-columns: 1fr; }
}

/* ── two-factor ─────────────────────────────────────────────────────────── */
.setup-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; width: min(440px, 92vw); margin: 40px auto; text-align: center;
}
.setup-card h1 { margin-bottom: 16px; }
.setup-card h1 span { color: var(--accent); }
.setup-card form { text-align: left; }
.setup-card button[type="submit"] { width: 100%; margin-top: 6px; }
.qr { border-radius: var(--radius); margin: 14px auto; display: block; background: #fff; padding: 8px; }
.secret { display: inline-block; background: var(--bg); border: 1px solid var(--line);
          border-radius: var(--radius); padding: 8px 12px; letter-spacing: .08em; word-break: break-all; }
.codes { list-style: none; padding: 0; margin: 14px 0; display: grid;
         grid-template-columns: 1fr 1fr; gap: 8px; }
.codes code { display: block; background: var(--bg); border: 1px solid var(--line);
              border-radius: var(--radius); padding: 8px; letter-spacing: .06em; }
.recovery { text-align: left; }
.login-secondary { margin-top: 16px; text-align: center; }
.login-secondary button { width: auto; }

/* ── the menu editor ─────────────────────────────────────────────────────── */
/* Each row is its own form so one link saves without touching the others. A
   form cannot sit between <tr> and <td>, so it wraps the cells and is laid out
   as the table row it replaces. */
.row-form { display: contents; }
.row-form input[type="text"],
.row-form input:not([type]) { width: 100%; }
.topnav a.on, .actions a.on { color: var(--accent); }
