:root {
  --bg: #0b1020;
  --bg-alt: #0f162b;
  --card: #141d36;
  --card-2: #1a2444;
  --border: #26314f;
  --border-soft: #1e2842;
  --text: #e8edf7;
  --muted: #8e9cbb;
  --primary: #5b8cff;
  --primary-dark: #3f6fe0;
  --pass: #2fbf71;
  --fail: #f4525f;
  --warn: #f5a623;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1100px 620px at 12% -8%, #16224a 0%, var(--bg) 58%);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .4rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.24rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.hidden { display: none !important; }
.center { text-align: center; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.row { display: flex; align-items: center; gap: .6rem; }
.row-wrap { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: .6rem; } .mb-1 { margin-bottom: .6rem; }
.mt-2 { margin-top: 1.2rem; } .mb-2 { margin-bottom: 1.2rem; }

/* ---------------- Auth screen ---------------- */
#authScreen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem;
}
.auth-card {
  width: 100%; max-width: 430px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 2rem; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: .65rem; font-weight: 700; font-size: 1.16rem; }
.brand .mark { flex: none; display: block; }
.auth-tabs { display: flex; gap: .35rem; margin: 1.4rem 0 1.2rem; background: var(--bg-alt); padding: .3rem; border-radius: 11px; }
.auth-tabs button {
  flex: 1; background: transparent; border: 0; color: var(--muted);
  padding: .55rem; border-radius: 8px; cursor: pointer; font: inherit; font-size: .9rem; font-weight: 600;
}
.auth-tabs button.active { background: var(--card-2); color: var(--text); }

/* ---------------- App shell ---------------- */
#app { display: none; min-height: 100vh; }
#app.ready { display: grid; grid-template-columns: 244px 1fr; }

.sidebar {
  background: rgba(9, 13, 28, .72);
  border-right: 1px solid var(--border-soft);
  padding: 1.2rem .85rem;
  display: flex; flex-direction: column; gap: .3rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { padding: .2rem .5rem 1.1rem; }
.nav-group-label {
  font-size: .66rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); padding: 1rem .7rem .35rem; font-weight: 700;
}
.nav-btn {
  display: flex; align-items: center; gap: .6rem;
  background: transparent; border: 0; color: var(--muted);
  padding: .58rem .7rem; border-radius: var(--radius-sm);
  cursor: pointer; font: inherit; font-size: .9rem; text-align: left; width: 100%;
  /* The shared button rule centres content; nav items must read as a list. */
  justify-content: flex-start;
}
.nav-btn:hover { background: var(--card); color: var(--text); }
.nav-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-icon { width: 18px; text-align: center; flex: none; }

.scope-banner {
  background: rgba(245, 166, 35, .12);
  border: 1px solid rgba(245, 166, 35, .45);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem; margin-bottom: .6rem;
}
.scope-banner .tiny { color: var(--warn); font-weight: 800; letter-spacing: .07em; font-size: .62rem; }
.scope-banner .name {
  font-weight: 700; font-size: .88rem; margin: .1rem 0 .4rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.scope-banner button { width: 100%; padding: .25rem; font-size: .74rem; }

.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border-soft); }
.usage-meter { padding: .6rem .7rem; }
.meter { height: 6px; background: var(--bg-alt); border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.meter > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }
.meter.warn > span { background: var(--warn); }
.meter.full > span { background: var(--fail); }

.main {
  padding: 1.6rem 2rem 4rem; max-width: 1240px;
  /* Grid items default to min-width:auto, so wide content (code blocks, tables)
     would stretch the column instead of scrolling inside it. */
  min-width: 0;
}
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }

/* ---------------- Cards / layout ---------------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.3rem;
  min-width: 0;
}
.card pre { max-width: 100%; overflow-x: auto; }
/* Spacing for cards stacked in normal flow. */
.card + .card { margin-top: 1.1rem; }
/* ...but side-by-side cards are still adjacent siblings, so the same rule was
   pushing every second column down by 1.1rem. The grid's own `gap` already
   spaces these, so the margin is both wrong and redundant here. */
.grid-2 > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.1rem; align-items: start; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .9rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; margin-top: .2rem; }

/* ---------------- Forms ---------------- */
label { display: block; font-size: .78rem; font-weight: 650; color: var(--muted); margin-bottom: .35rem; text-transform: uppercase; letter-spacing: .045em; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], select, textarea {
  width: 100%; background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  padding: .62rem .75rem; font: inherit; font-size: .92rem; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
textarea.code { font-family: var(--mono); font-size: .8rem; line-height: 1.55; }
.field { margin-bottom: .95rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
input[type=range] { width: 100%; accent-color: var(--primary); cursor: pointer; }

/* Password reveal. There is no password-reset flow yet, so a typo in a new
   password is unrecoverable without a superadmin — seeing what you typed
   matters more here than in an app that can email a reset link. */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 2.75rem; }
.pw-toggle {
  position: absolute; top: 0; right: 0; height: 100%; width: 2.75rem;
  display: grid; place-items: center;
  background: none; border: 0; padding: 0; margin: 0;
  color: var(--muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle:focus-visible {
  outline: 2px solid var(--primary); outline-offset: -3px;
  border-radius: var(--radius-sm); color: var(--text);
}
.pw-toggle svg { width: 18px; height: 18px; display: block; pointer-events: none; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .1rem; }
.slider-head label { margin: 0; }
.slider-val { font-size: .78rem; font-weight: 700; color: var(--primary); }

button, .btn {
  background: var(--card-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .58rem 1.05rem;
  font: inherit; font-size: .89rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
}
button:hover:not(:disabled) { border-color: var(--primary); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--primary-dark); }
button.danger { color: var(--fail); border-color: rgba(244, 82, 95, .4); }
button.danger:hover:not(:disabled) { background: rgba(244, 82, 95, .12); border-color: var(--fail); }
button.ghost { background: transparent; }
button.wide { width: 100%; }
button.sm { padding: .35rem .7rem; font-size: .8rem; }

/* ---------------- Scanner ---------------- */
.scan-tabs { display: flex; gap: .35rem; background: var(--bg-alt); padding: .3rem; border-radius: 11px; margin-bottom: 1.1rem; }
.scan-tabs button { flex: 1; background: transparent; border: 0; color: var(--muted); padding: .6rem; border-radius: 8px; }
.scan-tabs button.active { background: var(--card-2); color: var(--text); }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 2.4rem 1.2rem; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s; background: var(--bg-alt);
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: rgba(91, 140, 255, .07); }
.dropzone .big { font-size: 2rem; margin-bottom: .4rem; }
.file-chip {
  display: flex; align-items: center; gap: .7rem; padding: .75rem .9rem;
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

.result-banner {
  display: flex; align-items: center; gap: .9rem;
  padding: 1.05rem 1.2rem; border-radius: var(--radius); margin-bottom: 1.1rem;
}
.result-banner .icon { font-size: 1.7rem; }
.result-banner.pass { background: rgba(47, 191, 113, .12); border: 1px solid rgba(47, 191, 113, .4); }
.result-banner.fail { background: rgba(244, 82, 95, .12); border: 1px solid rgba(244, 82, 95, .4); }
.result-banner h2 { margin: 0; }

.violation {
  border: 1px solid var(--border); border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm); padding: .95rem 1.05rem; margin-bottom: .8rem; background: var(--bg-alt);
}
.violation.high { border-left-color: var(--fail); }
.violation.low { border-left-color: var(--primary); }
.violation .claim { font-style: italic; color: var(--text); border-left: 2px solid var(--border); padding-left: .7rem; margin: .5rem 0; }
.violation .fix { background: rgba(47, 191, 113, .08); border: 1px solid rgba(47, 191, 113, .25); border-radius: 8px; padding: .6rem .75rem; margin-top: .6rem; font-size: .88rem; }

/* ---------------- Badges / pills ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .55rem; border-radius: 99px;
  font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  border: 1px solid var(--border); background: var(--bg-alt); color: var(--muted);
}
.badge.pass { background: rgba(47, 191, 113, .15); color: var(--pass); border-color: rgba(47, 191, 113, .35); }
.badge.fail { background: rgba(244, 82, 95, .15); color: var(--fail); border-color: rgba(244, 82, 95, .35); }
.badge.warn { background: rgba(245, 166, 35, .15); color: var(--warn); border-color: rgba(245, 166, 35, .35); }
.badge.info { background: rgba(91, 140, 255, .15); color: var(--primary); border-color: rgba(91, 140, 255, .35); }

/* Copyable placeholder tokens in the email template editor. */
.chip {
  font-family: var(--mono); font-size: .74rem; padding: .2rem .5rem;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--card-2); color: var(--muted); cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--primary); }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th {
  text-align: left; padding: .6rem .7rem; color: var(--muted);
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--border); font-weight: 700; white-space: nowrap;
}
td { padding: .7rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:hover { background: rgba(255, 255, 255, .022); }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }
/* Data tables carry a lot of columns; trim the horizontal padding so they fit
   without a scrollbar at common widths. */
.table-wrap th, .table-wrap td { padding-inline: .5rem; }
/* Compact icon actions in table cells. */
.table-wrap td .btn.sm, .table-wrap td button.sm { padding: .3rem .5rem; }
.table-wrap th:first-child, .table-wrap td:first-child { padding-inline-start: .7rem; }
.table-wrap th:last-child, .table-wrap td:last-child { padding-inline-end: .7rem; }
.empty { text-align: center; padding: 2.6rem 1rem; color: var(--muted); }

/* ---------------- Model list ---------------- */
.dns-rec {
  display: grid; grid-template-columns: 58px 1fr; gap: .5rem;
  padding: .45rem 0; border-top: 1px solid rgba(255,255,255,.07);
}
.dns-rec > div:last-child { min-width: 0; overflow-wrap: anywhere; }

.model-item {
  display: flex; align-items: center; gap: .8rem; padding: .8rem .9rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: .55rem; cursor: pointer; background: var(--bg-alt);
}
.model-item:hover { border-color: var(--primary); }
.model-item.active { border-color: var(--primary); background: rgba(91, 140, 255, .1); }

/* ---------------- Plans ---------------- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 1rem; }
.plan {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.2rem; background: var(--card); display: flex; flex-direction: column; gap: .55rem;
}
.plan.current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.plan .price { font-size: 1.85rem; font-weight: 700; line-height: 1; }
.plan ul { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .85rem; }
.plan li { margin-bottom: .25rem; }
.plan button { margin-top: auto; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 8, 18, .78);
  backdrop-filter: blur(6px); z-index: 900;
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto;
  padding: 1.5rem; box-shadow: var(--shadow);
}
.modal.wide { max-width: 940px; }

/* ---------------- Toast / alerts ---------------- */
#toasts { position: fixed; bottom: 1.4rem; right: 1.4rem; z-index: 1000; display: flex; flex-direction: column; gap: .55rem; }
.toast {
  background: var(--card-2); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm); padding: .75rem 1rem; box-shadow: var(--shadow);
  max-width: 380px; font-size: .88rem; animation: slideIn .18s ease;
}
.toast.error { border-left-color: var(--fail); }
.toast.success { border-left-color: var(--pass); }
@keyframes slideIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .88rem; margin-bottom: 1rem; }
.alert.error { background: rgba(244, 82, 95, .12); border: 1px solid rgba(244, 82, 95, .35); color: #ffb4ba; }
.alert.warn { background: rgba(245, 166, 35, .12); border: 1px solid rgba(245, 166, 35, .35); color: #ffd89a; }
.alert.info { background: rgba(91, 140, 255, .12); border: 1px solid rgba(91, 140, 255, .35); }

.spinner {
  width: 15px; height: 15px; border: 2px solid rgba(255, 255, 255, .28);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.scanning { display: flex; flex-direction: column; align-items: center; gap: .9rem; padding: 3rem 1rem; }
.scanning .spinner { width: 34px; height: 34px; border-width: 3px; border-top-color: var(--primary); }

/* ---------------- Responsive ---------------- */
.app-topbar { display: none; }
.drawer-backdrop { display: none; }

.nav-toggle {
  width: 40px; height: 40px; padding: 0; flex: none;
  background: transparent; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.nav-toggle span {
  display: block; width: 17px; height: 2px; border-radius: 2px;
  background: var(--text); transition: transform .22s ease, opacity .18s ease;
}

@media (max-width: 900px) {
  #app.ready { grid-template-columns: 1fr; }

  .app-topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 60;
    display: flex; align-items: center; gap: .75rem;
    height: 58px; padding: 0 .9rem;
    background: rgba(9, 13, 28, .96); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-soft);
  }
  .topbar-title { font-weight: 700; font-size: 1.02rem; }

  /* The sidebar becomes an off-canvas drawer. It previously wrapped into a
     strip of buttons that jumbled the nav, and hid .sidebar-foot entirely —
     which meant no usage meter, no account and no way to sign out on mobile. */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 70;
    width: 270px; max-width: 84vw; height: 100vh;
    border-right: 1px solid var(--border);
    transform: translateX(-100%); transition: transform .24s ease;
    overflow-y: auto;
    /* Opaque: the desktop sidebar is translucent over the page background,
       which as an overlay drawer left the content showing through. */
    background: #0c1223;
    padding-top: 1rem;
  }
  body.drawer-open .sidebar { transform: none; }

  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(4, 7, 16, .6);
    opacity: 0; pointer-events: none; transition: opacity .24s ease;
  }
  body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }

  body.drawer-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  body.drawer-open .nav-toggle span:nth-child(2) { opacity: 0; }
  body.drawer-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .main { padding: calc(58px + 1.1rem) 1.1rem 3rem; }
  .field-row { grid-template-columns: 1fr; }
  .modal { max-height: 92vh; padding: 1.1rem; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

@media (min-width: 901px) {
  .app-topbar, .drawer-backdrop { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .drawer-backdrop, .nav-toggle span { transition: none; }
}
