@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: only light; /* app is light-themed; prevent Chromium auto-dark-mode */

  /* EFI Brand Colours */
  --efi-navy:       #000033;
  --efi-cyan:       #00AEEF;
  --efi-cyan-dark:  #0090C7;
  --efi-cyan-light: #e0f6fd;

  /* Semantic aliases */
  --bg:           #f2f4f7;
  --surface:      #ffffff;
  --border:       #dde1e7;
  --primary:      var(--efi-cyan);
  --primary-dark: var(--efi-cyan-dark);
  --primary-light: var(--efi-cyan-light);
  --success:      #0e7c3a;
  --success-bg:   #d1fae5;
  --text:         #0d0f1a;
  --text-muted:   #5a6270;
  --highlight:         var(--efi-cyan);
  --highlight-hover:   var(--efi-cyan-dark);
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,51,0.07), 0 2px 12px rgba(0,0,51,0.04);
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---- Header ---- */
header {
  background: var(--efi-navy);
  padding: 0 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  height: 56px;
}
.header-content {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
}

/* Broken-box motif — simplified CSS version of the EFI brand shape */
.header-broken-box {
  width: 28px;
  height: 28px;
  position: relative;
  flex-shrink: 0;
  margin-right: 12px;
}
.header-broken-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 18px; height: 18px;
  border-top: 2.5px solid #fff;
  border-left: 2.5px solid #fff;
}
.header-broken-box::after {
  content: '';
  position: absolute;
  bottom: 0; right: 0;
  width: 18px; height: 18px;
  border-bottom: 2.5px solid var(--efi-cyan);
  border-right: 2.5px solid var(--efi-cyan);
}

.header-wordmark { line-height: 1.1; }
.header-wordmark .brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--efi-cyan);
  letter-spacing: 0.01em;
  display: block;
}
.header-wordmark .brand-sub {
  font-size: 11px;
  font-weight: 300;
  color: rgba(255,255,255,0.75);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: block;
}
.header-right {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}
.header-tool-name {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#app-version {
  font-size: 10px;
  font-weight: 400;
  color: var(--efi-cyan);
  letter-spacing: 0.03em;
  opacity: 0.85;
}

main {
  flex: 1;
  overflow: hidden;   /* each step manages its own scrolling */
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Every step fills the remaining height so buttons are never off-screen */
.step-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Steps 1 & 3 are short panels — allow outer scroll on small windows */
#step-1, #step-3 { overflow-y: auto; }

/* Renewal email steps scroll independently */
#re-step-1, #re-step-2, #re-step-3 { overflow-y: auto; }

/* Claims Tracker is a single scrolling view, not stepped — its content
   (settings panel + error bar + claim list) can easily exceed the window
   height, so it needs the same explicit opt-in as every other section. */
#claims-view { overflow-y: auto; }

/* ---- Steps indicator ---- */
.steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.step {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.38;
  transition: opacity 0.2s;
}
.step.active  { opacity: 1; }
.step.completed { opacity: 0.65; }
.step-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  transition: background 0.2s, color 0.2s;
}
.step.active .step-num    { background: var(--efi-navy); color: var(--efi-cyan); }
.step.completed .step-num { background: var(--efi-cyan); color: #fff; }
.step-label { font-size: 13px; font-weight: 500; }
.step-line  { flex: 1; height: 2px; background: var(--border); min-width: 32px; max-width: 80px; }

/* ---- Panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Panel headings with EFI broken-box corner motif */
h2 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--efi-navy);
  padding-left: 14px;
  position: relative;
}
h2::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 8px; height: 8px;
  border-top: 2px solid var(--efi-cyan);
  border-left: 2px solid var(--efi-cyan);
}
h2::after {
  content: '';
  position: absolute;
  left: 0; bottom: -2px;
  width: 8px; height: 8px;
  border-bottom: 2px solid var(--efi-navy);
  border-left: 2px solid var(--efi-navy);
}

h3 { font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.hint { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.file-info {
  background: var(--efi-cyan-light);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--efi-cyan-dark);
  margin-bottom: 10px;
  word-break: break-all;
  border-left: 3px solid var(--efi-cyan);
}
.file-info .filename { font-weight: 600; }

.fields-preview { margin-top: 12px; max-height: 200px; overflow-y: auto; }
.fields-preview ul { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.fields-preview li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
}

label { font-size: 13px; font-weight: 500; margin-bottom: 4px; display: block; }
select, input[type="text"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, input[type="text"]:focus {
  border-color: var(--efi-cyan);
  box-shadow: 0 0 0 3px rgba(0,174,239,0.15);
}

#sheet-selector-wrap { margin-top: 12px; }
.row-count { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

.step-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  flex-shrink: 0;   /* always visible — never pushed off screen */
}

/* ---- Buttons ---- */
.btn {
  padding: 8px 18px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.02em;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--efi-navy); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #00005a; box-shadow: 0 2px 8px rgba(0,0,51,0.2); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); border-color: var(--efi-cyan); color: var(--efi-navy); }
.btn-success {
  background: var(--efi-cyan);
  color: #fff;
  padding: 10px 28px;
  font-size: 14px;
}
.btn-success:hover:not(:disabled) { background: var(--efi-cyan-dark); }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ---- Mapping layout ---- */
.mapping-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: 1fr;  /* force the single row to fill available height */
  gap: 16px;
  flex: 1;
  min-height: 0;
}
.pdf-preview-panel, .mapping-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#pdf-viewer-container {
  flex: 1;
  overflow: auto;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #6b7280;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 0;
}
#pdf-canvas { display: block; }
#field-overlays { position: absolute; top: 0; left: 0; pointer-events: none; }

.field-overlay {
  position: absolute;
  border: 2px solid var(--efi-cyan);
  background: rgba(0,174,239,0.15);
  border-radius: 3px;
  cursor: pointer;
  pointer-events: all;
  transition: background 0.15s, border-color 0.15s;
}
.field-overlay:hover { background: rgba(0,174,239,0.30); }

.field-tooltip {
  position: absolute;
  bottom: calc(100% + 3px);
  left: 0;
  background: #1a1d23;
  color: #fff;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.1s;
}
.field-overlay:hover .field-tooltip,
.field-overlay.selected .field-tooltip { opacity: 1; }
.field-overlay.selected {
  border-color: var(--efi-navy);
  background: rgba(0,0,51,0.14);
}
.field-overlay.mapped {
  border-color: var(--success);
  background: rgba(14,124,58,0.12);
}

.pdf-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 10px;
  flex-shrink: 0;
}
#page-indicator { font-size: 12px; color: var(--text-muted); }

#mapping-table-container { flex: 1; overflow-y: auto; min-height: 0; margin-bottom: 12px; }
#mapping-table { width: 100%; border-collapse: collapse; }
#mapping-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 8px;
  border-bottom: 2px solid var(--efi-cyan);
  position: sticky;
  top: 0;
  background: var(--surface);
}
#mapping-table td { padding: 5px 8px; border-bottom: 1px solid var(--bg); vertical-align: middle; }
#mapping-table tr.row-selected td { background: var(--efi-cyan-light); }
.field-name-cell {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-name-cell .field-type {
  font-family: 'Roboto', sans-serif;
  font-size: 10px;
  color: var(--text-muted);
  display: block;
}
#mapping-table select { width: 100%; padding: 4px 6px; font-size: 12px; }

/* Filename config */
.filename-config { border-top: 1px solid var(--border); padding-top: 12px; flex-shrink: 0; }
.filename-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.filename-row input { flex: 1; min-width: 80px; }
.filename-row select { flex: 2; }
.filename-ext { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.filename-preview { font-size: 11px; color: var(--text-muted); margin-top: 4px; font-style: italic; }

/* Generate step */
.generate-panel { max-width: 600px; margin: 0 auto; }
.summary-box {
  background: var(--efi-navy);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 16px;
  font-size: 13px;
  line-height: 1.9;
  color: rgba(255,255,255,0.82);
}
.summary-box strong { color: var(--efi-cyan); font-weight: 600; }
.output-dir-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.output-dir-row label { flex-shrink: 0; }
.output-dir-display {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gen-actions { display: flex; gap: 10px; margin-bottom: 16px; }

.progress-bar-outer {
  background: var(--border);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-bar-inner {
  height: 100%;
  background: var(--efi-cyan);
  border-radius: 99px;
  width: 0%;
  transition: width 0.2s;
}
.progress-label { font-size: 12px; color: var(--text-muted); }

.gen-result {
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  margin-top: 12px;
}
.gen-result.success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #6ee7b7;
}
.gen-result.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.hidden { display: none !important; }

/* ---- Home / Landing page ---- */
.home-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.home-greeting {
  margin-bottom: 32px;
}

.home-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--efi-navy);
  margin-bottom: 5px;
  padding-left: 0;  /* override h2 rule */
}
.home-title::before, .home-title::after { display: none; } /* no broken-box on h1 */

.home-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 192px);
  gap: 20px;
}

.tool-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 28px 20px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.15s;
}
.tool-card:hover {
  border-color: var(--efi-cyan);
  box-shadow: 0 6px 24px rgba(0, 174, 239, 0.15);
  transform: translateY(-2px);
}
.tool-card:active { transform: translateY(0); }

.tool-card-icon {
  width: 52px;
  height: 52px;
  color: var(--efi-navy);
  transition: color 0.18s;
}
.tool-card:hover .tool-card-icon { color: var(--efi-cyan); }

.tool-card-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--efi-navy);
  line-height: 1.2;
}

.tool-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---- Breadcrumb ---- */
.tool-breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.btn-breadcrumb-home {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  color: var(--efi-cyan);
  cursor: pointer;
  line-height: 1;
}
.btn-breadcrumb-home:hover { text-decoration: underline; }

.breadcrumb-sep {
  font-size: 15px;
  color: var(--border);
  line-height: 1;
}

.breadcrumb-tool {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

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

/* ---- Help button (header) ---- */
.btn-help {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.8);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 16px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.btn-help:hover { background: var(--efi-cyan); color: #fff; border-color: var(--efi-cyan); }

/* ---- Help page ---- */
#help { overflow-y: auto; }
.help-page { max-width: 900px; padding-bottom: 32px; }

.help-hero {
  margin-bottom: 24px;
}
.help-hero-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--efi-navy);
  margin-bottom: 6px;
  padding-left: 0;
}
.help-hero-title::before, .help-hero-title::after { display: none; }
.help-hero-sub { font-size: 13px; color: var(--text-muted); }

/* numbered step cards */
.help-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.help-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 14px;
}
.help-card-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--efi-navy);
  color: var(--efi-cyan);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-card-body h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--efi-navy);
  margin-bottom: 8px;
  padding-left: 0;
}
.help-card-body h3::before, .help-card-body h3::after { display: none; }
.help-card-body p { font-size: 12px; color: var(--text); line-height: 1.6; margin-bottom: 8px; }
.help-card-body p:last-child { margin-bottom: 0; }
.help-card-body code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}
.help-tip {
  background: var(--efi-cyan-light);
  border-left: 3px solid var(--efi-cyan);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--efi-cyan-dark);
  line-height: 1.5;
  margin-top: 8px;
}

/* templates + tips sections */
.help-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.help-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--efi-navy);
  margin-bottom: 6px;
  padding-left: 0;
}
.help-section-title::before, .help-section-title::after { display: none; }
.help-section-intro { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6; }
.help-section-intro code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}

.help-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.help-col h4 { font-size: 12px; font-weight: 700; color: var(--efi-navy); margin-bottom: 8px; }
.help-ol { list-style: decimal; padding-left: 16px; }
.help-ol li { font-size: 12px; color: var(--text); line-height: 1.7; }
.help-ol li strong { color: var(--efi-navy); }
.help-ol code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}

.help-tips-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.help-tips-list li {
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
  padding-left: 16px;
  position: relative;
}
.help-tips-list li::before {
  content: '›';
  position: absolute;
  left: 0;
  color: var(--efi-cyan);
  font-weight: 700;
}
.help-tips-list code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}

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

/* ---- Tool entry wrapper (card + footer link) ---- */
.tool-entry {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.tool-entry-footer { text-align: center; }
.btn-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  font-family: inherit;
  color: var(--efi-cyan);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-link:hover { color: var(--efi-cyan-dark); }

/* ---- Danger button ---- */
.btn-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}
.btn-danger:hover:not(:disabled) { background: #fecaca; }

/* ---- Template loader panel (step 1) ---- */
.tpl-loader-panel {
  margin-bottom: 12px;
  padding: 12px 16px;
  flex-shrink: 0;
}
.tpl-loader-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.tpl-loader-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.tpl-loader-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--efi-navy);
}
.tpl-applied-name {
  font-size: 12px;
  background: var(--efi-cyan-light);
  color: var(--efi-cyan-dark);
  border: 1px solid var(--efi-cyan);
  border-radius: 4px;
  padding: 2px 8px;
}
.tpl-loader-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tpl-select { min-width: 200px; max-width: 300px; width: auto; }

/* ---- Template manager ---- */
#templates { overflow-y: auto; }
.tpl-manager-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.tpl-manager-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--efi-navy);
  margin-bottom: 0;
  padding-left: 0;
}
.tpl-manager-title::before, .tpl-manager-title::after { display: none; }
.tpl-manager-dir { font-size: 12px; color: var(--text-muted); word-break: break-all; }

/* Folder path row */
.tpl-path-row {
  margin-bottom: 14px;
  flex-shrink: 0;
  padding: 14px 16px;
}
.tpl-path-row label { margin-bottom: 2px; }
.tpl-path-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tpl-path-input-group input { flex: 1; min-width: 0; }

.tpl-empty-panel {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.8;
}

/* ---- Template list ---- */
#tpl-list-panel { flex: 1; min-height: 0; overflow-y: auto; }
.tpl-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  align-content: start;
}
.tpl-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tpl-card-name { font-size: 14px; font-weight: 700; color: var(--efi-navy); }
.tpl-card-meta { font-size: 11px; color: var(--text-muted); line-height: 1.7; word-break: break-all; }
.tpl-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tpl-card-actions .tpl-use-btn { flex: 1 0 100%; }
.tpl-card-actions .tpl-delete-btn { margin-left: auto; }

/* ---- Template header mismatch warning ---- */
.tpl-mismatch-warning {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-left: 3px solid #f59e0b;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  color: #92400e;
  line-height: 1.6;
  margin-bottom: 8px;
}
.tpl-mismatch-warning code {
  background: rgba(0,0,0,0.07);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}

/* ---- Template save row ---- */
.tpl-save-row {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 8px;
  flex-shrink: 0;
}
.tpl-save-row label { margin-bottom: 6px; }
.tpl-save-error { color: #991b1b !important; margin-top: 6px; margin-bottom: 0; }

/* ---- Template builder PDF viewer ---- */
#tpl-pdf-viewer-container {
  flex: 1;
  overflow: auto;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #6b7280;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 0;
}
#tpl-pdf-canvas { display: block; }
#tpl-field-overlays { position: absolute; top: 0; left: 0; pointer-events: none; }
#tpl-page-indicator { font-size: 12px; color: var(--text-muted); }

/* ---- Template builder mapping table ---- */
#tpl-mapping-table-container { flex: 1; overflow-y: auto; min-height: 0; margin-bottom: 12px; }
#tpl-mapping-table { width: 100%; border-collapse: collapse; }
#tpl-mapping-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 8px;
  border-bottom: 2px solid var(--efi-cyan);
  position: sticky;
  top: 0;
  background: var(--surface);
}
#tpl-mapping-table td { padding: 5px 8px; border-bottom: 1px solid var(--bg); vertical-align: middle; }
#tpl-mapping-table tr.row-selected td { background: var(--efi-cyan-light); }
#tpl-mapping-table select { width: 100%; padding: 4px 6px; font-size: 12px; }

/* ===========================================================
   Renewal Emails module
   =========================================================== */

/* Config layout */
.re-path-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.re-path-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.re-path-value {
  font-size: 12px;
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  word-break: break-all;
}
.re-field-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.re-field-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.re-text-input {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-primary);
  box-sizing: border-box;
}
.re-text-input:focus { outline: 2px solid var(--efi-cyan); border-color: transparent; }
.re-checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.re-checkbox-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; }

/* Advanced column config */
.re-advanced-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  margin-top: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}
.re-advanced-toggle:hover { border-color: var(--efi-cyan); color: var(--efi-cyan); }
.re-chevron { font-size: 10px; transition: transform 0.15s; }
.re-chevron.open { transform: rotate(90deg); }
.re-cols-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 10px;
  padding: 12px 0 4px;
  font-size: 12px;
}
.re-col-input {
  width: 60px;
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-primary);
  text-transform: uppercase;
}
.re-col-input:focus { outline: 2px solid var(--efi-cyan); border-color: transparent; }

/* Match error / hint */
.re-match-hint { font-size: 12px; color: var(--text-muted); }

/* Summary bar */
.re-summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.re-stat { display: flex; align-items: center; gap: 5px; }
.re-stat-val { font-weight: 700; color: var(--efi-navy); }
.re-stat-warn { color: #d97706; }
.re-stat-ok   { color: #059669; }

/* Report toolbar */
.re-report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

/* Match report table */
.re-table-scroll { overflow-x: auto; }
.re-report-table {
  width: 100%;
  min-width: 800px;
  border-collapse: collapse;
  font-size: 12px;
}
.re-report-table th {
  text-align: left;
  padding: 6px 8px;
  background: var(--bg);
  border-bottom: 2px solid var(--efi-cyan);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.re-report-table td { padding: 5px 8px; border-bottom: 1px solid var(--bg); vertical-align: top; background: #ffffff; color: var(--text); }
.re-report-table tr:hover td { background: var(--bg); }
.re-report-table tr.re-row-issue td { background: #fff7ed; color: var(--text); }
.re-report-table tr.re-row-issue:hover td { background: #ffedd5; }
.re-pdf-ok   { color: #059669; font-size: 11px; word-break: break-all; }
.re-pdf-miss { color: #dc2626; font-size: 11px; font-weight: 600; }

/* Done summary */
#re-done-summary h2 { margin: 0 0 12px; }
.re-done-stat { font-size: 13px; margin: 4px 0; }

/* Attachment list */
.re-attachment-list { display: flex; flex-direction: column; gap: 4px; }
.re-attachment-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px;
  background: var(--bg); border-radius: 4px; font-size: 12px;
}
.re-attachment-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.re-attachment-remove {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; line-height: 1; padding: 0 2px;
}
.re-attachment-remove:hover { color: #dc2626; }

/* ---- Renewal Emails – email template editor ---- */
.re-editor-panel { margin-top: 16px; }

/* Toolbar */
.re-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.re-toolbar-group { display: flex; align-items: center; gap: 3px; }
.re-toolbar-sep-v { width: 1px; height: 20px; background: var(--border); margin: 0 3px; flex-shrink: 0; }
.re-toolbar-section-label { font-size: 11px; font-weight: 600; color: var(--text-muted); white-space: nowrap; margin-right: 2px; }

/* Placeholder insert buttons */
.re-ph-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
  border: 1px solid var(--efi-cyan);
  background: var(--efi-cyan-light);
  color: var(--efi-navy);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}
.re-ph-btn:hover { background: var(--efi-cyan); color: #fff; }

/* Formatting buttons */
.re-fmt-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-primary);
  line-height: 1;
  min-width: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.re-fmt-btn:hover   { background: var(--surface); border-color: var(--border); }
.re-fmt-btn.active  { background: var(--efi-cyan-light); border-color: var(--efi-cyan); color: var(--efi-navy); }
.re-fmt-btn svg     { display: block; }

/* Font / size selects */
.re-toolbar-select {
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
}
.re-font-sel { max-width: 120px; }
.re-size-sel { width: 52px; }

/* Colour picker */
.re-color-label {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  min-width: 26px;
}
.re-color-label:hover { background: var(--surface); border-color: var(--border); }
.re-color-letter { font-size: 13px; font-weight: 700; line-height: 1; color: var(--text-primary); }
.re-color-swatch {
  display: block;
  width: 14px;
  height: 3px;
  border-radius: 1px;
  background: #000;
  margin-top: 2px;
}
.re-color-label input[type="color"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* The editor area itself */
.re-editor {
  min-height: 280px;
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 14px 18px;
  outline: none;
  font-family: Aptos, Calibri, Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--surface);
}
.re-editor:focus { border-color: var(--efi-cyan); }
.re-editor p     { margin: 0 0 8px; }
.re-editor img   { max-width: 100%; height: auto; }

/* Placeholder chips inside the editor */
.re-editor .re-ph {
  display: inline-block;
  background: #e0f5ff;
  border: 1px solid var(--efi-cyan);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  color: var(--efi-navy);
  white-space: nowrap;
  cursor: default;
  user-select: none;
}

@media (prefers-color-scheme: dark) {
  .re-editor .re-ph { background: #003d55; border-color: var(--efi-cyan); color: #7dd8f7; }
}

/* ===========================================================
   Claims Tracker module
   =========================================================== */

.claims-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.claims-api-key-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.claims-key-status { font-size: 12px; font-weight: 600; }
.claims-key-status.ok { color: #059669; }
.claims-key-status.missing { color: #dc2626; }

.claims-log {
  max-height: 160px;
  overflow-y: auto;
  margin-top: 8px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  background: var(--bg);
  border-radius: 4px;
  padding: 6px 8px;
}
.claims-log-line { padding: 1px 0; color: var(--text-primary); }
.claims-log-line.error { color: #dc2626; }

.claims-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.claims-empty { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

.claims-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.claims-row-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
}
.claims-row-summary:hover { background: var(--bg); }
.claims-urgency { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.claims-urgency-low    { background: #059669; }
.claims-urgency-medium { background: #d97706; }
.claims-urgency-high   { background: #dc2626; }
.claims-ref { font-weight: 700; color: var(--efi-navy); white-space: nowrap; }
.claims-status { flex: 1; font-size: 13px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.claims-waiting { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.claims-staleness { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.claims-row-detail {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 13px;
}
.claims-row-detail p { margin: 4px 0; }
.claims-attachments { margin-top: 8px; }
.claims-attachment-meta { flex-shrink: 0; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.claims-attachment-open { flex-shrink: 0; font-size: 12px; }
.claims-attachment-badge { flex-shrink: 0; font-size: 11px; font-style: italic; color: var(--text-muted); white-space: nowrap; }

/* ===========================================================
   SAR Redaction Review module
   =========================================================== */

#sar-view { overflow-y: auto; }

.sar-approved-preview { margin-top: 8px; font-size: 12px; }
.sar-approved-preview .sar-preview-entry { padding: 2px 0; }
.sar-approved-preview .sar-preview-error { color: #991b1b; }

.sar-review-body {
  margin-top: 8px;
  padding: 16px 20px;
  font-size: 14px;
  line-height: 1.6;
  max-height: 42vh;
  overflow-y: auto;
  user-select: text;
}
.sar-review-body p { margin: 0 0 10px; }

/* One shared background per entity type so a reviewer recognises a category
   at a glance across items — deliberately not tied to confirm/reject state,
   which is instead shown via border style (see sar-status-*). */
mark.sar-span {
  padding: 1px 2px;
  border-radius: 3px;
  cursor: pointer;
  background: #fde68a;
}
mark.sar-span.sar-entity-PERSON            { background: #fde68a; }
mark.sar-span.sar-entity-EMAIL_ADDRESS      { background: #bfdbfe; }
mark.sar-span.sar-entity-PHONE_NUMBER       { background: #bfdbfe; }
mark.sar-span.sar-entity-LOCATION           { background: #c7f9cc; }
mark.sar-span.sar-entity-DATE_TIME          { background: #e5e7eb; }
mark.sar-span.sar-entity-UK_POSTCODE        { background: #c7f9cc; }
mark.sar-span.sar-entity-UK_NI_NUMBER       { background: #fecaca; }
mark.sar-span.sar-entity-UK_NHS_NUMBER      { background: #fecaca; }
mark.sar-span.sar-entity-UK_SORT_CODE       { background: #fbcfe8; }
mark.sar-span.sar-entity-UK_VEHICLE_REG     { background: #ddd6fe; }
mark.sar-span.sar-entity-POLICY_REFERENCE   { background: #fed7aa; }
mark.sar-span.sar-entity-MANUAL             { background: #fca5a5; }

mark.sar-span.sar-status-confirmed { outline: 2px solid #dc2626; }
mark.sar-span.sar-status-pending   { outline: 1px solid rgba(0,0,0,0.15); }

/* Rejected (includes auto-suppressed approved-list matches): "revealed" full
   detail keeps this entity type's own colour, faded, with a dashed outline
   — for closely inspecting one specific span. The higher-specificity
   `.sar-mute-suppressed` override below (the default state) replaces that
   with a flat, uniform light-grey background instead — deliberately not
   colour-coded per entity type, so a reviewer can scan a whole item and
   immediately see everything already handled ("approved, double-check me")
   without needing to toggle anything on first. Never `display:none` in
   either state — that would take the underlying text out of view with it,
   not just the mark; the span stays in the DOM (still clickable to
   re-flag) with its text always visible. */
mark.sar-span.sar-status-rejected { opacity: 0.45; outline: 1px dashed #9ca3af; }
.sar-mute-suppressed mark.sar-span.sar-status-rejected {
  background: #e2e4e9;
  outline: none;
  opacity: 1;
  padding: 1px 2px;
  border-radius: 3px;
}

.sar-match-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  margin-right: 8px;
}
.sar-match-all_approved  { background: #d1fae5; color: #065f46; }
.sar-match-mixed         { background: #fef3c7; color: #92400e; }
.sar-match-none_approved { background: #fee2e2; color: #991b1b; }
.sar-match-ambiguous     { background: #e5e7eb; color: #374151; }

.sar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,51,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.sar-overlay-box { max-width: 420px; width: 100%; }
.sar-shortcuts-list { list-style: none; margin: 12px 0; }
.sar-shortcuts-list li { padding: 4px 0; font-size: 13px; }
.sar-shortcuts-list kbd {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: 'Courier New', monospace;
  margin-right: 6px;
}

.sar-case-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.sar-case-row-name { font-weight: 700; color: var(--efi-navy); flex: 1; }
.sar-case-row-path { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }

.sar-btn-active { outline: 3px solid var(--efi-navy); outline-offset: 1px; }

/* Review screen two-column layout — sidebar is toggled via a `.hidden` class
   on #sar-review-sidebar (not a width collapse) so its content doesn't stay
   laid out off-screen while hidden. */
.sar-review-layout.sar-review-layout { display: flex; gap: 16px; align-items: flex-start; }
#sar-review-main { flex: 1; min-width: 0; }
.sar-review-sidebar {
  width: 320px;
  flex-shrink: 0;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  position: sticky;
  top: 0;
}
.sar-sidebar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.sar-sidebar-legend span { display: inline-flex; align-items: center; gap: 4px; }

.sar-status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.sar-status-dot-unreviewed { background: #9ca3af; }
.sar-status-dot-included   { background: #059669; }
.sar-status-dot-partial    { background: #d97706; }
.sar-status-dot-whole      { background: #dc2626; }

.sar-sidebar-list { display: flex; flex-direction: column; gap: 2px; }
.sar-sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  background: none;
  border: none;
  width: 100%;
}
.sar-sidebar-item:hover { background: var(--bg); }
.sar-sidebar-item.sar-sidebar-item-current { background: var(--efi-cyan-light); font-weight: 700; }
.sar-sidebar-item-no { width: 42px; flex-shrink: 0; color: var(--text-muted); }
.sar-sidebar-item-subject { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sar-sidebar-item-stale { color: #d97706; flex-shrink: 0; }
