:root {
  color-scheme: light dark;
  --border: #444;
  --panel-bg: #f2f2f2;
  --text: #1f2328;
  --muted: #666;
  --accent: #1f2328;
  --body-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* The light-mode values above (--muted especially) are too dark
       to read once the page itself goes to a black background --
       these keep every label/caption/heading at a real contrast
       ratio against --body-bg instead of relying on accidental
       legibility from a lighter panel behind it. */
    --border: #8a8f94;
    --panel-bg: #2a2a2a;
    --text: #e8e8e8;
    --muted: #b0b0b0;
    --accent: #5b8def;
    --body-bg: #121212;
  }
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem 4rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--body-bg);
}

h1 { font-size: 1.4rem; margin-bottom: 0.2rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.4rem; }
h3 { font-size: 1rem; margin: 1.4rem 0 0.5rem; }
.muted { color: var(--muted); font-size: 0.85rem; }
.hidden { display: none !important; }

.demo-banner {
  background: #fff3cd; border: 1px solid #ffe69c; color: #664d03;
  padding: 0.6rem 1rem; border-radius: 6px; margin-bottom: 1.5rem; font-size: 0.9rem;
}
.warning-banner {
  background: #fde8e8; border: 1px solid #f3b4b4; color: #7a1f1f;
  padding: 0.6rem 1rem; border-radius: 6px; margin: 1rem 0; font-size: 0.85rem;
}
.error-banner {
  background: #fde8e8; border: 1px solid #f3b4b4; color: #7a1f1f;
  padding: 0.6rem 1rem; border-radius: 6px; margin: 0.8rem 0; font-size: 0.9rem;
}
/* settings.BOOTSTRAP_SOURCE=s3 -- a standby/DR deploy serving a
   snapshot instead of live data (see app.js's init() and
   dr_snapshot.py). Deliberately its own color, distinct from
   .demo-banner (yellow) and .warning-banner/.error-banner (red), so
   it doesn't read as "something's broken" -- this is expected/normal
   for that deploy, just worth knowing at a glance. */
.dr-banner {
  background: #e0ecff; border: 1px solid #adc6f0; color: #1c3f7a;
  padding: 0.6rem 1rem; border-radius: 6px; margin-bottom: 1.5rem; font-size: 0.9rem;
}
/* The error-notify button (label from config.yaml's
   email.error_notify_label) + its send-status text, on the page-load
   error screen (see renderBootstrapError in app.js). */
.error-banner-actions { margin-top: 0.7rem; display: flex; align-items: center; gap: 0.7rem; }
.error-banner-actions .btn { background: #fff; }

/* ---- Page loader ---- */
#pageLoader {
  position: fixed; inset: 0; background: rgba(255,255,255,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; z-index: 200;
}
@media (prefers-color-scheme: dark) {
  #pageLoader { background: rgba(20,20,20,0.92); }
}
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid #ccc; border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Field groups (Product / Delivery / Org multi-selects) ---- */
.field-group { margin-bottom: 1.1rem; }
.field-label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }

.chip-box {
  position: relative; background: var(--panel-bg); border-bottom: 2px solid var(--border);
  padding: 0.5rem 0.6rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
}
.chip {
  background: #dfe3e6; color: #1f2328; border-radius: 999px; padding: 0.15rem 0.4rem 0.15rem 0.7rem;
  display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; white-space: nowrap;
}
.chip button {
  border: none; background: #8a8f94; color: #fff; border-radius: 50%;
  width: 16px; height: 16px; font-size: 0.7rem; line-height: 1; cursor: pointer; padding: 0;
}
.chip-input {
  flex: 1; min-width: 140px; border: none; background: transparent; outline: none;
  font-size: 0.92rem; padding: 0.25rem; color: var(--text);
}
.dropdown-list {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; color: #1f2328;
  border: 1px solid #ccc; max-height: 240px; overflow: auto; z-index: 20;
  box-shadow: 0 6px 14px rgba(0,0,0,0.12);
}
.dropdown-item { padding: 0.45rem 0.75rem; cursor: pointer; font-size: 0.9rem; }
.dropdown-item:hover { background: #eef3ff; }
.dropdown-empty { padding: 0.45rem 0.75rem; color: #888; font-size: 0.85rem; }

.select-all { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; margin-top: 0.35rem; }

/* ---- Manual email adder ---- */
.manual-add-row { display: flex; gap: 0.5rem; margin-top: 0.4rem; }
.manual-add-row input {
  flex: 1; padding: 0.5rem 0.6rem; border: none; border-bottom: 2px solid var(--border);
  background: var(--panel-bg); color: var(--text); font-size: 0.92rem; outline: none;
}
.manual-emails { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }

/* ---- BCC preview ---- */
#bccSection { margin-top: 1.6rem; }
.bcc-counts { font-size: 0.88rem; color: var(--muted); margin-bottom: 0.6rem; }
.org-list { border-top: 1px solid #e2e2e2; }
.org-row {
  padding: 0.65rem 0.2rem; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; border-bottom: 1px solid #e2e2e2; font-size: 0.95rem;
}
.org-row .chevron { color: #888; font-size: 0.8rem; }
.org-row-empty { opacity: 0.7; }
.org-emails { padding: 0.3rem 0.2rem 0.8rem 1.2rem; display: flex; flex-direction: column; gap: 0.35rem; border-bottom: 1px solid #e2e2e2; }
.org-emails .contact-line { font-size: 0.85rem; }
.org-emails .contact-line.muted { font-size: 0.8rem; max-width: 640px; }
.contact-source { color: #999; font-size: 0.75rem; margin-left: 0.35rem; }
.no-orgs { padding: 0.8rem 0.2rem; color: var(--muted); font-size: 0.9rem; }

/* ---- Message section ---- */
#messageSection { margin-top: 2.2rem; padding-top: 1rem; border-top: 1px solid #e2e2e2; }
.static-line { font-size: 0.92rem; margin: 0.5rem 0 0.3rem; }
.static-line.footer-highlight { background: #e6e6e6; padding: 0.15rem 0.4rem; display: inline-block; }
input[type=text].subject-input, textarea.body-input {
  width: 100%; padding: 0.6rem 0.7rem; border: none; border-bottom: 2px solid var(--border);
  background: var(--panel-bg); color: var(--text); font-size: 0.95rem; font-family: inherit; outline: none;
}
textarea.body-input { resize: vertical; min-height: 90px; }

.test-mode-row { display: flex; align-items: center; gap: 0.5rem; margin: 1rem 0 0.6rem; font-size: 0.88rem; }

.btn {
  padding: 0.6rem 1.5rem; border: 1px solid #8a8f94; background: #fff; color: #333;
  font-weight: 600; letter-spacing: 0.03em; cursor: pointer; border-radius: 2px; font-size: 0.85rem;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:disabled { background: #ccc; border-color: #ccc; color: #888; }

.schedule-block { margin-top: 1.4rem; padding-top: 1rem; border-top: 1px solid #e2e2e2; }
.schedule-row { display: flex; gap: 1.2rem; align-items: flex-end; margin-bottom: 0.8rem; flex-wrap: wrap; }
.schedule-row .field { display: flex; flex-direction: column; gap: 0.3rem; }
.schedule-row input {
  padding: 0.5rem 0.6rem; border: none; border-bottom: 2px solid var(--border);
  background: var(--panel-bg); color: var(--text); font-size: 0.9rem;
}

.scheduled-block { margin-top: 1.6rem; padding-top: 1rem; border-top: 1px solid #e2e2e2; }
/* One item = its collapsed .scheduled-row plus an optional
   .scheduled-detail below it when expanded -- the border lives on the
   wrapper (not the row) so it sits under the detail too, same pattern
   as .org-row/.org-emails above. */
.scheduled-item { border-bottom: 1px solid #eee; }
.scheduled-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 0; font-size: 0.9rem; cursor: pointer; gap: 0.6rem;
}
.scheduled-row button { font-size: 0.78rem; padding: 0.3rem 0.7rem; }
.scheduled-summary {
  display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; flex: 1;
}
.scheduled-date, .scheduled-count { flex-shrink: 0; }
/* Truncates a long subject with an ellipsis in the collapsed row only
   -- the expanded .scheduled-detail below shows it in full. flex: 1
   with min-width: 0 is what lets it actually shrink (and therefore
   truncate) instead of pushing the date/count out of view. */
.scheduled-subject {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.scheduled-row .chevron { color: #888; font-size: 0.8rem; flex-shrink: 0; }
.scheduled-detail { padding: 0.2rem 0.2rem 0.9rem 1.2rem; font-size: 0.85rem; }
.scheduled-detail .scheduled-detail-subject { font-weight: 600; margin: 0 0 0.4rem; }
.scheduled-detail .scheduled-detail-body {
  white-space: pre-wrap; margin: 0 0 0.9rem; padding: 0.6rem 0.7rem;
  background: var(--panel-bg); border-radius: 4px;
}
/* Inline, unlike .error-banner -- a failed-send note sits mid-line
   within a .scheduled-row rather than as its own boxed banner. */
.scheduled-row-error { color: #b3261e; }
@media (prefers-color-scheme: dark) {
  .scheduled-row-error { color: #ff8a80; }
}

/* ---- Confirmation modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal {
  background: #fff; color: #1f2328; border-radius: 10px; padding: 1.6rem;
  max-width: 520px; width: 100%; max-height: 82vh; overflow: auto;
}
.modal h2 { margin-top: 0; }
.modal-domain { font-weight: 600; margin-top: 0.8rem; font-size: 0.9rem; }
.modal-email-list { margin: 0.2rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.4rem; }
/* The modal is always a white surface regardless of theme, so its
   "muted" text uses a fixed gray instead of var(--muted) -- that
   variable turns light in dark mode, which would be unreadable here. */
.modal .muted, .modal-note { font-size: 0.82rem; color: #666; margin-top: 0.6rem; }

/* ---- Attachments (SEND NOW only) ---- */
.attachments-block { margin: 0.8rem 0; }
.attachments-block input[type="file"] { display: block; margin-top: 0.3rem; font-size: 0.85rem; }
.attachment-hint { font-size: 0.8rem; margin-top: 0.4rem; }

/* ---- Static login (LOGIN_REQUIRED -- the AWS standby) ---- */
.login-box { max-width: 340px; margin: 4rem auto; }
.login-box form { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 1rem; }
.login-box input[type=text], .login-box input[type=password] {
  padding: 0.55rem 0.7rem; border: none; border-bottom: 2px solid var(--border);
  background: var(--panel-bg); color: var(--text); font-size: 0.95rem; margin-bottom: 0.6rem;
}
.login-box .btn { margin-top: 0.4rem; }
.user-bar { display: flex; justify-content: flex-end; align-items: center; gap: 0.7rem; }
.user-bar .btn { padding: 0.35rem 0.9rem; }
