/* Roboto (Apache 2.0) — the ONLY interface font in this panel. Self-hosted so it
   always loads, even where Google Fonts is blocked. One variable file covers
   every weight 300-700; Roboto Mono is used for licence keys and hostnames so
   0/O and 1/l stay distinguishable. */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300 700;          /* variable range */
  font-display: swap;
  src: url('fonts/roboto-v51-latin-var.woff2') format('woff2');
}
@font-face {
  font-family: 'Roboto Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/roboto-mono-v31-latin-400.woff2') format('woff2');
}

/* Carter One (SIL Open Font License) - self-hosted so no request ever leaves
   the server and the wordmark still renders if Google is unreachable. */
@font-face {
  font-family: 'Carter One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/carter-one-v18-latin.woff2') format('woff2');
}

:root {
  --violet: #9100F8;
  --violet-dark: #6d00bd;
  --orange: #f55a18;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #ffffff;
  --ok: #0a8a3f; --warn: #996800; --bad: #b32d2e;
}
* { box-sizing: border-box; }
h1, h2, h3, h4 { font-weight: 400; }
body { margin: 0; font-family: 'Roboto', sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--violet); }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1000px 500px at 50% -10%, rgba(145,0,248,.18), transparent), var(--bg); }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 30px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 50px rgba(30,41,59,.10); }
.brand { font-weight: 500; font-size: 20px; letter-spacing: -.02em; margin-bottom: 4px; }
.brand b { color: var(--violet); }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

/* Shell — fixed header + dedicated left icon rail */
:root { --appbar-h: 64px; --rail-w: 88px; }

/* Header spans the full width and stays put while the page scrolls. */
.appbar { position: fixed; top: 0; left: 0; right: 0; z-index: 70; height: var(--appbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: #fff; border-bottom: 1px solid var(--line); }
.appbar .brand { margin: 0; font-size: 18px; white-space: nowrap; }
.appbar .spacer { flex: 1; }
.tagpill { font-size: 11.5px; color: var(--violet); background: #f4e9ff;
  padding: 3px 10px; border-radius: 999px; }
.who { color: var(--muted); font-size: 13px; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: none; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  transition: border-color .15s, background .15s, color .15s; }
.icon-btn svg { width: 20px; height: 20px; display: block; }
button.icon-btn:hover { background: #f6f7fb; border-color: #d9c9ea; }
.nav-toggle { display: none; }

/* Left rail: icon above label, sitting under the header. */
.rail { position: fixed; top: var(--appbar-h); left: 0; bottom: 0; z-index: 60; width: var(--rail-w);
  background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; padding: 14px 8px 16px; overflow-y: auto; }
.rail-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 11px 4px; border-radius: 12px; text-decoration: none; border: 0; background: none;
  color: var(--muted); font-size: 11.5px; line-height: 1.25; text-align: center; width: 100%;
  transition: background .15s, color .15s; }
.rail-item svg { width: 22px; height: 22px; flex: none; }
.rail-item:hover { background: #f6f7fb; color: var(--ink); }
.rail-item.active { background: #f4e9ff; color: var(--violet); }
/* Accent bar hugs the rail's right edge (matches the 8px padding). */
.rail-item.active::after { content: ""; position: absolute; right: -8px; top: 50%;
  width: 3px; height: 26px; margin-top: -13px; border-radius: 3px 0 0 3px; background: var(--violet); }
.rail-foot { margin-top: auto; }

.main { margin-left: var(--rail-w); padding-top: var(--appbar-h); min-width: 0; }
.content { max-width: 1040px; margin: 0 auto; padding: 22px 20px; }
.scrim { display: none; }

/* Narrow screens: the rail slides in over the page, the header stays fixed. */
@media (max-width: 860px) {
  .appbar { padding: 0 12px; gap: 8px; }
  .nav-toggle { display: inline-flex; }
  .appbar .who { display: none; }
  /* 200px keeps a 5:1 mark at the full 40px height on tablet widths. */
  .appbar .brand-logo { max-width: 200px; }
  .rail { transform: translateX(-100%); transition: transform .22s ease; }
  .rail.open { transform: translateX(0); }
  .scrim { display: block; position: fixed; top: var(--appbar-h); left: 0; right: 0; bottom: 0;
    z-index: 55; background: rgba(15,23,42,.42); }
  .main { margin-left: 0; }
  .content { padding: 18px 16px; }
}

.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
/* Form fields align to the TOP of a row, never centre: their heights differ
   (a two-line hint vs none), and centring pushed each label and input to a
   different vertical position. Everything else in a .row still centres. */
.row > .field { align-self: flex-start; }

label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
textarea { font: inherit; resize: vertical; line-height: 1.5; }
.field { flex: 1 1 180px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 500; }
.btn-primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn-primary:hover { background: var(--violet-dark); }
.btn-danger { color: var(--bad); border-color: #f1c0c0; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* 7 columns with hostnames will not fit a phone — let the table scroll rather
   than force the whole page sideways. */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.domain-line { font-family: 'Roboto Mono', monospace; font-size: 12.5px;
  line-height: 1.55; white-space: nowrap; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tbody tr:hover { background: #faf7ff; cursor: pointer; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-active { background: #e7f6ec; color: var(--ok); }
.badge-grace { background: #fcf9e8; color: var(--warn); }
.badge-expired, .badge-suspended, .badge-revoked { background: #fdecec; color: var(--bad); }
.badge-pending { background: #eef2ff; color: #4f46e5; }

.key-box { font-family: 'Roboto Mono', monospace; background: #0f172a; color: #a5f3c0; padding: 10px 12px;
  border-radius: 8px; display: inline-block; letter-spacing: 1px; }
.muted { color: var(--muted); }
.err { color: var(--bad); font-size: 13px; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.back { background: none; border: 0; color: var(--violet); padding: 0; margin-bottom: 10px; font-weight: 500; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.mono { font-family: 'Roboto Mono', monospace; font-size: 12.5px; }

/* ---------- settings forms ---------- */
.field { margin-bottom: 14px; }
.hintline { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.45; }
.hintline code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.okline { color: var(--ok); font-size: 13px; margin-top: 10px; }

.term-preview { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fbfbfd; max-width: 420px; }
.term-row { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; padding: 3px 0; }
.term-row b { font-weight: 500; }
input:disabled { background: #f6f7fb; color: var(--muted); }

.danger-zone { margin-top: 22px; padding: 16px; border: 1px solid #f1c0c0;
  border-radius: 12px; background: #fffafa; }
.danger-zone h3 { color: var(--bad); }

/* ---------- branding ---------- */
/* The two logo options sit side by side; the active one is outlined. */
.logo-cards { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.logo-card { flex: 1 1 340px; min-width: 300px; margin-bottom: 0; transition: border-color .15s, background .15s; }
.logo-card.chosen { border-color: var(--violet); background: #fdfaff; }
.pickrow { display: flex; align-items: center; gap: 9px; margin: 0 0 14px; font-size: 14px; color: var(--ink); cursor: pointer; }
.pickrow input { width: auto; margin: 0; }
.pickrow b { font-weight: 500; }
.swatch { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
input[type=color] { flex: none; }

/* Text wordmark as rendered in the header */
.logo-text { display: block; }

/* Rendered at a fixed 40px tall; width follows the aspect ratio. object-fit
   keeps very wide marks undistorted if they hit the width cap instead. */
.brand-logo { height: 40px; width: auto; max-width: 260px; object-fit: contain; display: block; }
.promo-preview { display: grid; place-items: center; min-height: 64px; padding: 12px;
  border: 1px dashed var(--line); border-radius: 12px; background: #fbfbfd; margin-bottom: 16px; }
.promo-chip { display: inline-flex; align-items: center; gap: 9px; padding: 9px 16px; border-radius: 999px;
  background: linear-gradient(90deg, #fff1f2, #fff7ed); border: 1px solid #fde3e7; color: #d8455c; font-size: 14px; }
.promo-chip svg { width: 17px; height: 17px; flex: none; }
.logo-preview { display: grid; place-items: center; min-height: 84px; padding: 14px;
  border: 1px dashed var(--line); border-radius: 12px; background: #fbfbfd; margin-bottom: 16px; }
.logo-preview img { max-height: 56px; max-width: 260px; object-fit: contain; }
input[type=file] { font-size: 13px; }
.cooldown-note { margin-top: 10px; background: #fff8e6; border: 1px solid #f3e0b0; color: #7a5a00;
  border-radius: 10px; padding: 9px 12px; font-size: 12.5px; }

/* --- Email template editor ------------------------------------------------ */
/* Editor and preview side by side on a wide screen, stacked on a narrow one:
   the preview is the point of the screen, so it must never be pushed off. */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.mail-toolbar { gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.mail-toolbar .btn { padding: 5px 10px; min-width: 34px; justify-content: center; }

/* Both modes share a box so switching Visual/HTML does not make the page jump. */
.mail-editor { width: 100%; min-height: 300px; max-height: 60vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: #fff;
  font-size: 14px; line-height: 1.6; }
.mail-editor:focus { outline: 2px solid var(--violet); outline-offset: -1px; }
textarea.mail-editor { resize: vertical; white-space: pre-wrap; }
.mail-editor h2 { font-size: 17px; font-weight: 500; margin: 0 0 10px; }
.mail-editor p { margin: 0 0 10px; }
.mail-editor a { color: var(--violet); }

.mail-preview { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 10px;
  background: #f4f5f9; display: block; }

/* The real header bar at its real size, so the colour is judged as it will
   actually appear rather than as a small chip. */
.mail-header-swatch { border-radius: 12px 12px 0 0; padding: 22px 26px; border: 1px solid var(--line); border-bottom: none; }
/* Edited in place on the header bar, so the wordmark is judged in context. */
.mail-logo-box { color: #fff; font-weight: 500; outline: none; min-width: 40px; display: inline-block; }
.mail-logo-box:focus { box-shadow: 0 0 0 2px rgba(255,255,255,.55); border-radius: 4px; }

/* --- broadcast colour pickers --- */
.bc-color { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.bc-color input[type="color"] { width: 54px; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; cursor: pointer; background: #fff; }
