/* Casilla admin panel. Same postal identity as the webmail: navy ink, airmail red.
   System fonts only (the nginx CSP allows no external fonts, styles or scripts). */

:root {
  color-scheme: light dark;
  --ink: #16213e;
  --muted: #56627a;
  --bg: #f1f3f7;
  --panel: #ffffff;
  --line: #dde2ea;
  --hover: #f3f5f9;
  --blue: #2a4fb0;
  --red: #d1362b;
  --err: #b3261e;
  --ok-bg: #dff3e8;
  --ok-fg: #14573a;
  --warn-bg: #fdebd0;
  --warn-fg: #7a4a07;
  --bad-bg: #fde4e1;
  --bad-fg: #8a1c14;
  --side: #16213e;
  --side-ink: #e8ecf6;
  --side-muted: #aab5cc;
  --side-sel: rgba(255, 255, 255, .17);
  --focus: #2a4fb0;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: Rockwell, "Rockwell Nova", "Roboto Slab", Cambria, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e7ebf3;
    --muted: #a0abc2;
    --bg: #0b1020;
    --panel: #141b2d;
    --line: #26304a;
    --hover: #19223a;
    --blue: #8fb0ff;
    --err: #ff9a90;
    --ok-bg: #123826;
    --ok-fg: #8be0b4;
    --warn-bg: #46300d;
    --warn-fg: #f4c27a;
    --bad-bg: #4a1814;
    --bad-fg: #ffb4ab;
    --side: #0d1429;
    --focus: #8fb0ff;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 var(--sans);
}

a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: .5rem;
  top: -4rem;
  z-index: 100;
  padding: .6rem 1rem;
  border-radius: .5rem;
  background: var(--ink);
  color: var(--panel);
}
.skip:focus { top: .5rem; }

/* ---------- shell ---------- */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  padding: .5rem .75rem;
  background: var(--side);
  color: var(--side-ink);
}
.bar :focus-visible { outline-color: #fff; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  color: inherit;
  font: 700 1.35rem/1 var(--display);
  letter-spacing: -.01em;
  text-decoration: none;
}
.brand.big { font-size: 1.7rem; color: var(--ink); }

.brand-mark {
  width: 1.15rem;
  height: 1.4rem;
  border: 3px dotted var(--red);
  padding: 2px;
  background: var(--red);
  background-clip: content-box;
}

.bar nav ul { display: flex; flex-wrap: wrap; gap: .25rem; margin: 0; padding: 0; list-style: none; }
.bar nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 .75rem;
  border-radius: .5rem;
  color: inherit;
  text-decoration: none;
}
.bar nav a:hover { background: rgba(255, 255, 255, .09); }
.bar nav a[aria-current="page"] { background: var(--side-sel); font-weight: 700; }

.logout { display: flex; align-items: center; gap: .75rem; margin: 0 0 0 auto; }
.who { display: none; margin: 0; color: var(--side-muted); font-size: .85rem; overflow-wrap: anywhere; }

.page { width: 100%; max-width: 70rem; padding: 1.25rem 1rem 3rem; }

.shell.bare { min-height: 100dvh; }
.shell.bare .page { margin: 0 auto; }

@media (min-width: 700px) { .who { display: block; } }

@media (min-width: 900px) {
  .shell:not(.bare) { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100dvh; }
  .bar {
    position: sticky;
    top: 0;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 1.5rem;
    height: 100dvh;
    padding: 1.25rem .75rem;
  }
  .bar nav ul { flex-direction: column; }
  .logout { flex-direction: column; align-items: stretch; margin: auto 0 0; gap: .5rem; }
  .page { padding: 2rem 2rem 4rem; }
}

/* ---------- type ---------- */
h1 { margin: 0 0 .5rem; font: 700 clamp(1.5rem, 4vw, 2rem)/1.2 var(--display); letter-spacing: -.01em; overflow-wrap: anywhere; }
h2 { margin: 0 0 .75rem; font: 700 1.25rem/1.25 var(--display); }
h3 { margin: 1.75rem 0 .75rem; font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted, .help { color: var(--muted); }
.help { margin: 0; font-size: .85rem; }
.crumb { margin: 0 0 .25rem; font-size: .9rem; }
small { color: var(--muted); }
code { font: .88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.block { margin-top: 2.25rem; }
.narrow { max-width: 26rem; margin: 3rem auto; }
.narrow-form { max-width: 28rem; }

/* ---------- messages ---------- */
.flash {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  border: 1px solid currentColor;
  border-radius: .5rem;
}
.flash.ok { background: var(--ok-bg); color: var(--ok-fg); }
.flash.error { background: var(--bad-bg); color: var(--bad-fg); }
.flash.warn { background: var(--warn-bg); color: var(--warn-fg); }

.badge {
  display: inline-block;
  padding: .05rem .6rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  vertical-align: middle;
}
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 2.75rem;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #b92d23; border-color: #b92d23; }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.quiet { border-color: rgba(255, 255, 255, .3); background: none; color: var(--side-ink); }
.btn.quiet:hover { background: rgba(255, 255, 255, .1); }
.btn.small { min-height: 2.25rem; padding: 0 .65rem; font-size: .85rem; }

/* ---------- forms ---------- */
.form { display: grid; gap: 1rem; margin-top: 1rem; }
.form.grid { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); align-items: start; }
.form.inline { margin-top: .5rem; gap: .5rem; min-width: 14rem; }
.field { display: grid; gap: .35rem; }
.field.wide, .form .row { grid-column: 1 / -1; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; }
label { font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], select, textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--panel);
}
textarea { resize: vertical; line-height: 1.5; }

.affix { display: flex; gap: .5rem; align-items: stretch; }
.affix input { flex: 1; min-width: 0; }
.suffix { display: inline-flex; align-items: center; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: .5rem; background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: .7rem .85rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { color: var(--muted); font-size: .85rem; font-weight: 600; white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 600; }

.dns td { min-width: 14rem; }
.table-wrap + .help { margin-top: .75rem; }
.table-wrap + .help + p { margin-top: 1rem; }

/* Narrow screens: each row becomes a small card with labelled fields. */
@media (max-width: 699px) {
  table.stackable, .stackable tbody, .stackable tr, .stackable th, .stackable td { display: block; width: 100%; }
  .stackable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stackable tr { padding: .6rem .85rem; border-bottom: 1px solid var(--line); }
  .stackable tbody tr:last-child { border-bottom: 0; }
  .stackable th, .stackable td { padding: .25rem 0; border: 0; }
  .stackable td[data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: .8rem; }
  .dns td, .actions.stack { min-width: 0; }
}
.dns .btn { margin-top: .35rem; }
code.value { display: block; overflow-wrap: anywhere; word-break: break-all; }

.actions { white-space: nowrap; }
.actions form { display: inline-block; margin: 0; }
.actions.stack { white-space: normal; min-width: 13rem; }
.actions.stack form, .actions.stack details { display: block; margin: 0 0 .5rem; }
details summary { display: flex; align-items: center; min-height: 2.25rem; cursor: pointer; color: var(--blue); }

/* ---------- dashboard figures ---------- */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1.25rem 2rem; margin: 0; }
.figures dt { color: var(--muted); font-size: .9rem; }
.figures dd { margin: 0; font: 700 1.9rem/1.2 var(--display); }
.figures a { color: inherit; text-decoration-color: var(--line); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
