/* App chrome */
:root {
  /* Defaults (dark) if no preference available) */
  --bg: #0b1220;
  --card: #0f1e2d;
  --border: #1e2a3a;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --accent: #94f3e4;
}

#file-list li .btn { padding: 2px 8px; }

/* Explicit theme overrides via attribute */
html[data-theme="dark"] {
  --bg: #0b1220;
  --card: #0f1e2d;
  --border: #1e2a3a;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --accent: #94f3e4;
}
html[data-theme="light"] {
  --bg: #e5e3d9;
  --card: #efeee8;
  --border: #dfe7ef;
  --text: #343f4f;
  --muted: #475569;
  --accent: #e5e3d9; /* subtle blue accent in light */
}

/* Light mode button overrides */
html[data-theme="light"] .btn {
  background: transparent;
  color: #343f4f;
  border: 1px solid #343f4f;
}
html[data-theme="light"] .btn.primary {
  background: transparent;
  color: #343f4f;
  border: 1px solid #343f4f;
}
html[data-theme="light"] .btn:hover,
html[data-theme="light"] .btn.primary:hover {
  background: #343f4f;
  color: #ffffff;
  border-color: #343f4f;
}

/* Light mode: switch (toggle) knob uses #343f4f */
html[data-theme="light"] .switch .slider::before {
  background: #343f4f;
}
html[data-theme="light"] .switch input:checked + .slider::before {
  background: #343f4f;
}

/* Ensure small list action buttons follow light color */
html[data-theme="light"] #file-list .btn {
  background: transparent;
  color: #343f4f;
  border: 1px solid #343f4f;
}

/* Light mode title styling */
html[data-theme="light"] h1,
html[data-theme="light"] h2 {
  color: #343f4f;
  font-weight: 700;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --card: #f7f9fb;
    --border: #dfe7ef;
    --text: #0f172a;
    --muted: #475569;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--muted);
  font-family: 'Roboto', sans-serif;
  height: 100%;
}

a {
  color: var(--text);
  text-decoration: underline;
}

a:hover,
a:focus {
  color: var(--accent);
}

.app-header, .app-footer {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}
.app-header h1 { margin: 0; }
.app-footer {
  display: none;
}
.subtitle { color: var(--muted); margin-top: 4px; }

/* Main area should fill available height */
.app-main {
  min-height: calc(100vh - 120px); /* header+footer approx height */
  padding: 16px;
}

/* Views: only one is visible at a time */
.view { display: none; }
.view.active { display: block; }

/* Inputs panel */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.row { margin-bottom: 16px; }

.switch-state {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 8px;
  min-width: 40px;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 42px;
  height: 22px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.25s ease;
}
.switch .slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--card);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.25s ease, background 0.25s ease;
}
.switch input:checked + .slider {
  background: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translate(18px, -50%);
  background: #343f4f;
}

.field-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  grid-column: 1 / -1;
  margin-bottom: -4px;
}

.field-switch label {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  margin: 0;
}

.field-switch .switch {
  margin: 0;
}


.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 800px) {
  .grid { grid-template-columns: 1fr; }
}

.field label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.field label .note { color: var(--muted); font-style: italic; font-size: 0.85rem; }
.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

/* Prevent background color changes on focus/typing/validation/autofill */
.field input:focus,
.field input:active,
.field input:valid,
.field input:invalid {
  background: transparent !important;
  outline: none;
}
/* Firefox invalid UI background override */
.field input:-moz-ui-invalid {
  box-shadow: none;
  background: transparent !important;
}
/* Chrome autofill background override */
.field input:-webkit-autofill,
.field input:-webkit-autofill:hover,
.field input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px transparent inset;
  box-shadow: 0 0 0px 1000px transparent inset;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
}

.files {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
#file-list {
  margin: 0;
  padding-left: 16px;
  list-style: disc;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: var(--accent);
  color: #000;
  border: none;
}
.btn.small {
  padding: 6px 10px;
  font-size: 0.85rem;
}
.field-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.field-input:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

.print-btn {
  border: 1px solid var(--border);
  background: var(--accent);
  color: #000;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}
.print-btn:hover {
  border-color: var(--accent);
}

html[data-theme="light"] .print-btn {
  background: #343f4f;
  color: #fff;
  border: none;
}

.actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.muted { color: var(--muted); }
.btn.muted {
  color: var(--muted);
  border-color: var(--border);
}
.btn.muted:hover {
  color: var(--text);
  border-color: var(--accent);
}

.privacy-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.privacy-overlay.visible {
  display: flex;
}
.privacy-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.privacy-modal {
  position: relative;
  width: min(720px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card);
  color: var(--text);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.privacy-modal__header {
  position: relative;
}
.privacy-modal__body {
  font-size: 0.95rem;
  line-height: 1.5;
  max-height: 55vh;
  overflow-y: auto;
}
.privacy-modal__body h1,
.privacy-modal__body h2,
.privacy-modal__body h3 {
  color: var(--accent);
}
.privacy-modal__body p:last-child {
  margin-bottom: 0;
}
.privacy-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}
.modal-close {
  position: absolute;
  top: -6px;
  left: -6px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover,
.modal-close:focus {
  color: var(--accent);
}
body.privacy-locked {
  overflow: hidden;
}

/* Report view (full page) */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

/* Brand logos */
.brand {
  height: 36px;
  width: auto;
  border-radius: 8px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 10px;
}
/* Theme-specific logos: blue logo on dark background, noir logo on light */
html[data-theme="dark"] .brand-dark { display: inline; }
html[data-theme="dark"] .brand-light { display: none; }
html[data-theme="light"] .brand-dark { display: none; }
html[data-theme="light"] .brand-light { display: inline; }
.admin-link {
  position: absolute;
  top: 12px;
  right: 20px;
  font-size: 1.5rem;
  text-decoration: none;
  color: var(--muted);
  line-height: 1;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.2s ease, background 0.2s ease;
}
.admin-link:hover {
  color: var(--accent);
  background: rgba(148, 243, 228, 0.12);
}
.admin-link:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media print {
  .admin-link { display: none !important; }
}
.admin-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 12px;
  width: 100%;
}
.admin-panel + .admin-panel {
  margin-top: 16px;
}
.admin-panel h2 {
  margin-top: 0;
}
.admin-login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 360px;
}
.admin-login-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-login-actions .btn.primary {
  flex: 0 0 auto;
}
.admin-summary-metric {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 1.15rem;
  font-weight: 600;
}
.admin-summary-metric span {
  font-size: 2.4rem;
  color: var(--accent);
  font-weight: 700;
}
.admin-table table {
  width: 100%;
  border-collapse: collapse;
}
.admin-table {
  overflow-x: auto;
}
.admin-table table {
  min-width: 860px;
}
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 0.95rem;
}
.admin-table tbody tr:hover {
  background: rgba(148, 243, 228, 0.08);
}
.admin-table .files-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}
.admin-table .files-list li {
  margin-bottom: 4px;
}
.admin-upload-actions {
  margin-bottom: 6px;
}
.admin-email-list {
  margin: 0;
  padding-left: 18px;
}
.admin-email-list li {
  margin-bottom: 4px;
}
.email-meta {
  font-size: 0.8rem;
}
.admin-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.report-frame {
  width: 100%;
  height: calc(100vh - 200px); /* fill the page below toolbar/header/footer */
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--card); /* match dark theme background */
}

/* Report template styles */
body.report-doc {
  line-height: 1.45;
  padding: 16px;
}
.report-doc h2 { text-align: left; }
.container { max-width: 1100px; margin: 0 auto; }
h1, h2 { color: var(--accent); }
.card { background: var(--card); border:1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 14px; }
.card-title { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.note-right { color: var(--muted); font-style: italic; font-size: 0.9rem; }
.charts img { display:block; width:100%; height:auto; border-radius:12px; background:#fff; }
.charts canvas { display:block; max-width:100%; }
.charts { clear: both; }
.charts-two .card { overflow:hidden; }
#chart-roi,
#chart-payback { width:100%; }
/* Size and center specific Appendix charts (image fallbacks and canvases) */
.charts img[alt="Task Counts (Combined)"],
.charts img[alt="Monthly Cost Comparison"] {
  width: 85%;
  max-width: 1000px;
  margin: 12px auto;
}
.charts #chart-counts,
.charts #chart-costs {
  display: block;
  width: 85%;
  margin: 12px auto;
}
.charts-two { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap:14px; }
/* Keep charts side-by-side on most screens; stack only on smaller widths */
@media (max-width: 700px) { .charts-two { grid-template-columns: 1fr; } }
.charts h2 { text-align: left; clear: both; }
.chart-legend { display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
.kpi-grid { display:grid; gap:12px; margin:16px 0 20px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpi-sub { color: var(--muted); font-size: 0.9rem; margin-top: 6px; }
/* In multi-scenario mode, we show pre-rendered PNGs and should hide canvases */
/* Previously hid canvases in multi-scenario mode; now we render them dynamically */

/* Hide legacy field if present */
label[for="process_monthly_cost"],
#process_monthly_cost,
.field:has(#process_monthly_cost) { display: none !important; }
.table-wrap { overflow-x:auto; -webkit-overflow-scrolling: touch; }
table { width:100%; border-collapse: collapse; min-width: 500px; }
th, td { border-bottom: 1px solid var(--border); padding: 10px 8px; text-align:left; }
th { color: var(--accent); font-weight:600; }
/* Light mode: table column headers should be dark */
html[data-theme="light"] th { color: #343f4f; }
@media print { .card { page-break-inside: avoid; } button { display:none; } }
.admin-link.inline {
  position: static;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  line-height: 1;
}
