/* ===========================================================================
   Email Platform — shared design system
   Internal admin tool: dark rail, light workspace, high-contrast surfaces.

   Conventions used across every page:
     - surfaces alternate: --bg (page) vs --surface (cards) — never card-on-
       same-shade, so panels always read as distinct objects
     - buttons are solid fills on light backgrounds, never translucent
     - cards in a row are equal height (.grid > .card { height: 100% })
   =========================================================================== */

:root {
  --navy-900: #0d1526;
  --navy-800: #14203a;
  --navy-700: #1d2c4d;
  --navy-600: #2a3d66;

  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-alt: #f7f9fc;
  --border: #d6dce7;
  --border-strong: #b6c0d1;

  --text: #16203a;
  --text-muted: #5a6883;
  --text-invert: #eaf0fb;

  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #e5edff;

  --ok: #157f4a;
  --ok-soft: #e2f5ec;
  --warn: #9a6400;
  --warn-soft: #fdf1da;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --info: #0e6b8a;
  --info-soft: #e2f2f8;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 26, 51, 0.08);
  --shadow: 0 4px 14px rgba(16, 26, 51, 0.1);
  --shadow-lg: 0 12px 32px rgba(16, 26, 51, 0.16);

  --rail-w: 232px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.22rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 1rem; }
code, pre, .mono { font-family: var(--mono); font-size: .88em; }

/* ------------------------------------------------------------------ layout */

.app { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--navy-900);
  color: var(--text-invert);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.rail-brand {
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.rail-brand strong { display: block; font-size: 1rem; letter-spacing: -.01em; }
.rail-brand span { font-size: .76rem; color: #93a4c4; }
.rail-logo { display: block; max-width: 100%; max-height: 34px; width: auto; margin-bottom: .3rem; }

.rail-nav { padding: .75rem .6rem; flex: 1; }
.rail-group { margin-bottom: 1rem; }
.rail-group-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #7f92b5;
  padding: .35rem .65rem;
  font-weight: 600;
}
.rail-nav a {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .48rem .65rem;
  border-radius: var(--radius-sm);
  color: #c6d2e8;
  font-size: .89rem;
  text-decoration: none;
}
.rail-nav a:hover { background: var(--navy-700); color: #fff; text-decoration: none; }
.rail-nav a.active { background: var(--accent); color: #fff; font-weight: 600; }

.rail-foot {
  padding: .85rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, .1);
  font-size: .8rem;
  color: #93a4c4;
}
.rail-foot a { color: #c6d2e8; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .85rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.topbar h1 { margin: 0; font-size: 1.15rem; }

.content { padding: 1.75rem; flex: 1; }
.content > section + section { margin-top: 1.75rem; }

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.25rem;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: -1.15rem -1.25rem 1rem;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-head h2, .card-head h3 { margin: 0; }
.card.flush { padding: 0; }
.card.flush .card-head { margin: 0; border-radius: var(--radius) var(--radius) 0 0; }

/* Equal-height cards in a row regardless of content length. */
.grid { display: grid; gap: 1rem; }
.grid > * { height: 100%; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* Stat tiles sit on the light page background, so they take a dark treatment
   to stand apart from the surrounding white cards. */
.stat {
  background: var(--navy-800);
  color: var(--text-invert);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow-sm);
}
.stat .label { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: #93a4c4; }
.stat .value { font-size: 1.75rem; font-weight: 680; line-height: 1.15; margin-top: .2rem; }
.stat .sub { font-size: .8rem; color: #a7b6d2; margin-top: .15rem; }
.stat.ok .value { color: #7ee2ac; }
.stat.warn .value { color: #ffce7a; }
.stat.danger .value { color: #ff9d95; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: .89rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { text-decoration: none; }

/* Solid fills only on light surfaces — a translucent button disappears here. */
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-alt); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1e17; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

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

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: .3rem; }
.field .hint { font-size: .79rem; color: var(--text-muted); margin-top: .28rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], select, textarea {
  width: 100%;
  padding: .5rem .65rem;
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 110px; resize: vertical; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 220px; }

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

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .89rem; }
table.data th {
  text-align: left;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: .6rem .85rem;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td { padding: .6rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-alt); }
table.data tbody tr:last-child td { border-bottom: none; }
/* Alignment utilities must beat `table.data th`'s left-align.
   That base rule is specificity (0,1,2); a bare `.right` is (0,1,0), so it lost
   on the header while winning on the cell — headers left, data right, columns
   visibly out of line. Scoping the utilities to the table raises them to
   (0,2,2) so a header and its column always agree. */
table.data th.num, table.data td.num,
table.data th.right, table.data td.right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data th.center, table.data td.center { text-align: center; }
table.data th.left, table.data td.left { text-align: left; }

/* ------------------------------------------------------- badges & banners */

.badge {
  display: inline-block;
  padding: .13rem .5rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #e8ecf3; color: var(--text-muted); }

.banner {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  margin-bottom: 1.1rem;
  font-size: .9rem;
}
.banner strong { display: block; }
.banner-ok { background: var(--ok-soft); border-color: var(--ok); color: #0c5c35; }
.banner-warn { background: var(--warn-soft); border-color: var(--warn); color: #7a4f00; }
.banner-danger { background: var(--danger-soft); border-color: var(--danger); color: #8f1e17; }
.banner-info { background: var(--info-soft); border-color: var(--info); color: #0b5570; }

/* Full-stop / maintenance state must be impossible to miss. */
.banner-stop {
  background: var(--danger);
  color: #fff;
  border-color: #7d1913;
  box-shadow: var(--shadow);
}
.banner-stop a { color: #fff; text-decoration: underline; }

/* ------------------------------------------------------------------ misc */

.muted { color: var(--text-muted); }
.small { font-size: .84rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}
.empty h3 { color: var(--text); }

.progress {
  height: 8px;
  background: #dfe5ef;
  border-radius: 999px;
  overflow: hidden;
}
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress.ok > span { background: var(--ok); }
.progress.warn > span { background: var(--warn); }
.progress.danger > span { background: var(--danger); }

/* ---------------------------------------------------------- auth screens */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--navy-900), var(--navy-700));
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
}
.auth-card h1 { font-size: 1.3rem; }
.auth-card .btn { width: 100%; }
/* Side-by-side actions (resend / cancel) still fill their half of the row. */
.auth-card .btn-row { display: flex; gap: .6rem; }
.auth-card .btn-row form { margin: 0; }
.auth-card details > summary { cursor: pointer; color: var(--text-muted); }

/* One-time code entry: wide, monospaced, and spaced so a six-digit string is
   readable at a glance and hard to mistype. */
/* Specificity has to clear the `input[type="text"]` base rule above, hence the
   attribute selector rather than a bare class. */
input[type="text"].code-input {
  font-family: var(--mono);
  font-size: 1.5rem;
  letter-spacing: .38em;
  text-align: center;
  padding: .6rem .5rem;
}

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .rail { width: 100%; flex: none; height: auto; position: static; }
  .rail-nav { display: flex; flex-wrap: wrap; gap: .25rem; }
  .rail-group { margin: 0; }
  .content, .topbar { padding: 1rem; }
}
