/* One small stylesheet, no build step, no framework. It follows the operating
   system's light/dark preference rather than shipping a theme toggle. */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1b1f24;
  --muted: #6a737d;
  --accent: #2b6cb0;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok-bg: #e7f5ec;
  --ok-text: #1a7f37;
  --err-bg: #fdeceb;
  --err-text: #b42318;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --border: #2c3238;
    --text: #e6e8ea;
    --muted: #9aa4ae;
    --accent: #6aa9e9;
    --accent-text: #0d1117;
    --danger: #f2726a;
    --ok-bg: #14301f;
    --ok-text: #7ee2a8;
    --err-bg: #35191a;
    --err-text: #f2a29c;
  }
}

* { box-sizing: border-box; }

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

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}

.brand span { color: var(--muted); font-weight: 400; }

/* The top navigation sits between the brand and the sign-out form, and the
   margin-right pushes that form to the far edge where it was before. */
.topnav {
  display: flex;
  gap: 1rem;
  margin-right: auto;
}

.topnav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.topnav a:hover { color: var(--text); text-decoration: underline; }

/* What a horizon claims, beside its name on a checkbox. It is secondary to the
   name, so it is smaller and quieter, and it wraps rather than widening the
   column. */
.claims {
  color: var(--muted);
  font-size: 0.78rem;
  margin-left: 0.3rem;
}

/* A run of chips on one line, for a list that is read rather than scanned --
   the values a geo database assigns that name no country. */
.values-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.5rem 0;
}

/* Which kind of thing a horizon routes on. Two quiet colours, because the point
   is to tell the two apart at a glance, not to draw the eye. */
.chip.kind-network { background: var(--surface-2, #eef2f7); color: var(--muted); }
.chip.kind-geo { background: #e8f0fe; color: #1a4fa0; }

/* The "route on" choice, which decides what the rest of the form asks for. */
.kind-choice {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin: 0;
}

.kind-choice legend {
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0 0.3rem;
}

.kind-choice .check { display: flex; gap: 0.5rem; align-items: baseline; margin: 0.3rem 0; }

/* --- the country picker (static/countries.js) ------------------------------
   The <select multiple> stays in the DOM and is what the form submits; this is
   only what an operator looks at instead. Hidden this way rather than with
   display:none, so assistive technology and the form both still see it. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.picker {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  background: var(--surface);
}

.picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-height: 1.6rem;
  margin-bottom: 0.45rem;
}

.picker-search { width: 100%; }

/* Fixed height with its own scrollbar: 251 countries must never push the rest
   of the form off the page. */
.picker-options {
  max-height: 15rem;
  overflow-y: auto;
  margin-top: 0.45rem;
  border-top: 1px solid var(--border);
}

.picker-option {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 4px;
  padding: 0.3rem 0.45rem;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}

.picker-option:hover { background: var(--surface-2, #eef2f7); }
.picker-option:focus-visible { outline: 2px solid var(--accent, #1a4fa0); outline-offset: -2px; }

.picker-option.is-selected { background: #e8f0fe; color: #1a4fa0; font-weight: 600; }
.picker-option.is-selected::after { content: " ✓"; }

/* A chosen country, which is also the button that removes it. */
.chip-remove {
  border: 0;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.chip-remove::after { content: " ×"; opacity: 0.6; }
.chip-remove:hover::after { opacity: 1; }

.picker-empty { margin: 0.45rem 0 0; }

/* --- headings and layout --------------------------------------------------- */

h1 { font-size: 1.4rem; margin: 0.2rem 0; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.crumb { margin: 0; font-size: 0.85rem; color: var(--muted); }
.crumb a { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1.25rem;
}

.card.narrow { max-width: 26rem; margin: 3rem auto; }
.card.empty { text-align: center; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0 1rem;
}

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0.9rem; }

/* --- banners --------------------------------------------------------------- */

.banner {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  margin: 0 0 1rem;
}

.banner.ok { background: var(--ok-bg); color: var(--ok-text); }
.banner.err { background: var(--err-bg); color: var(--err-text); }

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

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.content { word-break: break-word; max-width: 28rem; }
tr.disabled td { opacity: 0.55; }

.tag {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 0.45rem;
  color: var(--muted);
  white-space: nowrap;
}

.tag.type { font-weight: 600; color: var(--text); }

.row-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  white-space: nowrap;
}

/* --- record sets ------------------------------------------------------------
   A row is one RRset: the name and type identify it, the badge says how it is
   answered, and the values are stacked so a set of several reads as one thing. */

.rrsets td.name { font-weight: 500; word-break: break-all; }
.rrsets td { vertical-align: middle; }
.zones td.name a { text-decoration: none; font-weight: 500; }
.zones td.name a:hover { text-decoration: underline; }

.values {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.values li {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-wrap: wrap;
  word-break: break-all;
}

.values li.off { opacity: 0.5; text-decoration: line-through; }

.chip {
  font-size: 0.72rem;
  border-radius: 4px;
  padding: 0 0.35rem;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--muted);
  white-space: nowrap;
}

.chip.warn { background: var(--err-bg); color: var(--err-text); }

/* A horizon chip says the value is not served to everybody, so it has to read
   as a restriction rather than as one more attribute of the value. */
.chip.horizon {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--text);
  font-weight: 600;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}

.badge.lb {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}

.badge.lb.rotate {
  background: color-mix(in srgb, var(--ok-text) 14%, transparent);
  color: var(--ok-text);
  border-color: color-mix(in srgb, var(--ok-text) 35%, transparent);
}

.meta { display: flex; flex-wrap: wrap; gap: 0.15rem 0.9rem; font-size: 0.85rem; margin: 0.25rem 0 0; }

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

label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  margin: 0.5rem 0;
}

/* The horizon boxes sit inside one cell of the value table, one per horizon, so
   they stack rather than taking a row each. */
label.check.inline {
  display: flex;
  gap: 0.3rem;
  margin: 0.1rem 0;
  font-size: 0.8rem;
  white-space: nowrap;
}

td.horizons { min-width: 9rem; }

input[type="text"], input[type="password"], input:not([type]), textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  margin-bottom: 0.4rem;
}

textarea { resize: vertical; }

input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  margin: 1rem 0;
}

legend { font-weight: 600; font-size: 0.85rem; padding: 0 0.35rem; }

.filters {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.filters input { margin-bottom: 0; width: auto; }

/* A short run of buttons side by side, such as the two at the head of a zone. */
.row { display: flex; gap: 0.5rem; align-items: center; }

.inline { display: inline; }
.actions { margin-top: 1rem; }
.actions.row { margin-top: 0.35rem; }
.stack > .actions { margin-top: 0.5rem; }

/* --- the answer-mode chooser ------------------------------------------------ */

.answer-modes { display: grid; gap: 0.35rem; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-weight: 400;
  margin: 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 6px;
}

.choice:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.choice input { margin-top: 0.25rem; }
.choice > span { display: flex; flex-direction: column; gap: 0.1rem; }
.choice .muted { font-size: 0.85rem; }

/* --- the value editor -------------------------------------------------------
   A compact grid of inputs: one row is one value of the set. */

.values-editor { margin-bottom: 0.25rem; table-layout: auto; }
.values-editor th { font-size: 0.72rem; }
.values-editor td { padding: 0.2rem 0.3rem; border-bottom: none; vertical-align: middle; }
.values-editor tbody tr:hover { background: none; }
.values-editor input { margin-bottom: 0; }
.values-editor td.num { width: 1%; }
.values-editor td.num input { width: 6rem; text-align: right; }
.values-editor input[type="checkbox"] { width: auto; }
.values-editor input::placeholder { opacity: 0.55; }

/* The value table can outgrow a narrow screen once a type has four fields; it
   scrolls on its own rather than stretching the page. */
.values-editor { display: block; overflow-x: auto; white-space: nowrap; }
.values-editor tbody, .values-editor thead { display: table; width: 100%; }

.slot {
  margin: 0.35rem 0 0;
  padding: 0.55rem;
  border-top: 1px solid var(--border);
}

.slot input { max-width: 12rem; }
.slot label { margin-top: 0.25rem; }

select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  margin-bottom: 0.4rem;
}

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

button, .button {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .button:hover { border-color: var(--accent); }

button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.linkish {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

.linkish.danger { color: var(--danger); }

a { color: var(--accent); }

/* --- pager ----------------------------------------------------------------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
  padding-top: 0.5rem;
}
