/* Admin interface. No framework: a handful of variables and a grid. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --border: #e2e2dd;
  --text: #1a1a18;
  --muted: #6b6b64;
  --accent: #1a1a18;
  --accent-text: #ffffff;
  --ok-bg: #e8f3ec;
  --ok-text: #1d5434;
  --err-bg: #fbeae9;
  --err-text: #8a231d;
  --warn-bg: #fdf3e2;
  --warn-text: #7a5312;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131314;
    --surface: #1c1c1e;
    --border: #2f2f32;
    --text: #ececea;
    --muted: #9a9a94;
    --accent: #ececea;
    --accent-text: #131314;
    --ok-bg: #16281d;
    --ok-text: #86d1a3;
    --err-bg: #2c1817;
    --err-text: #ef9d97;
    --warn-bg: #2b2213;
    --warn-text: #e8bf72;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 14px; letter-spacing: -0.005em; }

a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.back { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.back:hover { color: var(--text); }

/* --- top bar ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background:
    linear-gradient(var(--accent) 0 0) 0 0 / 7px 7px no-repeat,
    linear-gradient(var(--accent) 0 0) 100% 0 / 7px 7px no-repeat,
    linear-gradient(var(--accent) 0 0) 0 100% / 7px 7px no-repeat,
    linear-gradient(var(--accent) 0 0) 100% 100% / 3px 3px no-repeat;
}
.topbar nav { display: flex; align-items: center; gap: 16px; font-size: 0.92rem; }
.topbar nav a { text-decoration: none; color: var(--muted); }
.topbar nav a:hover { color: var(--text); }

/* --- panels -------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.public-card {
  max-width: 420px;
  margin: 14vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow);
}
.public-card h1 { margin-bottom: 10px; }

/* --- forms --------------------------------------------------------------- */

label { display: block; font-size: 0.85rem; font-weight: 500; margin: 12px 0 5px; }
fieldset legend + label { margin-top: 0; }

input[type="text"], input[type="url"], input[type="password"], select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}
input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}
input[type="color"]:disabled { opacity: 0.35; cursor: not-allowed; }
input[type="range"] { width: 100%; accent-color: var(--text); }
input[type="file"] { width: 100%; font-size: 0.85rem; color: var(--muted); }

fieldset {
  border: 0;
  border-top: 1px solid var(--border);
  padding: 4px 0 14px;
  margin: 0 0 6px;
}
fieldset:first-of-type { border-top: 0; }
legend { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); padding: 10px 0 2px; }

.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-top: 12px; }
.checkbox input { width: auto; accent-color: var(--text); }

.stack > label:first-child { margin-top: 0; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; }

.grid-form {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr 0.7fr auto;
  gap: 12px;
  align-items: end;
}
.grid-form label { margin-top: 0; }
.grid-form-action { display: flex; }
@media (max-width: 760px) {
  .grid-form { grid-template-columns: 1fr; }
}

.row { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.row.wrap { flex-wrap: wrap; }
.inline { display: inline; }

/* --- buttons ------------------------------------------------------------- */

button, .button {
  display: inline-block;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.primary:hover { opacity: 0.88; }
.link-button { border: 0; background: none; color: var(--muted); padding: 0; font-size: 0.92rem; }
.link-button:hover { color: var(--text); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- tables -------------------------------------------------------------- */

.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
}
th.numeric { text-align: right; }
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.row-inactive td { opacity: 0.5; }
.destination { max-width: 280px; word-break: break-all; }
.actions { white-space: nowrap; }
.actions > * { margin-right: 4px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 500; }
.badge-on { background: var(--ok-bg); color: var(--ok-text); }
.badge-off { background: var(--err-bg); color: var(--err-text); }

/* --- messages ------------------------------------------------------------ */

.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 16px; font-size: 0.9rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }

.warnings:empty { display: none; }
.warning {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: 0.86rem;
}
.warning-error { background: var(--err-bg); color: var(--err-text); }
.warning-warning { background: var(--warn-bg); color: var(--warn-text); }

/* --- studio ------------------------------------------------------------- */

.studio {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}
@media (max-width: 880px) {
  .studio { grid-template-columns: 1fr; }
}
.studio > .panel { margin-bottom: 0; }

.preview {
  /* Chequerboard: the only way to see that a transparent background really is. */
  background-image:
    linear-gradient(45deg, var(--border) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  justify-content: center;
}
.preview svg { width: 100%; max-width: 360px; height: auto; display: block; }
.preview.is-loading { opacity: 0.45; transition: opacity 120ms; }

.meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 16px 0 0;
  font-size: 0.83rem;
}
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; }

.logo-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

/* --- style gallery -------------------------------------------------------- */

.presets { padding-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.86rem;
}
.chip.is-active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* --- sub-fields and pairs ------------------------------------------------- */

.sub-fields {
  margin-top: 10px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
}
.sub-fields[hidden] { display: none; }
.sub-fields > label:first-child { margin-top: 0; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair label { margin-top: 12px; }

/* A setting with no effect on the current shape: visible, but stepped back. */
.is-inert { opacity: 0.4; }

/* --- lifecycle, notes, destructive actions ------------------------------- */

textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}
textarea:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.notes-preview { font-style: italic; }

.badge-draft       { background: var(--warn-bg); color: var(--warn-text); }
.badge-circulating { background: var(--ok-bg);   color: var(--ok-text); }
.badge-retired     { background: var(--bg);      color: var(--muted); border: 1px solid var(--border); }

.danger { color: var(--err-text); border-color: var(--err-bg); }
.danger:hover { border-color: var(--err-text); }

/* A panel whose action is unavailable: present, explained, but inert. */
.panel-locked { opacity: 0.75; }

.grid-form-wide { grid-column: 1 / -1; }

/* A field and its button side by side: apply a template, name a new one. */
.pair-tight { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
