:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef2f4;
  --ink: #18242f;
  --muted: #5d6b77;
  --line: #dce3e8;
  --accent: #0f6e6e;
  --accent-ink: #ffffff;
  --accent-soft: #e1f0ef;
  --high: #1d7a4a; --high-bg: #dff2e7;
  --mid: #8a6100; --mid-bg: #fbf0d4;
  --low: #a13d3d; --low-bg: #f8e1e1;
  --warn: #a35d00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 2px 8px rgba(16, 32, 48, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1519; --surface: #172026; --surface-2: #1e2a31; --ink: #e6edf1; --muted: #93a3ae;
    --line: #2a3841; --accent: #3fb3ad; --accent-ink: #062322; --accent-soft: #163a39;
    --high: #6fd39d; --high-bg: #173527; --mid: #e8c060; --mid-bg: #3a3017; --low: #f08f8f; --low-bg: #3d1f1f;
    --warn: #f0b060; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1519; --surface: #172026; --surface-2: #1e2a31; --ink: #e6edf1; --muted: #93a3ae;
  --line: #2a3841; --accent: #3fb3ad; --accent-ink: #062322; --accent-soft: #163a39;
  --high: #6fd39d; --high-bg: #173527; --mid: #e8c060; --mid-bg: #3a3017; --low: #f08f8f; --low-bg: #3d1f1f;
  --warn: #f0b060; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
input[type="range"] { accent-color: var(--accent); }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.15rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.error { color: var(--low); }
[hidden] { display: none !important; }

button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: .45rem .85rem; background: none; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.ghost { border-color: var(--line); background: var(--surface); }
.ghost:hover { background: var(--surface-2); text-decoration: none; }
select, input[type="search"], input[type="number"], textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem;
}
textarea { width: 100%; resize: vertical; }

/* ---- barra superior */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem;
  padding: .6rem max(16px, calc((100vw - 1080px) / 2)); background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; letter-spacing: .2px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.tabs { display: flex; gap: .25rem; margin-left: .5rem; }
.tabs button { color: var(--muted); font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--ink); background: var(--surface-2); }
.session { margin-left: auto; display: flex; gap: .5rem; align-items: center; }
.session a.ghost { border: 1px solid var(--line); border-radius: 8px; padding: .45rem .85rem; font-size: .9rem; }

main { max-width: 1080px; margin: 0 auto; padding: 1.25rem 16px 4rem; }

/* ---- login */
.center-card {
  max-width: 460px; margin: 12vh auto 0; text-align: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem 1.5rem; box-shadow: var(--shadow);
}
.center-card h1 { font-size: 1.4rem; margin-bottom: .5rem; }
.center-card .primary { margin-top: 1rem; padding: .65rem 1.3rem; }

/* ---- resumen y filtros */
.summary { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .9rem; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .3rem .75rem; font-size: .88rem; }
.chip b { font-variant-numeric: tabular-nums; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input[type="search"] { flex: 1 1 240px; min-width: 0; }
.range { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--muted); }
.range output { min-width: 2ch; font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* ---- ofertas */
.jobs { display: grid; gap: .7rem; }
.job {
  display: grid; grid-template-columns: 52px 1fr; gap: .9rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.job.st-descartada, .job.st-rechazada { opacity: .6; }
.score {
  width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums;
}
.s-high { background: var(--high-bg); color: var(--high); }
.s-mid { background: var(--mid-bg); color: var(--mid); }
.s-low { background: var(--low-bg); color: var(--low); }
.s-none { background: var(--surface-2); color: var(--muted); }
.body { min-width: 0; }
.job h3 { font-size: 1.02rem; overflow-wrap: anywhere; }
.meta { margin: .15rem 0 .4rem; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.resumen { margin: 0 0 .4rem; }
details { margin: .3rem 0 .6rem; }
details summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
details h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: .8rem 0 .25rem; }
details p { margin: 0; }
.warn { color: var(--warn); }
.row-actions { margin-top: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.links { display: flex; gap: .9rem; margin-left: auto; font-size: .92rem; }
.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h3 { margin-bottom: .3rem; }

/* ---- criterios */
.section-head { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; }
.section-head p { margin: .25rem 0 0; }
.criteria { display: grid; gap: .9rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; }
.field { display: grid; gap: .25rem; }
.field .label { font-weight: 600; font-size: .93rem; }
.field .hint { color: var(--muted); font-size: .82rem; }
.field input[type="number"] { max-width: 180px; }

/* ---- actividad */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin-bottom: 1.4rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.kpi b { display: block; font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .86rem; }
.table-wrap { overflow-x: auto; margin-top: .6rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--surface-2); }
td:last-child { white-space: normal; }

/* ---- aviso */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .92rem; z-index: 10;
}
#toast.error { background: var(--low); color: #fff; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  #sheet-link { display: none !important; }
  .job { grid-template-columns: 1fr; }
  .score { width: auto; height: auto; padding: .2rem .6rem; justify-self: start; font-size: 1rem; }
  .links { margin-left: 0; width: 100%; }
}

/* ---- generar ahora */
.generate {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem;
  background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem .9rem; margin-bottom: 1rem;
}
.generate.busy { justify-content: flex-start; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
