/* ---------------------------------------------------------------------------
   CAP Mission Alerting Tool

   Navy #12233b primary, red #e23b3b accent, light gray #eef1f5 background.
   Everything themable is a custom property so the dark theme is an override
   rather than a second stylesheet.
   --------------------------------------------------------------------------- */

:root {
  /* Brand constants - identical in both themes */
  --navy: #12233b;
  --red: #e23b3b;
  --red-strong: #c93232;

  /* Light theme */
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-sunken: #f7f9fc;
  --surface-raised: #eef1f5;
  --text: #12233b;
  --text-soft: #24405f;
  --text-muted: #6b7a90;
  --border: #dfe4ec;
  --border-input: #c9d2de;
  --header-bg: #12233b;
  --header-text: #ffffff;
  --header-eyebrow: #9fb0c8;
  --tab-bg: #e2e7ee;
  --hover: #f4f6fa;
  --ok: #1c7a44;
  --warn-bg: #fdecec;
  --shadow: 0 1px 2px rgba(18, 35, 59, 0.06);

  /* Mission type accent - overridden per type below */
  --type: #6b7a90;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* Dark theme - applied by the toggle, or by the device preference when the
   duty officer has not chosen explicitly. */

:root[data-theme="dark"] {
  --bg: #0d1520;
  --surface: #151f2e;
  --surface-sunken: #101927;
  --surface-raised: #1d2937;
  --text: #e6ecf4;
  --text-soft: #b9c7d9;
  --text-muted: #8595aa;
  --border: #263447;
  --border-input: #34455c;
  --header-bg: #0a121c;
  --header-text: #ffffff;
  --header-eyebrow: #7e93ad;
  --tab-bg: #16202e;
  --hover: #1c2735;
  --ok: #4cc98a;
  --warn-bg: #3a1f22;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1520;
    --surface: #151f2e;
    --surface-sunken: #101927;
    --surface-raised: #1d2937;
    --text: #e6ecf4;
    --text-soft: #b9c7d9;
    --text-muted: #8595aa;
    --border: #263447;
    --border-input: #34455c;
    --header-bg: #0a121c;
    --header-text: #ffffff;
    --header-eyebrow: #7e93ad;
    --tab-bg: #16202e;
    --hover: #1c2735;
    --ok: #4cc98a;
    --warn-bg: #3a1f22;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- header ---------- */

.site-header {
  background: var(--header-bg);
  border-bottom: 4px solid var(--red);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--header-eyebrow);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.title {
  margin: 2px 0 0;
  color: var(--header-text);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.title .accent { color: var(--red); }

.header-side {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-note {
  margin: 0;
  color: var(--header-eyebrow);
  font-size: 12px;
}

.theme-toggle {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: var(--header-eyebrow);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.theme-toggle:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding-top: 16px;
}

.tab {
  appearance: none;
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--tab-bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 5px 5px 0 0;
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 3px 0 var(--red);
}

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

main { padding-bottom: 40px; }

.panel.is-hidden,
.field.is-hidden { display: none; }

.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 5px 5px 5px;
  padding: 18px 20px 22px;
  box-shadow: var(--shadow);
}

/* The mission card carries the colour of the mission type currently selected,
   so the duty officer gets a glanceable confirmation of what they are sending. */
.card-mission { border-top: 3px solid var(--type); }

.card-title {
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text);
}

/* ---------- mission type accents ---------- */

.panel[data-type="udf"]      { --type: #cf7118; }
.panel[data-type="sar"]      { --type: #2f6fb0; }
.panel[data-type="training"] { --type: #2e8b57; }
.panel[data-type="cn"]       { --type: #1f8a8a; }
.panel[data-type="arc"]      { --type: #7a4fa3; }
.panel[data-type="other"]    { --type: #6b7a90; }

.type-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--type);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* ---------- form fields ---------- */

.field { margin-bottom: 16px; }

.field > label,
.list-head label,
.pseudo-label,
.field legend {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-input);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}

textarea { resize: vertical; }

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--type);
  outline-offset: 1px;
  border-color: var(--type);
}

input[type="checkbox"] { accent-color: var(--red); }

fieldset.channels {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px 12px;
  margin: 0 0 16px;
}

fieldset.channels legend { padding: 0 4px; margin: 0; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-right: 18px;
  font-size: 15px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  min-height: 32px;
}

/* ---------- recipients ---------- */

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.list-actions { display: flex; gap: 12px; }

.link-btn {
  appearance: none;
  border: none;
  background: none;
  padding: 2px 0 6px;
  color: var(--text-soft);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}

.link-btn:hover { color: var(--red); }

.recipient-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border-input);
  border-radius: 4px;
  background: var(--surface);
  padding: 6px 4px;
}

.recipient {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
}

.recipient:hover { background: var(--hover); }

.recipient input { margin-top: 3px; }

.recipient-name { font-weight: 600; }

.recipient-meta {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
}

.count {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------- preview ---------- */

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.preview-head .pseudo-label { margin-bottom: 0; }

.preview {
  margin: 0;
  padding: 13px;
  min-height: 96px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-left: 3px solid var(--type);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

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

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 4px;
  font: inherit;
  font-weight: 600;
  padding: 12px 20px;
  cursor: pointer;
}

.btn-primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.btn-primary:hover { background: var(--red-strong); border-color: var(--red-strong); }

.btn-ghost {
  background: var(--surface);
  border-color: var(--border-input);
  color: var(--text);
}

.btn-ghost:hover { border-color: var(--text-soft); }

.btn[disabled] { opacity: 0.55; cursor: default; }

.send-row { margin-top: 4px; }

/* ---------- status and results ---------- */

.status {
  margin: 12px 0 0;
  font-size: 14px;
  min-height: 1.2em;
  font-weight: 600;
}

.status.ok {
  color: var(--ok);
  padding: 10px 12px;
  background: var(--surface-sunken);
  border-left: 3px solid var(--ok);
  border-radius: 3px;
}

.status.err {
  color: var(--red);
  padding: 10px 12px;
  background: var(--warn-bg);
  border-left: 3px solid var(--red);
  border-radius: 3px;
}

.results { margin-top: 14px; }

.results ul {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.results li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  background: var(--surface);
}

.results li:last-child { border-bottom: none; }

.results .who { font-weight: 700; }

.chan {
  display: block;
  color: var(--text-muted);
  margin-top: 3px;
}

.chan.sent { color: var(--ok); }
.chan.failed { color: var(--red); }
.chan.skipped { color: var(--text-muted); }

/* ---------- roster table ---------- */

.intro { margin-top: 0; }

.muted { color: var(--text-muted); font-size: 13px; }

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.roster-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.roster-table th,
.roster-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.roster-table thead th {
  background: var(--surface-raised);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.roster-table tbody tr:last-child td { border-bottom: none; }

.roster-table input,
.roster-table select { font-size: 14px; padding: 7px 9px; }

.col-active { width: 62px; text-align: center; }
.roster-table td.col-active { text-align: center; }
.col-remove { width: 44px; }

.remove-btn {
  appearance: none;
  border: 1px solid var(--border-input);
  background: var(--surface);
  color: var(--red);
  border-radius: 4px;
  min-width: 32px;
  height: 32px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.remove-btn:hover { border-color: var(--red); background: var(--warn-bg); }

/* Icon only where the column header explains it; worded on the stacked cards. */
.remove-label { display: none; }

.roster-actions { margin: 14px 0 18px; }

.save-row { max-width: 280px; }

.empty-row td {
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px 10px;
}

/* ---------- sent log ---------- */

.log-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 4px;
}

.log-controls .field { margin-bottom: 0; }

.log-entry {
  border: 1px solid var(--border);
  border-left: 3px solid var(--type);
  border-radius: 5px;
  background: var(--surface);
  padding: 14px 16px;
  margin-top: 12px;
}

.log-entry[data-type="udf"]      { --type: #cf7118; }
.log-entry[data-type="sar"]      { --type: #2f6fb0; }
.log-entry[data-type="training"] { --type: #2e8b57; }
.log-entry[data-type="cn"]       { --type: #1f8a8a; }
.log-entry[data-type="arc"]      { --type: #7a4fa3; }
.log-entry[data-type="other"]    { --type: #6b7a90; }

.log-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.log-number { font-weight: 700; }

.log-time {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.log-summary {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.log-facts {
  margin-top: 10px;
  display: grid;
  gap: 4px;
}

.log-fact {
  font-size: 13px;
  display: flex;
  gap: 8px;
}

.log-fact span {
  flex: 0 0 72px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-top: 2px;
}

.log-details { margin-top: 12px; }

.log-details summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-soft);
  padding: 6px 0;
}

.log-details .preview { margin-top: 8px; }

.log-recipients {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.log-recipients li {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.log-recipients li:last-child { border-bottom: none; }

/* ---------- legal pages (privacy, terms) ---------- */

.legal { padding: 20px 20px 40px; }

.legal .card {
  border-radius: 5px;
  max-width: 760px;
  padding: 24px 28px 28px;
}

.legal h3 {
  margin: 26px 0 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.legal p {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.6;
}

.legal a { color: var(--text-soft); }

.legal-meta {
  color: var(--text-muted);
  font-size: 13px;
}

.legal .callout {
  padding: 12px 14px;
  background: var(--surface-sunken);
  border-left: 4px solid var(--red);
}

.legal .warning {
  padding: 12px 14px;
  background: var(--warn-bg);
  border-left: 4px solid var(--red);
}

.legal .contact { line-height: 1.5; }

.legal .disclaimer {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 14px 0 26px;
}

.site-footer p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------------------------------------------------------------------------
   Small screens. A duty officer is as likely to open this on a phone in a car
   as at a desk, so the roster stops being a table and the send button follows
   the thumb.
   --------------------------------------------------------------------------- */

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

@media (max-width: 760px) {
  .wrap { padding: 0 14px; }

  .header-inner {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .header-side { width: 100%; justify-content: space-between; }

  .tabs { padding-top: 12px; }

  .tab { flex: 1; text-align: center; padding: 12px 10px; }

  .card { padding: 16px 14px 20px; }

  /* Comfortable tap targets and no iOS zoom-on-focus (needs >= 16px). */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }

  textarea { min-height: 88px; }

  /* Beats the desktop `.roster-table input/select` rule, which is more
     specific than the bare element selectors above. */
  .roster-table input:not([type="checkbox"]),
  .roster-table select {
    font-size: 16px;
    min-height: 44px;
  }

  .check { min-height: 44px; margin-right: 14px; }

  .check input[type="checkbox"],
  .recipient input[type="checkbox"],
  .roster-table input[type="checkbox"] {
    width: 24px;
    height: 24px;
    flex: none;
  }

  /* The row gives the checkbox a full-height band to be tapped in. */
  .roster-table td.col-active { min-height: 44px; }

  .recipient { padding: 10px 8px; }

  .recipient-list { max-height: 300px; }

  .link-btn { padding: 8px 0; font-size: 13px; }

  /* The roster stops being a table and becomes one card per officer. */
  .table-scroll {
    overflow-x: visible;
    border: none;
    border-radius: 0;
  }

  .roster-table,
  .roster-table tbody,
  .roster-table tr,
  .roster-table td {
    display: block;
    width: 100%;
  }

  .roster-table { min-width: 0; }

  .roster-table thead { display: none; }

  .roster-table tbody tr {
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-input);
    border-radius: 5px;
    background: var(--surface);
    padding: 8px 10px 10px;
    margin-bottom: 12px;
  }

  .roster-table td {
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: none;
    padding: 5px 0;
  }

  .roster-table td::before {
    content: attr(data-label);
    flex: 0 0 76px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .roster-table td.col-active { text-align: left; }
  .col-active, .col-remove { width: auto; }

  .roster-table td.col-remove { padding-top: 8px; }
  .roster-table td.col-remove::before { content: none; }

  .remove-btn {
    width: 100%;
    height: 40px;
    font-size: 13px;
    font-weight: 600;
  }

  .remove-label { display: inline; }

  .empty-row td { display: block; }
  .empty-row td::before { content: none; }

  .roster-actions .btn,
  .btn-primary { width: 100%; }

  .log-controls { display: block; }
  .log-controls .field { margin-bottom: 12px; }
  .log-controls .btn { width: 100%; }
  .log-time { margin-left: 0; width: 100%; }
  .log-fact { flex-direction: column; gap: 0; }
  .log-fact span { flex: none; }

  .save-row { max-width: none; }

  /* Keep Send within thumb reach on a long form. */
  .send-row {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 0 -14px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  .legal { padding: 16px 0 32px; }
  .legal .card { padding: 18px 16px 22px; }
}

@media (prefers-reduced-motion: no-preference) {
  .tab, .btn, .link-btn, .theme-toggle { transition: background-color .12s, border-color .12s, color .12s; }
}
