:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1d2430;
  --muted: #6b7684;
  --line: #dfe4ea;
  --accent: #2f7d75;
  --accent-ink: #ffffff;
  --danger: #b4443a;
  --ok: #2d7a4f;
  --warn: #9a6b1f;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --panel: #1b2027;
    --ink: #e6eaef;
    --muted: #8d97a3;
    --line: #2b323b;
    --accent: #4fa89e;
    --accent-ink: #0d1114;
    --danger: #d9776c;
    --ok: #63b487;
    --warn: #d0a353;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* An explicit `display` in a rule below beats the browser's built-in
   [hidden] { display: none }, so anything toggled with el.hidden needs this to
   actually disappear. Learned the hard way from a login overlay that would not
   go away. */
[hidden] { display: none !important; }

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

h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
code { font-family: var(--mono); font-size: .92em; background: var(--bg); padding: 1px 4px; border-radius: 3px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- gate */
.gate { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.gate-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 32px; width: 100%; max-width: 380px;
}
.gate-card input { width: 100%; margin: 14px 0 12px; }
.gate-card button { width: 100%; }
.error { color: var(--danger); min-height: 18px; margin: 10px 0 0; font-size: 13px; }

/* -------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px; height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 15px; white-space: nowrap; }
.tabs { display: flex; gap: 2px; flex: 1; }
.tabs button {
  background: none; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.tabs button:hover { background: var(--bg); color: var(--ink); }
.tabs button.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: currentColor; }
.pill.bad { color: var(--danger); border-color: currentColor; }

/* ------------------------------------------------------------- buttons */
button, .upload-btn {
  font: inherit; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid transparent; border-radius: 6px; padding: 8px 16px;
}
button:hover, .upload-btn:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; filter: none; }
button.ghost {
  background: var(--panel); color: var(--ink); border-color: var(--line);
}
button.ghost:hover { background: var(--bg); filter: none; }
button.small { padding: 4px 10px; font-size: 12px; }
button.danger { color: var(--danger); }
.upload-btn { padding: 4px 12px; font-size: 12px; border-radius: 6px; }

/* -------------------------------------------------------------- layout */
.tab-panel { display: grid; grid-template-columns: 240px 1fr; height: calc(100vh - 52px); }
.tab-panel.single { grid-template-columns: 1fr; }
.tab-panel[hidden] { display: none; }

.list-pane { border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; }
.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  font-weight: 600; position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.list { list-style: none; margin: 0; padding: 6px; }
.list li {
  padding: 9px 10px; border-radius: 6px; cursor: pointer; margin-bottom: 2px;
}
.list li:hover { background: var(--bg); }
.list li.active { background: var(--bg); box-shadow: inset 2px 0 0 var(--accent); }
.list .id { font-family: var(--mono); font-size: 11px; color: var(--muted); display: block; }
.list .off { opacity: .5; }

.pane { padding: 18px 22px; overflow-y: auto; }
.pane .list-head { border: none; padding: 0 0 14px; position: static; background: none; }

.empty { display: grid; place-content: center; text-align: center; padding: 40px; gap: 6px; }
.empty[hidden] { display: none; }

/* -------------------------------------------------------------- editor */
.editor { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(380px, 1fr); overflow: hidden; }
.editor[hidden] { display: none; }
.editor-form { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
label.grow { display: flex; flex-direction: column; flex: 1; min-height: 260px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row.checks { grid-template-columns: auto auto; justify-content: start; gap: 22px; align-items: center; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }

input[type=text], input[type=password], input:not([type]), select, textarea {
  width: 100%; margin-top: 4px;
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
input[type=color] { width: 100%; height: 30px; padding: 2px; margin-top: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
textarea { font-family: var(--mono); font-size: 13px; line-height: 1.55; resize: vertical; }
#t-html { flex: 1; min-height: 240px; resize: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

label.check { display: flex; align-items: center; gap: 7px; font-weight: 500; color: var(--ink); font-size: 13px; }
label.check input { width: auto; margin: 0; }
.hint {
  display: inline-grid; place-items: center; width: 15px; height: 15px;
  border-radius: 50%; background: var(--line); color: var(--muted);
  font-size: 10px; cursor: help;
}

.editor-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.editor-actions { display: flex; gap: 8px; align-items: center; padding-top: 4px; }
.status { font-size: 12px; color: var(--muted); margin-left: auto; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--danger); }

details summary { cursor: pointer; font-size: 12px; color: var(--muted); font-weight: 600; }
details textarea { margin-top: 8px; }

fieldset.theme { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
fieldset.theme legend { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 6px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 10px; }
.swatches label { font-size: 11px; text-align: center; }

/* ------------------------------------------------------------- preview */
.preview-pane { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--panel); overflow: hidden; }
.preview-head {
  display: flex; gap: 10px; align-items: baseline; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.preview-head .muted { font-weight: 400; font-size: 12px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.params {
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px;
  max-height: 180px; overflow-y: auto;
}
.params p { grid-column: 1 / -1; margin: 0; }
.params label { font-family: var(--mono); font-size: 11px; }
#preview-frame, #brand-preview { flex: 1; width: 100%; border: none; background: #fff; }

/* -------------------------------------------------------------- assets */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 26px; text-align: center; color: var(--muted); margin-bottom: 18px;
}
.dropzone.over { border-color: var(--accent); color: var(--accent); }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.asset {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; display: flex; flex-direction: column; gap: 6px;
}
.asset .thumb {
  height: 90px; display: grid; place-items: center; overflow: hidden;
  background: var(--bg); border-radius: 4px; font-size: 26px;
}
.asset .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset .name { font-size: 12px; word-break: break-all; }
.asset .meta { font-size: 11px; color: var(--muted); }
.asset .actions { display: flex; gap: 6px; }
.asset .actions button { flex: 1; }
.asset.selectable { cursor: pointer; }
.asset.selectable:hover { border-color: var(--accent); }

/* ----------------------------------------------------------------- log */
.stats { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; }
table.log th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line);
}
table.log td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.log tr:hover td { background: var(--panel); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; }
.tag.sent { color: var(--ok); }
.tag.failed { color: var(--danger); }
.tag.queued { color: var(--warn); }
.tag.sending { color: var(--muted); }
.err { color: var(--danger); font-size: 11px; display: block; margin-top: 3px; word-break: break-word; }
.mono { font-family: var(--mono); font-size: 11px; }

/* --------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border-radius: var(--radius); padding: 22px;
  width: 100%; max-width: 620px; max-height: 80vh; overflow-y: auto;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-card .asset-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.secret {
  font-family: var(--mono); font-size: 13px; word-break: break-all;
  background: var(--bg); padding: 12px; border-radius: 6px; margin: 10px 0;
}

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 20px;
  border-radius: 999px; font-size: 13px; z-index: 60;
}
.toast[hidden] { display: none; }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .preview-pane { display: none; }
  .tab-panel { grid-template-columns: 180px 1fr; }
}
