:root {
  /* Tartesia corporate palette (docs/estilos.txt): green #A3D907, grey #273539, light grey #F4F7F9, red #EF4444.
     The green is too light for text on white, so it is used for fills, borders and focus; text stays grey. */
  --bg: #F4F7F9;
  --surface: #ffffff;
  --surface-2: #F9FBFC;
  --border: #DDE4E8;
  --text: #273539;
  --muted: #5E6D72;
  --accent: #A3D907;          /* fills, borders, focus */
  --accent-hover: #93C406;
  --accent-soft: #F1F9D9;     /* light green tint */
  --accent-text: #273539;     /* text on green */
  --danger: #EF4444;          /* "supera umbral": borders and large text */
  --danger-bg: #FDECEC; --danger-fg: #C62828;   /* small text needs a darker red to be readable */
  --warn-bg: #FFF4E0;   --warn-fg: #A35A00;
  --info-bg: #EAF1F4;   --info-fg: #2F5866;
  --ok-bg: #F1F9D9;     --ok-fg: #4A6400;      /* dark olive from the brand green, readable on light */
  --neutral-bg: #EDF1F3; --neutral-fg: #4A585D;
  --radius: 10px;
  color-scheme: light;  /* light only: the logo is dark grey and the corporate palette is light */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 3px solid var(--accent);
}
.topbar-left { display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 16px; }
.brand-logo { display: block; height: 36px; width: auto; }
.brand-name { padding-left: 12px; border-left: 1px solid var(--border); line-height: 24px; letter-spacing: .01em; }
.nav { display: flex; gap: 4px; }
.nav a {
  color: var(--muted); text-decoration: none; font-weight: 500; padding: 6px 10px; border-radius: 8px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--text); background: var(--accent-soft); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w, 420px); min-height: 0; }

/* drag handle on the panel's left edge */
.resizer {
  position: absolute; top: 0; bottom: 0; left: -4px; width: 8px; z-index: 5;
  cursor: col-resize; touch-action: none;
}
.resizer::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px;
  background: transparent; transition: background .15s;
}
.resizer:hover::after, .resizer:focus-visible::after, body.resizing .resizer::after { background: var(--accent); }
.resizer:focus-visible { outline: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe { pointer-events: none; } /* the PDF iframe would swallow the drag */

.viewer { position: relative; min-height: 0; padding: 16px; display: flex; }
.viewer iframe { flex: 1; width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.dropzone {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--muted); cursor: pointer; text-align: center; padding: 24px;
  transition: border-color .15s, background .15s;
}
.dropzone strong { color: var(--text); font-size: 16px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.dz-icon { color: var(--accent); margin-bottom: 6px; }

.panel {
  position: relative;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head { padding: 16px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.result { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 16px; align-content: start; }

.btn {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 14px; cursor: pointer;
  border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); font-weight: 500; padding: 6px 10px; }
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent); }
a.btn { text-decoration: none; }
.btn.download { justify-self: start; }

.status { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.status.error { color: var(--danger-fg); }
.status.done { color: var(--ok-fg); }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface-2); }
.card h2 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.vehicle-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-all; }
.cost { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.flags { display: grid; grid-template-columns: 1fr; gap: 10px; }
.flag { border-radius: 8px; padding: 10px; font-weight: 600; display: grid; gap: 2px; }
.flag small { font-weight: 400; font-size: 12px; opacity: .85; }
.flag.yes { background: var(--danger-bg); color: var(--danger-fg); }
.flag.no { background: var(--neutral-bg); color: var(--neutral-fg); }

.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.chip.SUSTITUIDA { background: var(--danger-bg); color: var(--danger-fg); }
.chip.REPARADA   { background: var(--warn-bg);   color: var(--warn-fg); }
.chip.PINTURA    { background: var(--info-bg);   color: var(--info-fg); }
.chip.neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

.summary { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.pieces { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.piece { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: grid; gap: 4px; }
.piece-name { font-weight: 600; }
.piece-meta { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 12px; }

/* verdict banner, as in the PDF report: dark grey, stripe + title in green (low) or red (above threshold) */
.verdict {
  background: var(--text); color: #fff; border-radius: var(--radius); padding: 14px 16px 14px 18px;
  border-left: 5px solid var(--accent);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.verdict.low  { border-left-color: var(--accent); }
.verdict.high { border-left-color: var(--danger); }
.verdict-title { font-size: 17px; font-weight: 800; letter-spacing: .02em; line-height: 1.25; flex: 1 1 160px; }
.verdict.low .verdict-title  { color: var(--accent); }
.verdict.high .verdict-title { color: var(--danger); }
.verdict-energy { display: grid; justify-items: end; text-align: right; }
.verdict-energy-label { font-size: 12px; color: #C9D2D6; }
.verdict-energy-value { font-size: 20px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; white-space: nowrap; }

.meta { font-size: 12px; color: var(--muted); word-break: break-all; }
.meta.wrap { word-break: normal; } /* prose: break between words, not inside them */

/* form fields (Nuevo: Tramitador/Referencia; Procesados: filters) */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
.field abbr { color: var(--danger-fg); text-decoration: none; }
.field input {
  font: inherit; font-size: 14px; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.list-filters { display: flex; gap: 12px; flex-wrap: wrap; }
.list-filters .field { flex: 1 1 220px; max-width: 320px; }

/* inline confirmation (Nuevo Análisis with an unprocessed PDF) */
.confirm {
  border: 1px solid var(--warn-fg); background: var(--warn-bg); color: var(--warn-fg);
  border-radius: 8px; padding: 10px 12px; display: grid; gap: 10px;
}
.confirm p { margin: 0; font-size: 13px; }
.confirm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.confirm-actions .btn { padding: 6px 12px; }

/* session & login */
.topbar-right { display: flex; align-items: center; gap: 16px; min-width: 0; }
.session { display: flex; align-items: center; gap: 10px; }
.session-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 24vw; }
.login-view { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; display: grid; gap: 14px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card { border-top: 4px solid var(--accent); }
.login-card p { margin: 0; font-size: 13px; }

/* list of stored results */
.list-view { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.list-head { display: flex; align-items: baseline; gap: 12px; }
.list-head h1 { margin: 0; font-size: 18px; }
.list-head .btn { margin-left: auto; }
.list-head .meta { word-break: normal; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.list-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.list-table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.list-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.list-table tbody tr:last-child td { border-bottom: 0; }
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr:hover { background: var(--surface-2); }
.list-table tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list-table .num { text-align: right; }
.nowrap { white-space: nowrap; }
.list-more { align-self: center; }
.chip.low { background: var(--ok-bg); color: var(--ok-fg); }
.chip.high { background: var(--danger-bg); color: var(--danger-fg); }
.chip.pending { background: var(--warn-bg); color: var(--warn-fg); }

/* detail view */
.back-link { color: var(--text); text-decoration: none; font-weight: 600; justify-self: start; }
.back-link:hover { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.pdf-message {
  flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px;
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); color: var(--muted);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 60vh auto; }
  .panel { border-left: 0; border-top: 1px solid var(--border); }
  .resizer { display: none; }
  .result { overflow: visible; }
  .brand-logo { height: 28px; }
  .topbar-left { gap: 10px; }
  .list-table th:nth-child(3), .list-table td:nth-child(3),
  .list-table th:nth-child(5), .list-table td:nth-child(5),
  .list-table th:nth-child(6), .list-table td:nth-child(6),
  .list-table th:nth-child(7), .list-table td:nth-child(7) { display: none; } /* tramitador, matrícula, cost, energy */
  .fields { grid-template-columns: 1fr; }
}

/* collapsible, flat cards (energy, pieces) */
.card.flat { background: transparent; }
.collapsible > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary h2 { margin: 0; flex: 1; }
.collapsible[open] > summary { margin-bottom: 10px; }
.collapsed-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.collapsible[open] .collapsed-value { display: none; }
.chevron {
  width: 8px; height: 8px; flex: none; margin-right: 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s;
}
.collapsible[open] .chevron { transform: rotate(45deg); }
.collapsible > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

/* no colour inside the flat cards */
.flat .chip { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.flat .piece { background: transparent; }
.collapsible:not([open]) .open-only { display: none; }
