/* Customer Reports - styled with the Stockpile design system (Repurpose It brand, RPI Genie look).
   Token names and values come from Stockpile's tokens.json; see the README there for usage rules. */

:root {
  /* identity (same in both themes) */
  --ri-teal: #008e73;
  --ri-lime: #94d800;
  --genie-deep: #061410;
  --brand: #007961;
  --on-brand: #ffffff;
  --on-accent: #0a0a0a;
  --appbar-bg: #08120e;
  --appbar-line: rgba(255, 255, 255, 0.12);
  --appbar-eyebrow: #94d800;
  --pill-bg: rgba(255, 255, 255, 0.06);
  --pill-border: rgba(255, 255, 255, 0.14);
  --danger: #e8003d;
  --status-online: #94d800;

  /* light: Repurpose It */
  --brand-dark: #007961;
  --link: #007961;
  --accent: #4f7400;
  --indicator: #007961;
  --bg: #edf1ef;
  --card-top: #ffffff;
  --card: #ffffff;
  --card-border: #d9e2dd;
  --surface: #ffffff;
  --text: #0f1a16;
  --muted: #4a5852;
  --line: #d9e2dd;
  --input: #e7eeea;
  --focus-bg: #ffffff;
  --soft-brand: #e2f1ec;
  --bad: #c4002f;
  --bad-bg: #fff3f6;
  --ok: #0a7d4f;
  --ok-bg: #e4f6ee;
  --warn-bg: #fff4e3;
  --warn-border: #f0c98a;
  --warn-text: #8a4b00;
  --disabled-text: #9099a4;
  --blocked: #c5c9ce;
  --toast-bg: #1a1d21;
  --scrim: rgba(8, 18, 14, 0.6);
  --shadow-card: 0 1px 2px rgba(10, 10, 10, 0.06), 0 1px 1px rgba(10, 10, 10, 0.04);
  --shadow-lift: 0 1px 2px rgba(10, 10, 10, 0.06), 0 4px 16px rgba(10, 10, 10, 0.05);
  --shadow-topbar: 0 1px 3px rgba(0, 0, 0, 0.12);
  --shadow-popover: 0 4px 8px rgba(10, 10, 10, 0.06), 0 16px 32px rgba(10, 10, 10, 0.08);
  --shadow-overlay: 0 12px 40px rgba(0, 0, 0, 0.3);

  /* type */
  --sans: Inter, Aptos, Calibri, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* space and shape */
  --space-label: 4px;
  --space-tight: 8px;
  --space-control-y: 10px;
  --space-field-row: 12px;
  --space-card-gap: 14px;
  --space-gutter: 16px;
  --space-control: 44px;
  --space-button: 46px;
  --space-content: 1100px;
  --radius: 10px;
  --radius-control: 8px;
  --radius-tile: 12px;
  --radius-overlay: 16px;
  --radius-pill: 999px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

/* dark: RPI Genie */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-dark: #4db09d;
    --link: #4db09d;
    --accent: #94d800;
    --indicator: #94d800;
    --bg: #061410;
    --card-top: #10251f;
    --card: #0b1b16;
    --card-border: rgba(255, 255, 255, 0.12);
    --surface: #0f221c;
    --text: #f2f5f3;
    --muted: #a3b3ac;
    --line: #21362f;
    --input: #152b24;
    --focus-bg: #1b362d;
    --soft-brand: #0f2e25;
    --bad: #ff6b8a;
    --bad-bg: #3a1a23;
    --ok: #4fd39a;
    --ok-bg: #123024;
    --warn-bg: #3a2a12;
    --warn-border: #6b4a1a;
    --warn-text: #ffc477;
    --disabled-text: #5f7069;
    --blocked: #2b3e37;
    --toast-bg: #1b362d;
    --scrim: rgba(6, 20, 16, 0.7);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 32px rgba(77, 176, 157, 0.12);
    --shadow-topbar: 0 1px 0 rgba(0, 0, 0, 0);
    --shadow-popover: 0 16px 32px rgba(0, 0, 0, 0.5);
    --shadow-overlay: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 64px rgba(77, 176, 157, 0.15);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand-dark: #4db09d;
  --link: #4db09d;
  --accent: #94d800;
  --indicator: #94d800;
  --bg: #061410;
  --card-top: #10251f;
  --card: #0b1b16;
  --card-border: rgba(255, 255, 255, 0.12);
  --surface: #0f221c;
  --text: #f2f5f3;
  --muted: #a3b3ac;
  --line: #21362f;
  --input: #152b24;
  --focus-bg: #1b362d;
  --soft-brand: #0f2e25;
  --bad: #ff6b8a;
  --bad-bg: #3a1a23;
  --ok: #4fd39a;
  --ok-bg: #123024;
  --warn-bg: #3a2a12;
  --warn-border: #6b4a1a;
  --warn-text: #ffc477;
  --disabled-text: #5f7069;
  --blocked: #2b3e37;
  --toast-bg: #1b362d;
  --scrim: rgba(6, 20, 16, 0.7);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lift: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 32px rgba(77, 176, 157, 0.12);
  --shadow-topbar: 0 1px 0 rgba(0, 0, 0, 0);
  --shadow-popover: 0 16px 32px rgba(0, 0, 0, 0.5);
  --shadow-overlay: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 64px rgba(77, 176, 157, 0.15);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
::selection { background: var(--ri-lime); color: var(--on-accent); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.4 var(--sans);
}

/* ---------- Genie header (same in both themes) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-gutter);
  padding: var(--space-control-y) var(--space-gutter);
  background: var(--appbar-bg);
  color: var(--on-brand);
  border-bottom: 1px solid var(--appbar-line);
  box-shadow: var(--shadow-topbar);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; display: block; }
.brand-divider { width: 1px; height: 28px; background: var(--appbar-line); }
.eyebrow {
  margin: 0;
  font-size: 11px; line-height: 1.15; font-weight: 700; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--appbar-eyebrow);
}
h1 { margin: 2px 0 0; font-size: 18px; line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: var(--space-tight); }
.topbar-right { position: relative; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--pill-bg); border: 1px solid var(--pill-border); border-radius: var(--radius-pill);
  color: var(--on-brand);
  font: 600 13px/1.4 var(--sans); white-space: nowrap;
  cursor: pointer;
  transition: border-color 120ms var(--ease), background 120ms var(--ease);
}
.status-pill:hover, .status-pill[aria-expanded="true"] { border-color: rgba(148, 216, 0, 0.5); background: rgba(255, 255, 255, 0.1); }
.status-pill img { display: block; }

/* Appearance popup under the pill (uses the page theme, like Stockpile's popovers) */
.popover {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 20;
  width: 260px; padding: var(--space-field-row) var(--space-gutter) var(--space-gutter);
  background: linear-gradient(180deg, var(--card-top), var(--card));
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-tile);
  box-shadow: var(--shadow-popover);
}
.popover-label {
  margin: 0 0 var(--space-tight);
  font-size: 12px; font-weight: 600; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--accent);
}
.popover-hint { margin: var(--space-tight) 0 0; font-size: 12px; color: var(--muted); }
.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px;
  padding: 3px; background: var(--input); border: 1px solid var(--line); border-radius: var(--radius-control);
}
.segmented button {
  min-height: 36px; border: 0; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--muted);
  font: 600 14px/1.4 var(--sans);
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--brand-dark); box-shadow: var(--shadow-card); }

.banner {
  padding: var(--space-tight) var(--space-gutter);
  background: var(--warn-bg); color: var(--warn-text);
  border-bottom: 1px solid var(--warn-border);
  font-size: 13px; font-weight: 600;
}

main { max-width: var(--space-content); margin: 0 auto; padding: 20px var(--space-gutter) 48px; }

/* ---------- page heading ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-gutter); margin-bottom: var(--space-card-gap); }
.page-head > div { flex: 1; }
.section-label {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 6px;
  font-size: 12px; line-height: 1.4; font-weight: 600; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--accent);
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.hint { margin: 0; font-size: 13px; font-weight: 500; color: var(--muted); }
.user { margin: 0; color: var(--muted); font-size: 13px; text-align: right; overflow-wrap: anywhere; }

/* ---------- loading / errors ---------- */
.state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 80px var(--space-gutter); color: var(--muted); text-align: center; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--indicator);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- controls ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: var(--space-card-gap); flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1 1 280px; }

input, select, textarea {
  font: 400 16px/1.4 var(--sans);   /* 16px so phones don't zoom */
  color: var(--text);
  background: var(--input);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  padding: var(--space-control-y) var(--space-field-row);
  min-height: var(--space-control);
  width: 100%;
}
input[type="date"], select[name="SendTime"] { font-family: var(--mono); font-weight: 500; }
.toolbar select { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 0;
  background: var(--focus-bg);
}
button:focus-visible, .switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  font: 600 15px/1.4 var(--sans);
  min-height: var(--space-button);
  padding: 0 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-control);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 120ms var(--ease), box-shadow 220ms var(--ease), border-color 120ms var(--ease);
}
.btn:hover { border-color: var(--brand-dark); }
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 88%, #ffffff) 0%, var(--brand) 100%);
  border-color: var(--brand);
  color: var(--on-brand);
}
.btn.primary:hover { box-shadow: 0 4px 14px color-mix(in srgb, var(--brand) 35%, transparent); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: var(--line); }
.btn.danger.ghost:hover { border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn:disabled { background: var(--blocked); border-color: var(--blocked); color: var(--disabled-text); cursor: progress; box-shadow: none; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-control);
  background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer;
}
.icon-btn:hover { background: var(--input); color: var(--text); }
.link {
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
  font: 700 15px/1.4 var(--sans); letter-spacing: -0.01em; color: var(--text);
}
.link:hover { color: var(--link); text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .btn, .spinner { transition: none; animation-duration: 2s; }
  .btn:active { transform: none; }
}

/* ---------- report table (a card) ---------- */
.table-wrap {
  background: linear-gradient(180deg, var(--card-top), var(--card));
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
}
table.reports { width: 100%; border-collapse: collapse; }
.reports th, .reports td { padding: 12px var(--space-gutter); text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.reports th {
  font-size: 11px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap;
}
.reports tbody tr:last-child td { border-bottom: 0; }
.reports tbody tr { transition: background 120ms var(--ease); }
.reports tbody tr:hover { background: color-mix(in srgb, var(--soft-brand) 60%, transparent); }
.reports tr.paused td:not(.col-on):not(.col-actions) { color: var(--muted); }
.reports tr.paused .link { color: var(--muted); }
.col-on { width: 64px; }
.col-actions { width: 1%; white-space: nowrap; text-align: right; }
.col-actions .btn + .btn { margin-left: 4px; }
.num { white-space: nowrap; }  /* next-send time: keep on one line */
.muted { color: var(--muted); font-size: 13px; font-weight: 500; margin-top: 2px; }
.empty { padding: 32px; text-align: center; color: var(--muted); margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.pill { display: inline-block; white-space: nowrap; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; }
.pill.queued { background: var(--ok-bg); color: var(--ok); }

/* Enabled switch */
.switch { position: relative; display: inline-block; width: 40px; height: 24px; cursor: pointer; margin-top: 2px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--blocked); border-radius: var(--radius-pill); transition: background 120ms var(--ease); }
.switch span::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #ffffff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 120ms var(--ease);
}
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--card-border);
  background: linear-gradient(180deg, var(--card-top), var(--card));
  color: var(--text);
  box-shadow: var(--shadow-overlay);
  padding: 0;
}
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }

dialog.panel {
  width: min(580px, 100vw);
  height: 100vh;
  max-height: 100vh;
  margin: 0 0 0 auto;
  border-radius: 0;
  border-width: 0 0 0 1px;
}
dialog.panel form { display: flex; flex-direction: column; height: 100%; }
.panel-head, .panel-foot {
  display: flex; align-items: center; gap: var(--space-tight);
  padding: var(--space-field-row) var(--space-gutter);
  border-bottom: 1px solid var(--line);
}
.panel-foot { border-bottom: 0; border-top: 1px solid var(--line); background: var(--surface); }
.panel-head h2, dialog.modal h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.panel-body { flex: 1; overflow-y: auto; padding: var(--space-gutter); }
.grow { flex: 1; }

dialog.modal { width: min(460px, calc(100vw - 32px)); border-radius: var(--radius-tile); }
dialog.modal form { padding: 20px; }
dialog.modal h2 { margin-bottom: var(--space-tight); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-tight); margin-top: var(--space-gutter); }

fieldset { border: 0; margin: 20px 0 0; padding: 0; }
legend {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 0; margin-bottom: var(--space-field-row);
  font-size: 12px; font-weight: 600; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--accent);
}
legend::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.field { display: flex; flex-direction: column; gap: var(--space-label); margin-bottom: var(--space-field-row); }
.field > span { font-weight: 600; font-size: 13px; }
.field em { font-style: normal; font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 4px; }
.field small { color: var(--muted); font-size: 13px; font-weight: 500; }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0; font-weight: 600; min-height: var(--space-control); cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-field-row) var(--space-gutter); }
.preview {
  margin: 4px 0 0; padding: var(--space-field-row);
  background: var(--soft-brand); color: var(--text);
  border-radius: var(--radius-control); font-size: 13px; font-weight: 500;
}
.meta { color: var(--muted); font-size: 12px; margin: var(--space-field-row) 0 0; }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: var(--radius-control); font-weight: 600; margin: var(--space-field-row) 0 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--on-brand);
  padding: 10px 16px; border-radius: var(--radius-control); box-shadow: var(--shadow-overlay);
  max-width: calc(100vw - 32px); z-index: 10; font-weight: 500;
}
.toast.error { background: var(--danger); }

/* ---------- tablets and phones ---------- */
@media (max-width: 760px) {
  .pill-text { display: none; }          /* logo only on phones, as in Stockpile */
  .status-pill { padding: 5px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .user { text-align: left; }
  .row3 { grid-template-columns: 1fr 1fr; }
  .reports thead { display: none; }
  .reports, .reports tbody, .reports tr, .reports td { display: block; width: 100%; }
  .reports tr { border-bottom: 1px solid var(--line); padding: var(--space-tight) 0; position: relative; }
  .reports tbody tr:last-child { border-bottom: 0; }
  .reports td { border: 0; padding: 4px var(--space-gutter); }
  .reports td.col-on { position: absolute; right: 0; top: var(--space-tight); width: auto; }
  .col-actions { text-align: left; padding-top: var(--space-tight) !important; }
}
@media (max-width: 480px) {
  .row3 { grid-template-columns: 1fr; }
  .eyebrow { display: none; }
}

/* ---------- customer / contract pickers (searchable multi-select) ---------- */
.picker { position: relative; }
.picker-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: var(--space-control);
  padding: 6px var(--space-field-row);
  background: var(--input);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  cursor: text;
}
.picker-box:focus-within { outline: 2px solid var(--brand); background: var(--focus-bg); }
.chips { display: contents; }
.picker-input {
  flex: 1 1 140px; min-width: 120px; min-height: 30px;
  padding: 0; border: 0; background: transparent;
}
.picker-input:focus { outline: none; background: transparent; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  max-width: 100%;
  padding: 3px 4px 3px 10px;
  background: var(--soft-brand); color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600; line-height: 1.3;
  overflow-wrap: anywhere;
}
.chip.warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.chip.warn b { font-weight: 700; }
.chip-x {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; flex: none;
  border: 0; border-radius: 50%;
  background: transparent; color: inherit; font-size: 11px; cursor: pointer;
}
.chip-x:hover { background: color-mix(in srgb, currentColor 15%, transparent); }
.picker-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 280px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none;
  background: linear-gradient(180deg, var(--card-top), var(--card));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-popover);
}
.picker-list li { padding: 8px 10px; border-radius: 6px; }
.picker-list [role="option"] { display: flex; flex-direction: column; gap: 1px; cursor: pointer; }
.picker-list [role="option"] small { color: var(--muted); font-size: 12px; }
.picker-list [role="option"][aria-selected="true"] { background: var(--soft-brand); }
.picker-list [role="option"].free span { color: var(--link); font-weight: 600; }
.picker-list .note { color: var(--muted); font-size: 13px; cursor: default; }
