/* ===========================================================
   ADMIN — staff-facing interface.

   Different job from the public site: this is operated all day,
   so it prioritises density and speed over marketing polish.
   Same brand tokens, quieter application of them.
   =========================================================== */

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 {
  font-family: var(--font-display); font-weight: 800; margin: 0;
  line-height: 1.2; letter-spacing: -.015em;
}
.tnum { font-variant-numeric: tabular-nums; }
.eyebrow {
  display: inline-block; font-size: .72rem; font-weight: 700;
  letter-spacing: .18em; text-transform: uppercase; color: var(--red);
  margin-bottom: .6rem;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  font-weight: 700; font-size: .92rem; padding: .7em 1.4em;
  border-radius: var(--r-pill); white-space: nowrap;
  transition: transform var(--dur-fast), background var(--dur-fast), box-shadow var(--dur-fast);
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--red); color: #fff; box-shadow: var(--shadow-red); }
.btn-primary:hover:not(:disabled) { background: var(--red-600); transform: translateY(-1px); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-500); }
.btn-outline { border: 1.5px solid var(--hairline); color: var(--navy); background: var(--surface); }
.btn-outline:hover { border-color: var(--navy); }
.btn-sm { padding: .5em 1em; font-size: .84rem; }
.btn-block { width: 100%; padding: .9em 1.4em; font-size: 1rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ---------- FIELDS ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s-4); }
.field label { font-size: .86rem; font-weight: 600; color: var(--ink-soft); }
.field label .req { color: var(--red); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 1rem; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--hairline); border-radius: var(--r-md); padding: .72em .9em;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  width: 100%;
}
.field textarea { resize: vertical; min-height: 96px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(32,47,107,.12);
}
.field.err input, .field.err select, .field.err textarea { border-color: var(--red); }
.field .msg { font-size: .78rem; color: var(--red); min-height: 1em; }
.field .hint { font-size: .78rem; color: var(--muted); }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 3rem; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border-radius: var(--r-sm); color: var(--muted);
  display: grid; place-items: center;
}
.pw-toggle:hover { color: var(--navy); }
.pw-toggle svg { width: 19px; height: 19px; }
.pw-toggle.on { color: var(--red); }

/* ---------- ALERTS ---------- */
.alert {
  display: flex; gap: .7em; align-items: flex-start;
  border-radius: var(--r-md); padding: .85em 1.1em; margin-bottom: var(--s-4);
  font-size: .9rem; border: 1px solid transparent;
}
.alert svg { width: 19px; height: 19px; flex: none; margin-top: 1px; }
.alert-error { background: var(--danger-bg); color: #9B1B20; border-color: #F6C9CB; }
.alert-ok    { background: var(--ok-bg);     color: var(--ok);   border-color: #BFE6D2; }
.alert-info  { background: var(--info-bg);   color: var(--navy); border-color: #C4D0EE; }
.alert-warn  { background: var(--warn-bg);   color: #7A4E0C;     border-color: #F0D9B5; }

/* ---------- STATUS PILLS ---------- */
.pill {
  display: inline-flex; align-items: center; gap: .45em; font-size: .78rem;
  font-weight: 700; padding: .35em .8em; border-radius: var(--r-pill);
  border: 1px solid transparent; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-ok      { background: var(--ok-bg);     color: var(--ok);    border-color: #BFE6D2; }
.pill-info    { background: var(--info-bg);   color: var(--navy);  border-color: #C4D0EE; }
.pill-warn    { background: var(--warn-bg);   color: var(--warn);  border-color: #F0D9B5; }
.pill-bad     { background: var(--danger-bg); color: var(--red);   border-color: #F6C9CB; }
.pill-neutral { background: var(--surface-2); color: var(--muted); border-color: var(--hairline); }

/* ===========================================================
   LOGIN
   =========================================================== */
.login-body { background: var(--surface); }
.login-split { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }

.login-brand {
  position: relative; overflow: hidden; color: #fff;
  background: linear-gradient(150deg, #243471 0%, #182354 55%, #0D1433 100%);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: clamp(28px, 4vw, 56px);
}
.login-brand::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(45deg,
    rgba(255,255,255,.03) 0 1px, transparent 1px 44px);
}
.login-brand-in { position: relative; z-index: 2; margin: auto 0; max-width: 34rem; }
.login-brand img { height: 52px; width: auto; margin-bottom: clamp(28px, 5vw, 52px); }
.login-brand h2 { font-size: clamp(1.7rem, 3vw, 2.5rem); color: #fff; margin-bottom: .6rem; }
.login-brand p { color: rgba(255,255,255,.78); margin: 0 0 var(--s-6); max-width: 40ch; }
.login-brand ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .85rem; }
.login-brand li {
  display: flex; align-items: center; gap: .8em;
  color: rgba(255,255,255,.9); font-size: .95rem;
}
.login-brand li svg {
  width: 18px; height: 18px; flex: none; color: var(--red-300);
  background: rgba(227,30,36,.16); border-radius: 50%; padding: 4px;
}
.login-back { position: relative; z-index: 2; font-size: .86rem; color: rgba(255,255,255,.6); }
.login-back:hover { color: #fff; }

.login-panel { display: grid; place-items: center; padding: clamp(28px, 5vw, 56px); }
.login-form-wrap { width: 100%; max-width: 25rem; }
.login-form-wrap h1 { font-size: clamp(1.8rem, 3vw, 2.3rem); color: var(--navy); }
.login-sub { color: var(--muted); margin: .5rem 0 var(--s-6); }
.login-locked { margin-top: var(--s-4); font-size: .85rem; color: var(--warn); }
.login-foot {
  margin-top: var(--s-6); padding-top: var(--s-5);
  border-top: 1px solid var(--hairline); font-size: .84rem; color: var(--muted);
}

@media (max-width: 900px) {
  .login-split { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-panel { min-height: 100vh; }
}

/* ===========================================================
   ADMIN SHELL
   =========================================================== */
.shell { display: grid; grid-template-columns: 246px 1fr; min-height: 100vh; }

/* The mobile drawer backdrop. It MUST be positioned at every width, not only
   inside the mobile media query — otherwise it counts as a grid child on
   desktop, takes column 2, and pushes .main onto a second row where it renders
   246px wide and empty-looking. */
.side-scrim {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(13, 20, 51, .5);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-mid) var(--ease);
}

.side {
  background: var(--navy-900); color: rgba(255,255,255,.72);
  display: flex; flex-direction: column; padding: var(--s-5) 0;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { padding: 0 var(--s-5) var(--s-6); }
.side-brand img { height: 40px; width: auto; }
.side nav { display: flex; flex-direction: column; gap: 2px; padding: 0 var(--s-3); }
.side nav a {
  display: flex; align-items: center; gap: .8em; padding: .72em .9em;
  border-radius: var(--r-md); font-size: .93rem; font-weight: 600;
  color: rgba(255,255,255,.7); transition: background var(--dur-fast), color var(--dur-fast);
}
.side nav a svg { width: 18px; height: 18px; flex: none; }
.side nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.side nav a[aria-current="page"] { background: var(--red); color: #fff; }
.side-foot {
  margin-top: auto; padding: var(--s-5) var(--s-5) 0;
  border-top: 1px solid rgba(255,255,255,.1); font-size: .82rem;
}
.side-user { color: #fff; font-weight: 700; }
.side-role { color: rgba(255,255,255,.5); text-transform: capitalize; }
.side-foot a { display: inline-block; margin-top: .7rem; color: var(--red-300); font-weight: 600; }
.side-foot a:hover { color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--hairline);
  padding: var(--s-4) clamp(16px, 3vw, 32px);
  display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.35rem; color: var(--navy); }
.topbar .sub { font-size: .85rem; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; gap: var(--s-3); align-items: center; }
.content { padding: clamp(18px, 3vw, 32px); flex: 1; }

.burger-admin { display: none; width: 42px; height: 42px; border-radius: var(--r-sm); }
.burger-admin span {
  display: block; width: 20px; height: 2px; background: var(--navy); margin: 5px auto;
}

/* ---------- STAT CARDS ---------- */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--s-4); margin-bottom: var(--s-6);
}
.stat-card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: var(--s-5); position: relative; overflow: hidden;
}
/* A severity stripe so what needs attention reads at a glance, not by reading numbers. */
.stat-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--navy);
}
.stat-card.is-warn::before { background: var(--warn); }
.stat-card.is-ok::before   { background: var(--ok); }
.stat-card.is-bad::before  { background: var(--red); }
.stat-card .lbl {
  font-size: .76rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted);
}
.stat-card .val {
  font-family: var(--font-display); font-size: 2.1rem; font-weight: 800;
  color: var(--navy); line-height: 1.1; margin-top: .3rem;
}
.stat-card .foot { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* ---------- PANEL + TABLE ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); overflow: hidden;
}
.panel-head {
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--hairline);
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
}
.panel-head h2 { font-size: 1.05rem; color: var(--navy); }
.panel-head .right { margin-left: auto; display: flex; gap: var(--s-3); align-items: center; }
.panel-body { padding: var(--s-5); }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 760px; }
table.data th {
  text-align: left; font-size: .72rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); padding: .85rem var(--s-5);
  border-bottom: 1.5px solid var(--hairline); white-space: nowrap; background: var(--surface-2);
}
table.data th a { display: inline-flex; align-items: center; gap: .3em; }
table.data th a:hover { color: var(--navy); }
table.data td {
  padding: .8rem var(--s-5); border-bottom: 1px solid var(--hairline);
  vertical-align: middle; color: var(--ink-soft);
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .bill { font-weight: 700; color: var(--navy); }
table.data .muted { color: var(--muted); font-size: .84rem; }
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; }
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--r-sm); display: grid; place-items: center;
  color: var(--muted); border: 1px solid var(--hairline); background: var(--surface);
  transition: all var(--dur-fast);
}
.icon-btn:hover { color: var(--navy); border-color: var(--navy); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---------- FILTER BAR ---------- */
.filters {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: var(--s-3);
  align-items: end; padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--hairline); background: var(--surface-2);
}
.filters .field { margin-bottom: 0; }
.filters .field label { font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* ---------- EMPTY STATE ---------- */
.empty-state { text-align: center; padding: var(--s-9) var(--s-5); }
.empty-state .ico {
  width: 58px; height: 58px; margin: 0 auto var(--s-4); border-radius: 50%;
  background: var(--surface-2); color: var(--muted); display: grid; place-items: center;
}
.empty-state .ico svg { width: 26px; height: 26px; }
.empty-state h3 { color: var(--navy); margin-bottom: .4rem; }
.empty-state p { color: var(--muted); margin: 0 auto var(--s-5); max-width: 40ch; }

/* ---------- PAGINATION ---------- */
.pager {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-4) var(--s-5); border-top: 1px solid var(--hairline);
}
.pager .count { font-size: .85rem; color: var(--muted); }
.pager .links { margin-left: auto; display: flex; gap: .3rem; }
.pager .links a, .pager .links span {
  min-width: 34px; height: 34px; padding: 0 .6em; border-radius: var(--r-sm);
  display: grid; place-items: center; font-size: .86rem; font-weight: 600;
  border: 1px solid var(--hairline); color: var(--ink-soft);
}
.pager .links a:hover { border-color: var(--navy); color: var(--navy); }
.pager .links .on { background: var(--navy); border-color: var(--navy); color: #fff; }
.pager .links .gap { border: none; }

/* ---------- FORM LAYOUT ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-5); }
.form-grid .full { grid-column: 1 / -1; }
.form-section {
  font-size: .74rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); grid-column: 1 / -1;
  padding-bottom: .5rem; margin-bottom: var(--s-4); border-bottom: 1px solid var(--hairline);
}
.form-section:not(:first-child) { margin-top: var(--s-5); }
.form-actions {
  display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap;
  padding: var(--s-4) var(--s-5); border-top: 1px solid var(--hairline);
  background: var(--surface-2); position: sticky; bottom: 0;
}
.form-actions .spacer { margin-left: auto; }

@media (max-width: 1000px) {
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; inset: 0 auto 0 0; width: 246px; z-index: 60; height: 100vh;
    transform: translateX(-100%); transition: transform var(--dur-mid) var(--ease);
  }
  .side.open { transform: none; }
  .burger-admin { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  /* Only reachable on mobile, where the drawer can actually be opened. */
  .side-scrim.on { opacity: 1; pointer-events: auto; }
}

/* Sort direction marker in table headers */
.sort-ind { font-size: .62rem; color: var(--red); }

/* ---------- SETTINGS ---------- */
.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--s-4); align-items: start;
}
.toggle-row {
  display: flex; align-items: center; gap: .6em; font-size: .9rem;
  color: var(--ink-soft); cursor: pointer; margin-top: var(--s-2);
}
.toggle-row input { width: 17px; height: 17px; accent-color: var(--red); }

/* ---------- DESTRUCTIVE ACTIONS ---------- */
.icon-btn.danger:hover { color: var(--red); border-color: var(--red); }
.btn-danger { background: var(--red); color: #fff; box-shadow: var(--shadow-red); }
.btn-danger:hover { background: var(--red-700); transform: translateY(-1px); }
.modal-scrim {
  position: fixed; inset: 0; z-index: 200; background: rgba(13,20,51,.55);
  display: grid; place-items: center; padding: var(--s-4);
}
.modal-scrim[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--r-lg); padding: var(--s-6);
  max-width: 26rem; width: 100%; box-shadow: var(--shadow-lg);
}
.modal h2 { color: var(--navy); font-size: 1.2rem; margin-bottom: var(--s-3); }
.modal p { color: var(--muted); font-size: .92rem; margin-bottom: var(--s-5); }
.modal-actions { display: flex; gap: var(--s-3); justify-content: flex-end; }
