/* Email Marketing UI.
   Loaded BEFORE the dashboard's inline <style>, so shared classes (.status-pill, .panel,
   .small-button, ...) must NOT be redefined here - the dashboard's later rules would win.
   This file owns only the email-* components, and every size/colour comes from the dashboard
   tokens so both themes follow. Two scopes: #emailMarketing (the Broadcast -> Email page) and
   .email-sender-settings (the administrator block on the Settings page). */

#emailMarketing .email-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 16px 0;
  padding: 3px;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--white);
}
/* The tab buttons are built with .small-button, so reset its border/fill here (id + class
   outranks the single class) and use the house tinted-surface active state. */
#emailMarketing .email-tabs button {
  min-height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0;
  transform: none;
}
#emailMarketing .email-tabs button:hover {
  background: #142438;
  color: var(--ink);
}
#emailMarketing .email-tabs button[aria-selected="true"] {
  background: #142438;
  color: var(--lime);
}
#emailMarketing .email-banner,
.email-sender-settings .email-banner {
  border: 1px solid var(--line);
  padding: 11px 14px;
  border-radius: 5px;
  background: var(--white);
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-normal);
}
#emailMarketing .email-table,
.email-sender-settings .email-table {
  width: 100%;
  border-collapse: collapse;
}
#emailMarketing .email-table td,
#emailMarketing .email-table th,
.email-sender-settings .email-table td,
.email-sender-settings .email-table th {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
/* Matches the dashboard's own table headers (mono, tracked, tinted). */
#emailMarketing .email-table th,
.email-sender-settings .email-table th {
  background: #152337;
  color: var(--muted);
  font-family: var(--mono);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  white-space: nowrap;
}
#emailMarketing .email-table td,
.email-sender-settings .email-table td {
  color: var(--ink);
  font-size: var(--fs-sm);
  vertical-align: middle;
}
#emailMarketing .email-table td:first-child,
.email-sender-settings .email-table td:first-child {
  max-width: 300px;
  overflow-wrap: anywhere;
}
#emailMarketing .email-actions,
.email-sender-settings .email-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
/* Sender accounts are one card row each instead of a table, so the identity, the sending
   limits and the actions sit together and the actions can be icons. Reuses the dashboard's
   .icon-button / .status-pill / .count-chip rather than restyling them here. */
.email-sender-settings .sender-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}
.email-sender-settings .sender-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.email-sender-settings .sender-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
}
.email-sender-settings .sender-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.email-sender-settings .sender-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #48a27b;
}
.email-sender-settings .sender-dot.pending {
  background: #d8a13a;
}
.email-sender-settings .sender-dot.off {
  background: #b9c2bb;
}
.email-sender-settings .sender-copy {
  min-width: 0;
}
.email-sender-settings .sender-name {
  color: var(--ink);
  font-weight: 700;
}
.email-sender-settings .sender-meta {
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: var(--fs-2xs);
  overflow-wrap: anywhere;
}
.email-sender-settings .sender-side {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* The empty state and the prerequisite banner render outside .email-modal, so they need
   their own rules: .email-hint/.email-banner are only styled inside the modal above. */
.email-sender-settings .email-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
}
.email-sender-settings .email-banner {
  margin-top: 10px;
}
/* Matches the dashboard's .dry-notice tint, which is what this warns about: email cannot
   send until the encryption key and the public HTTPS URL are saved. */
.email-sender-settings .email-banner.warn {
  border-color: #66532d;
  background: #30291d;
  color: #f0c56a;
}
/* One shell for every email modal: a titled header, a scrollable body and a bordered footer.
   The dialog is a flex column so the body absorbs the leftover height and the header and
   footer stay put however long the form is. */
.email-modal {
  display: flex;
  flex-direction: column;
  width: min(880px, 95vw);
  max-height: 88vh;
  padding: 0;
  overflow: hidden;
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px #03091247;
}
.email-modal::backdrop {
  background: #030912bd;
  backdrop-filter: blur(2px);
}
.email-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.email-modal-title {
  margin: 0;
  color: var(--ink);
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: var(--track-heading);
  line-height: var(--lh-tight);
}
.email-modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px 20px 20px;
}
.email-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: var(--white);
}
/* Dialogs opened just to read something (reports, previews) have no actions. */
.email-modal-foot:empty {
  display: none;
}
.email-modal .email-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}
.email-modal label {
  display: block;
  color: var(--muted);
  margin: 0 0 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
}
.email-modal input:not([type="checkbox"]),
.email-modal select,
.email-modal textarea {
  width: 100%;
  min-height: 38px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 5px;
  padding: 9px 11px;
  font-size: var(--fs-sm);
}
.email-modal input:not([type="checkbox"]):focus,
.email-modal select:focus,
.email-modal textarea:focus {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 2px #4d8bff24;
}
/* A checkbox label is a control, not a field caption. */
.email-modal label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 400;
}
.email-modal label:has(input[type="checkbox"]) input {
  width: auto;
  min-height: 0;
  margin: 0;
  accent-color: var(--blue);
}
.email-modal textarea {
  min-height: 90px;
}
.email-modal .email-full {
  grid-column: 1/-1;
}
/* Named block inside a long form, e.g. the sender editor. */
.email-modal .email-section {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.email-modal .email-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.email-modal .email-section-title {
  color: var(--ink);
  font-family: var(--mono);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
}
.email-modal .email-section-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: var(--fs-xs);
}
.email-modal .email-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 14px 0;
}
/* A failed save is a boxed alert, not a coloured line of text. */
.email-modal .email-error:not(:empty) {
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid #5a3941;
  border-radius: 5px;
  background: #241d27;
  color: #ff8a83;
  white-space: pre-wrap;
}
.email-modal .email-hint {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-normal);
  margin: 8px 0;
}
/* The preview frame and the Quill editor stay a LIGHT island in both themes on purpose:
   they represent the email itself, which is authored for a white mail-client canvas.
   Only the surrounding chrome (borders, radius) follows the theme. */
.email-modal iframe {
  background: white;
  width: 100%;
  height: 350px;
  border: 1px solid var(--line);
  border-radius: 5px;
}
.email-modal .ql-container {
  height: 250px;
  background: white;
  color: #17212b;
}
/* quill.snow.css sets its own Helvetica stack; keep the app font inside the editor. */
.email-modal .ql-editor {
  font-family: var(--sans);
}
.email-modal .ql-toolbar {
  background: #f3f5f8;
}
.email-modal .email-step {
  border: 1px solid var(--line);
  padding: 14px;
  margin: 10px 0;
  border-radius: 5px;
}
.email-modal pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.email-modal summary {
  cursor: pointer;
  margin: 10px 0;
}
.email-modal .email-rule {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}
.email-modal .email-rule > * {
  flex: 1;
  min-width: 100px;
}
@media (max-width: 650px) {
  .email-modal .email-fields {
    grid-template-columns: 1fr;
  }
  #emailMarketing .email-table td,
  .email-sender-settings .email-table td {
    padding: 8px;
  }
  .email-sender-settings .sender-row {
    grid-template-columns: minmax(0, 1fr);
  }
  .email-sender-settings .sender-side {
    flex-wrap: wrap;
    justify-content: space-between;
  }
}

/* ============================================================================
   Light theme - ADDITIVE ONLY, and LAST so it wins within this file.
   Everything above already follows the dashboard colour tokens, so most surfaces
   flip for free; only the deliberately hard-coded values need a counterpart.
   ============================================================================ */
html[data-theme="light"] #emailMarketing .email-tabs button:hover {
  background: #eef2f7;
  color: #16202b;
}
html[data-theme="light"] #emailMarketing .email-tabs button[aria-selected="true"] {
  background: #e2edfb;
  color: #0b5fb0;
}
html[data-theme="light"] #emailMarketing .email-table th,
html[data-theme="light"] .email-sender-settings .email-table th {
  background: #f2f5f8;
  color: #5d6b7a;
}
html[data-theme="light"] .email-modal::backdrop {
  background: #1018284d;
}
html[data-theme="light"] .email-modal {
  box-shadow: 0 24px 80px #1018282e;
}
html[data-theme="light"] .email-modal .email-error:not(:empty) {
  border-color: #e6c3c5;
  background: #fdecec;
  color: #b3281f;
}
html[data-theme="light"] .email-modal input:focus,
html[data-theme="light"] .email-modal select:focus,
html[data-theme="light"] .email-modal textarea:focus {
  border-color: #0b74e0;
  box-shadow: 0 0 0 2px #0b74e029;
}
/* Status dots carry meaning by colour, so they need the light-theme greens/ambers. */
html[data-theme="light"] .email-sender-settings .sender-dot {
  background: #12a06a;
}
html[data-theme="light"] .email-sender-settings .sender-dot.pending {
  background: #a86f12;
}
html[data-theme="light"] .email-sender-settings .sender-dot.off {
  background: #b0b8c0;
}
html[data-theme="light"] .email-sender-settings .email-banner.warn {
  border-color: #f0dcae;
  background: #fdf3d9;
  color: #8a5a12;
}
