:root {
  color-scheme: dark;
  --bg: #0b1019;
  --panel: #1a1f27;
  --panel-raised: #222832;
  --ink: #e7eaf0;
  --muted: #aab2bd;
  --line: #363e49;
  --accent: #d8ad58;
  --accent-dark: #bd8e36;
  --accent-soft: #332f24;
  --danger: #e29a91;
  --danger-soft: #3b2524;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  border-right: 1px solid #2e3540;
  background: #080d16;
  color: #fff;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  margin: 2px 8px 28px;
  font-weight: 800;
  letter-spacing: -.01em;
}

.brand-logo {
  display: block;
  width: 176px;
  height: auto;
  object-fit: contain;
}

.brand-name {
  color: #a5aeba;
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

nav { display: grid; gap: 5px; }

nav a, .nav-button {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #c6d0cb;
  font: inherit;
  font-weight: 650;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

nav a:hover, nav a.active, .nav-button:hover { background: rgba(216,173,88,.14); color: #f2d69b; }
.logout-form { margin-top: auto; }

.main { min-width: 0; padding: 34px clamp(20px, 4vw, 52px) 60px; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-header h1 { margin: 2px 0 0; font-size: clamp(1.8rem, 3vw, 2.35rem); letter-spacing: -.035em; }
.page-header p { margin: 6px 0 0; color: var(--muted); }
.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

.panel, .metric-card, .settings-notice, .login-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel { padding: 20px; }
.table-panel { padding: 0; overflow: hidden; }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel h2, .panel-heading h2 { margin: 2px 0 0; font-size: 1.08rem; }
.text-link, .name-link { font-weight: 700; text-decoration: none; }
.name-link { color: var(--ink); }
.name-link:hover { color: var(--accent); text-decoration: underline; }

.metric-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card { padding: 18px; }
.metric-card span { color: var(--muted); font-size: .85rem; font-weight: 650; }
.metric-card strong { display: block; margin-top: 5px; font-size: 2rem; line-height: 1; }
.school-counter-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}
.school-counter-card h2 { margin: 3px 0 0; }
.school-counters { display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)); }
.school-counters > div { min-width: 155px; padding: 4px 20px; border-left: 1px solid var(--line); }
.school-counters span { display: block; color: var(--muted); font-size: .78rem; }
.school-counters strong { display: block; margin-top: 3px; font-size: 1.65rem; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); gap: 18px; }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1.6fr) repeat(2, minmax(155px, .8fr)) 90px auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
}
.email-filter-bar {
  display: grid;
  grid-template-columns: minmax(210px, 1.4fr) minmax(145px, .8fr) minmax(145px, .8fr)
    repeat(2, minmax(135px, .65fr)) 80px auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
}
.filter-actions { display: flex; gap: 7px; }
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
}
.pagination p { margin: 0; color: var(--muted); }
.pagination-links { display: flex; align-items: center; gap: 10px; }
.pagination-links > span:not(.button-quiet) { color: var(--muted); font-size: .84rem; }
.button-quiet.disabled { opacity: .48; cursor: not-allowed; }

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #141922;
}

.selection-actions, .record-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.selection-count { margin-left: 5px; color: var(--muted); font-size: .82rem; }
.selection-error { color: var(--danger); font-weight: 700; }

button, .button-link, .button-secondary, .button-quiet, input[type="submit"] {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #17201d;
  font: inherit;
  font-size: .84rem;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .button-link:hover, input[type="submit"]:hover { background: var(--accent-dark); }
.button-secondary { background: var(--panel-raised); color: #edcd8b; }
.button-quiet { border-color: var(--line); background: transparent; color: var(--ink); }
.button-archive { border-color: #626b77; background: #272d36; color: #ccd2da; }
.button-archive:hover { border-color: var(--accent); background: #343129; color: #f0d79f; }
.button-danger { border-color: #774b48; background: var(--panel-raised); color: var(--danger); }
.button-danger:hover { background: var(--danger-soft); }

.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #131821; color: var(--muted); font-size: .72rem; letter-spacing: .055em; text-transform: uppercase; }
tbody tr:hover { background: #242a33; }
tbody tr:last-child td { border-bottom: 0; }
.date-cell { color: var(--muted); font-variant-numeric: tabular-nums; }
.checkbox-column { width: 52px; text-align: center; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }

.status, .delivery {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: .72rem;
  font-weight: 800;
}
.status-waiting { background: #293641; color: #b9cedf; }
.status-updated { background: #213c2b; color: #a7d9b5; }
.status-rescheduled { background: #372d47; color: #ceb8e6; }
.status-reminded { background: #40371f; color: #efd18b; }
.status-confirmed, .delivery-sent { background: #1f3d2a; color: #9ed9ae; }
.status-cancelled, .delivery-failed { background: #442725; color: #efaaa2; }
.status-overdue { background: #482f22; color: #efb18d; }
.status-archived { background: #303735; color: #b9c2be; }

.activity-list { display: grid; }
.activity-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.activity-item:last-child { border: 0; }
.activity-link { color: inherit; text-decoration: none; }
.activity-link:hover { color: var(--accent); }
.activity-item strong, .activity-item span { display: block; }
.activity-item div span { color: var(--muted); font-size: .82rem; text-transform: capitalize; }
.applicant-email-timeline { margin-bottom: 18px; padding: 0; overflow: hidden; }
.applicant-email-timeline .panel-heading { margin: 0; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.timeline-count { color: var(--muted); font-size: .82rem; }
.timeline-link-cell { text-align: right; }

.detail-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
dl { display: grid; grid-template-columns: 110px 1fr; gap: 10px; }
dt { color: var(--muted); }
dd { margin: 0; }

.stack-form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: .84rem; font-weight: 700; }
[hidden] { display: none !important; }
select, textarea, input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid #47505d;
  border-radius: 7px;
  padding: 9px 10px;
  background: #11161d;
  color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(216, 173, 88, .16); border-color: var(--accent); }
.edit-table input { min-width: 145px; }
.edit-table select { min-width: 165px; }
.edit-table input[type="date"], .edit-table input[type="number"] { min-width: 120px; }
.readonly-value { display: block; min-width: 145px; color: var(--ink); font-weight: 650; white-space: normal; }
.field-help { margin: -4px 0 0; color: var(--muted); font-size: .78rem; }
.campaign-send-form { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.campaign-send-form .field-help { margin: 0 0 10px; }
.template-subsection { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; }
.template-subsection h3 { margin: 0; font-size: .95rem; }
.settings-overview { align-items: start; }
.settings-layout { display: flex; flex-direction: column; }
.settings-layout > .settings-template-panel { order: -1; }
.settings-template-panel { margin-bottom: 18px; padding: 0; overflow: hidden; }
.settings-template-panel > .panel-heading { margin: 0; padding: 20px 22px 16px; }
.template-heading p { margin: 6px 0 0; color: var(--muted); font-size: .86rem; }
.template-tabs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 0 22px 14px;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.template-tabs .template-tab {
  width: auto;
  min-width: max-content;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161d;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
  white-space: nowrap;
}
.template-tabs .template-tab:hover { border-color: #77663f; background: var(--accent-soft); color: var(--ink); }
.template-tabs .template-tab.is-active {
  border-color: var(--accent-dark);
  background: var(--accent-soft);
  color: #f2d69b;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.template-editor { padding: 22px; }
.template-pair-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.campaign-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 0 22px 22px; }
.campaign-tools .campaign-send-form { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 9px; background: #141922; }
.integration-state { padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .72rem; font-weight: 800; }
.integration-state.is-ready { border-color: #456f61; background: #19342c; color: #9ed4c0; }
.integration-state.is-warning { border-color: #80574f; background: var(--danger-soft); color: var(--danger); }
.integration-meta { display: grid; gap: 5px; }
.integration-meta span { color: var(--muted); font-size: .76rem; font-weight: 700; }
.integration-meta code { overflow-wrap: anywhere; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #11161d; color: var(--ink); font-size: .78rem; }
input[readonly] { color: var(--muted); cursor: text; }

.builder-toolbar, .preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.applicant-stack, .preview-stack { display: grid; gap: 20px; }
.applicant-editor { padding: 20px; }
.applicant-heading, .reservation-heading, .program-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.applicant-heading { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.applicant-heading h2, .reservation-heading h3 { margin: 3px 0; }
.applicant-heading p { margin: 0; color: var(--muted); }
.host-family-field { width: min(100%, 260px); }
.reservation-list { display: grid; gap: 16px; margin: 18px 0; }
.reservation-card { padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: #141922; }
.reservation-fields { display: grid; grid-template-columns: minmax(220px, 1.4fr) minmax(170px, .8fr) minmax(110px, .5fr); gap: 12px; margin-top: 14px; }
.program-section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.program-list { display: grid; gap: 10px; margin-top: 10px; }
.program-row { display: grid; grid-template-columns: minmax(220px, 1fr) 130px auto; align-items: end; gap: 10px; }
.email-preview-card { padding: 20px; }
.email-preview-card .panel-heading p { margin: 8px 0 0; }
.email-preview-frame { width: 100%; min-height: 520px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.preview-stack .email-preview-frame { min-height: 780px; }
.preview-actions { justify-content: flex-end; margin-top: 20px; }

.flash { margin-bottom: 18px; padding: 12px 15px; border: 1px solid #a6d0c7; border-radius: 8px; background: var(--accent-soft); color: var(--accent-dark); }
.flash-error { border-color: #e2b0b0; background: var(--danger-soft); color: var(--danger); }
.settings-notice { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 18px; padding: 15px 18px; }
.settings-notice span { color: var(--muted); }
.empty-state { padding: 24px !important; color: var(--muted); text-align: center; }

pre { overflow: auto; padding: 14px; border-radius: 8px; background: #090e16; color: #dce1e8; white-space: pre-wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

.auth-page { display: grid; grid-template-columns: 1fr; place-items: center; padding: 24px; background: #080d16; }
.auth-shell { width: min(100%, 430px); }
.login-card { padding: 32px; }
.login-card h1 { margin: 0; font-size: 2rem; letter-spacing: -.03em; }
.login-card > p { margin: 8px 0 24px; color: var(--muted); }
.login-brand {
  align-items: center;
  margin: 0 0 28px;
}
.login-brand .brand-logo { width: 210px; }
.login-brand .brand-name { color: var(--muted); }

@media (max-width: 1050px) {
  .dashboard-grid, .detail-grid, .settings-grid { grid-template-columns: 1fr; }
  .action-bar { align-items: flex-start; flex-direction: column; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .email-filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-search { grid-column: 1 / -1; }
  .template-pair-grid, .campaign-tools { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { grid-template-columns: repeat(3, 1fr); }
  .logout-form { margin-top: 12px; }
  .main { padding: 24px 14px 44px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .metric-row { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .school-counter-card { align-items: flex-start; flex-direction: column; }
  .school-counters { width: 100%; grid-template-columns: 1fr; }
  .school-counters > div { padding: 10px 0; border-top: 1px solid var(--line); border-left: 0; }
  .filter-bar { grid-template-columns: 1fr; }
  .email-filter-bar { grid-template-columns: 1fr; }
  .filter-search { grid-column: auto; }
  .filter-actions { flex-wrap: wrap; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .settings-notice { flex-direction: column; }
  .settings-template-panel > .panel-heading, .template-editor { padding-right: 16px; padding-left: 16px; }
  .template-tabs { padding-right: 16px; padding-left: 16px; }
  .campaign-tools { padding-right: 16px; padding-left: 16px; }
  .applicant-heading, .reservation-heading { align-items: flex-start; flex-direction: column; }
  .host-family-field { width: 100%; }
  .reservation-fields, .program-row { grid-template-columns: 1fr; }
}
