/* Admin UI colors come only from the variables below. Desktop only. */
:root {
  /* Colors */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f5f7fa;
  --text: #1a2230;
  --text-soft: #3d4757;
  --muted: #6b7686;
  --border: #e2e5e9;
  --border-strong: #cdd3dd;
  --accent: #1f6fc5;
  --accent-hover: #1a5fae;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--surface));
  --accent-text: #ffffff;
  --success: #067647;
  --success-bg: #ecfdf3;
  --error: #b42318;
  --error-bg: #fef3f2;
  --error-border: #fecdca;
  --warning: #93370d;
  --warning-bg: #fffaeb;
  --warning-border: #fedf89;
  --scrim: #0008;
  --focus-ring: color-mix(in srgb, var(--accent) 25%, transparent);

  /* Shape and depth */
  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px #0000000d, 0 2px 10px #0000000a;
  --shadow: 0 1px 2px #0000000d, 0 2px 10px #0000000f;
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.08);

  /* Type */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
code { font: 0.88em var(--mono); background: var(--surface-alt); padding: 1px 5px; border-radius: 4px; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 36px;
  padding: 0 32px;
  height: 58px;
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(8px);
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.topbar .brand::before {
  content: "KJ";
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.topbar .brand:hover { text-decoration: none; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 2px; flex: 1; }
.topbar nav a {
  padding: 5px 13px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.topbar nav a:hover { color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); }
.topbar nav a.active { color: var(--accent); font-weight: 600; background: color-mix(in srgb, var(--accent) 13%, transparent); }
.topbar .logout { color: var(--muted); font-size: 0.9rem; }
.topbar .logout:hover { color: var(--text); text-decoration: none; }

/* Page frame */
main { padding: 28px 32px 64px; }
h1 { margin: 0 0 20px; font-size: 1.625rem; font-weight: 650; letter-spacing: -0.02em; }
h2 { letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); }
.error, .warning, .notice, .problems {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  margin: 0 0 16px;
}
.error { color: var(--error); background: var(--error-bg); border-color: var(--error-border); }
.warning { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.notice { color: var(--success); background: var(--success-bg); border-color: var(--success-bg); }
.problems { color: var(--error); background: var(--error-bg); border-color: var(--error-border); font-size: 0.9rem; }
.problems ul { margin: 4px 0 0; padding-left: 1.2em; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
main > p.muted:not(.empty) { margin: -8px 0 20px; }

/* Buttons */
.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 550;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.button:hover, button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); text-decoration: none; }
.button.secondary, button.secondary { background: var(--surface); color: var(--text-soft); border-color: var(--border-strong); }
.button.secondary:hover, button.secondary:hover { background: var(--surface-alt); border-color: var(--border-strong); color: var(--text); }
button.link-danger, button.link-action {
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  font-weight: 500;
}
button.link-danger { color: var(--error); }
button.link-action { color: var(--accent); }
button.link-danger:hover, button.link-action:hover { background: none; text-decoration: underline; text-underline-offset: 3px; }
button.link-danger:hover { color: var(--error); }
button.link-action:hover { color: var(--accent-hover); }
button:disabled { opacity: 0.45; cursor: default; pointer-events: none; }
button:focus-visible, .button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Inputs */
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.75; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
input[readonly], textarea[readonly] { background: var(--surface-alt); }

/* Filters (pills) */
.filters { display: inline-flex; gap: 2px; margin-bottom: 20px; padding: 3px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 999px; }
.filters a { padding: 4px 16px; border-radius: 999px; color: var(--muted); font-weight: 500; text-decoration: none; transition: color 0.15s, background 0.15s; }
.filters a:hover { color: var(--text); }
.filters a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Tables */
table.list {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
table.list th, table.list td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
table.list th { background: var(--surface-alt); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
table.list tbody tr { transition: background 0.12s; }
table.list tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
table.list tr:last-child td { border-bottom: 0; }
table.list td a { font-weight: 500; }
table.list td.actions { text-align: right; white-space: nowrap; }
table.list td.actions > * + * { margin-left: 12px; }
table.list form { margin: 0; }

/* Status badges */
.status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.5;
  text-transform: capitalize;
}
.status-queued { background: color-mix(in srgb, var(--warning) 14%, transparent); border-color: transparent; color: var(--warning); }
.status-scheduled { background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: transparent; color: var(--accent); }
.status-published { background: color-mix(in srgb, var(--success) 14%, transparent); border-color: transparent; color: var(--success); }

/* Forms on a card */
.item-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.item-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--text); }
.item-form .hint { font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.item-form input, .item-form textarea, .item-form select { font-weight: 400; }
.item-form input[type=date], .item-form select { align-self: flex-start; }
.item-form textarea { font-family: var(--mono); font-size: 0.86rem; line-height: 1.6; }
.item-form .muted.hint { margin: 0; }
.form-actions { display: flex; align-items: center; gap: 12px; }
.form-actions a:not(.button) { color: var(--muted); margin-left: 4px; }
.form-actions a:not(.button):hover { color: var(--text); }
.body-row { display: flex; gap: 28px; align-items: flex-start; }
.body-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.preview-col { display: flex; flex-direction: column; gap: 8px; width: 560px; max-width: 45%; flex: none; }
.preview-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  box-sizing: border-box;
  border: 4px solid var(--text);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
form.inline-delete { margin-top: 24px; }

/* Prompt box */
.prompt-box { margin-top: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; box-shadow: var(--shadow-sm); }
.prompt-box summary { cursor: pointer; font-weight: 600; }
.prompt-box[open] summary { margin-bottom: 8px; }
.prompt-box textarea { width: 100%; margin-top: 12px; font: 0.82rem/1.6 var(--mono); background: var(--surface-alt); }

/* Settings */
form.inline { display: inline; margin: 0 0 0 12px; }
.settings { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.setting {
  display: grid;
  grid-template-columns: 1fr 120px auto;
  gap: 20px;
  align-items: center;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.setting.has-error { border-color: var(--error-border); background: var(--error-bg); }
.setting-text { display: flex; flex-direction: column; gap: 2px; }
.setting-text label { font-weight: 600; }
.setting .hint { font-size: 0.85rem; }
.setting input { text-align: right; }
.setting form.inline { margin: 0; }
.field-error { color: var(--error); font-size: 0.9rem; }

/* Glossary */
form.inline-add { display: flex; align-items: center; gap: 8px; margin: 0; }
form.inline-add input[name=name] { width: 260px; }
.glossary { display: flex; flex-direction: column; gap: 20px; }
.cat-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.cat-bar select { min-width: 360px; }
.cat-bar form { margin: 0; }
.cat-add summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.cat-add[open] { flex: 1; }
.cat-add form { display: flex; gap: 8px; margin-top: 10px; }
.cat-add input { flex: 1; min-width: 0; }
.term-pane { min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.pane-head h2 { margin: 0; font-size: 1.25rem; font-weight: 650; }
.pane-head .actions { display: flex; align-items: center; gap: 16px; }
.pane-head .actions form.inline { margin: 0; }
.pane-tools { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.pane-tools .filters { margin: 0; }
form.search { display: flex; gap: 8px; }
form.search input { width: 260px; }
table.terms td { padding: 8px 16px; }
table.terms .term-use { white-space: nowrap; }
table.terms .term-use .muted { margin-left: 8px; font-size: 0.85rem; }
table.terms form.inline { margin: 0; }
table.terms button { padding: 4px 12px; font-size: 0.85rem; }
.term-pane > .hint { margin-top: 16px; font-size: 0.85rem; }
.descriptions { margin: 0 0 16px; padding: 12px 16px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 14%, transparent); border-radius: var(--radius); }
.descriptions .desc { margin: 4px 0; font-size: 0.9rem; color: var(--text-soft); }
.descriptions .desc strong { color: var(--text); }

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-box {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 360px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.login-box h1 { margin: 0 0 4px; font-size: 1.4rem; text-align: center; }
.login-box h1::before {
  content: "KJ";
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.95rem;
  font-weight: 700;
}
.login-box label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 500; color: var(--text-soft); }
.login-box button { padding: 10px 12px; }
.login-box .error { margin: 0; }

/* Empty states */
p.empty { margin: 0; padding: 40px 16px; text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }

/* Edit popups (static/modal.js) */
dialog.modal {
  width: 34rem;
  max-width: 94vw;
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: var(--scrim); }
dialog.modal .modal-body { padding: 24px 28px; }
dialog.modal h1 { margin: 0 0 16px; font-size: 1.25rem; }
dialog.modal .item-form { padding: 0; border: 0; box-shadow: none; background: none; }
dialog.modal form.inline-delete { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
dialog.modal .item-form select { width: 100%; max-width: 100%; align-self: stretch; }

/* Table corners (no overflow clipping, so headers can stick) and sticky headers */
table.list thead th { position: sticky; top: 58px; z-index: 2; }
table.list thead th:first-child, table.list:not(:has(thead)) tbody tr:first-child td:first-child { border-top-left-radius: calc(var(--radius) - 1px); }
table.list thead th:last-child, table.list:not(:has(thead)) tbody tr:first-child td:last-child { border-top-right-radius: calc(var(--radius) - 1px); }
table.list tbody tr:last-child td:first-child { border-bottom-left-radius: calc(var(--radius) - 1px); }
table.list tbody tr:last-child td:last-child { border-bottom-right-radius: calc(var(--radius) - 1px); }

/* Filter counts */
.filters .count { margin-left: 4px; padding: 0 7px; border-radius: 999px; background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.filters a.active .count { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* Glossary rows: the badge sits next to the name, actions stay right */
table.terms td.term-name { width: 1%; white-space: nowrap; }
table.terms td.term-use { width: 100%; }

/* New-item and new-skin popups are compact: the big fields wait for the full screen */
.modal-only { display: none; }
dialog.modal .modal-only { display: block; margin: -8px 0 16px; }
dialog.modal .body-row, dialog.modal .prompt-box, dialog.modal script, dialog.modal button[formtarget] { display: none; }

/* "Saved" toast */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }

.image-preview { margin-top: 20px; }
.image-preview img { display: block; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 12px; }

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; margin-top: 16px; }
.image-card { margin: 0; }
.image-card figcaption { font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }
.image-card canvas, .image-preview canvas { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.image-card canvas { cursor: zoom-in; }
.image-card canvas:hover { border-color: var(--accent); }
.image-card .card-actions { margin-top: 8px; }
.image-preview { max-width: 640px; }
dialog.lightbox { border: 0; padding: 0; background: transparent; max-width: none; max-height: none; overflow: visible; }
dialog.lightbox::backdrop { background: var(--scrim); }
dialog.lightbox img { display: block; height: 92vh; width: auto; max-width: 94vw; object-fit: contain; border-radius: var(--radius); }
dialog.lightbox .lb-bar { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 8px; color: var(--surface); }
dialog.lightbox .lb-bar button { padding: 4px 14px; }
.paste-box { margin-top: 16px; }
.paste-box summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.image-card .post-text { white-space: pre-wrap; margin: 8px 0 0; color: var(--muted); }
.image-card figcaption { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin: 8px 0 0; }
.image-card .card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.edit-thumb { display: block; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 4px; }
.save-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 8px; }

/* Dividend List */
.dates { font-size: 0.85rem; }
.picker { margin-bottom: 14px; flex-wrap: wrap; }
.inline-label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
table.dividends td { vertical-align: top; }
table.dividends details { margin-top: 6px; max-width: 520px; }
table.dividends details p { margin: 6px 0; }
.signal { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.signal-red { background: color-mix(in srgb, var(--error) 14%, transparent); color: var(--error); }
.signal-warn { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); }
.signal-good { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.verdict { font-weight: 600; text-transform: capitalize; }
.verdict-buy { color: var(--success); }
.verdict-wait { color: var(--warning); }
.verdict-avoid { color: var(--error); }
.video-item { margin-top: 20px; }
.image-preview .post-text { white-space: pre-wrap; font: inherit; margin: 8px 0 0; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
