:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #18202b;
  --muted: #5e6875;
  --line: #dce0e6;
  --primary: #2747d6;
  --primary-ink: #ffffff;
  --run: #0b8a5b;
  --run-soft: #e3f4ec;
  --run-ink: #ffffff;
  --danger: #c2362f;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --surface: #1a2029; --ink: #e7eaee; --muted: #9aa4b1; --line: #2b333e;
    --primary: #8096ff; --primary-ink: #0d1220; --run: #3cc896; --run-soft: #15302a; --run-ink: #0b1f17; --danger: #f07167;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.55 var(--font); font-variant-numeric: tabular-nums; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; font-weight: 600; }
h1 { font-size: 1.75rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.wrap { width: min(1080px, 100% - 2.5rem); margin-inline: auto; }
main.wrap { padding: 2rem 0 4rem; }
.muted { color: var(--muted); }
.small, .hint { font-size: .85rem; }
.hint { display: block; color: var(--muted); font-weight: 400; margin-top: .25rem; }
.nowrap { white-space: nowrap; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Barra superior */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-in { display: flex; align-items: center; gap: 1rem; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 600; color: var(--ink); text-decoration: none; }
.nav { display: flex; gap: .25rem; margin-left: auto; overflow-x: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: .4rem .65rem; border-radius: 8px; white-space: nowrap; font-size: .95rem; }
.nav a:hover { color: var(--ink); background: var(--bg); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--bg); font-weight: 500; }
.run-pill { display: inline-flex; align-items: center; gap: .45rem; background: var(--run-soft); color: var(--run); padding: .25rem .7rem; border-radius: 999px; text-decoration: none; font-weight: 600; font-size: .9rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--run); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* Mensajes */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; background: var(--run-soft); color: var(--ink); border-left: 3px solid var(--run); }
.flash-error { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border-left-color: var(--danger); }
.warn { color: var(--danger); }

/* Formularios */
label { display: block; font-weight: 500; font-size: .92rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .35rem; padding: .6rem .7rem; font: inherit; font-weight: 400; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
input, select { height: 2.75rem; }
.filters .btn { min-height: 2.75rem; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
textarea { resize: vertical; }
.stack > * + * { margin-top: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 1rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.narrow { max-width: 520px; }
.login { margin: 3rem auto 0; }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 1rem; font: inherit; font-weight: 500;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.btn-stop { background: var(--run); border-color: var(--run); color: var(--run-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--bg); border-color: transparent; }
.btn-sm { padding: .3rem .55rem; font-size: .85rem; }
.btn-lg { padding: .8rem 1.6rem; font-size: 1.05rem; }
.danger { color: var(--danger); }
.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* Cronómetro: el elemento protagonista */
.timer { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; margin-bottom: 2.5rem; position: relative; overflow: hidden; }
.timer-running { border-color: color-mix(in srgb, var(--run) 45%, var(--line)); }
.timer-running::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--run); }
.timer-context { color: var(--run); font-weight: 500; margin-bottom: .2rem; }
.timer-task { font-size: 1.4rem; font-weight: 500; margin-bottom: .2rem; }
.clock { font-size: clamp(4rem, 13vw, 8.5rem); font-weight: 300; line-height: 1; letter-spacing: -.04em; margin: .2em 0 .15em; }
.timer-running .clock { color: var(--ink); }
.clock-idle { color: var(--line); }
.timer-form { margin-top: 1.5rem; max-width: 760px; }

/* Listas de tiempos */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.section-head h1, .section-head h2 { margin: 0; }
.totals { display: flex; gap: 1.25rem; color: var(--muted); margin: 0 0 1rem; flex-wrap: wrap; }
.entry-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.entry-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .85rem 1rem; }
.entry-list li + li { border-top: 1px solid var(--line); }
.entry-main strong { display: block; font-weight: 500; }
.entry-main .muted { font-size: .9rem; }
.note { margin: .35rem 0 0; color: var(--muted); font-size: .92rem; white-space: normal; }
.entry-side { display: flex; align-items: flex-start; gap: .4rem; flex-shrink: 0; }
.dur { font-weight: 600; min-width: 3.5rem; text-align: right; padding-top: .1rem; }

/* Tablas */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: .85rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
td { padding: .7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.is-archived { opacity: .6; }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 6px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); margin-left: .3rem; vertical-align: 1px; }
.tag-run { background: var(--run-soft); color: var(--run); border-color: transparent; }

/* Filtros */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1.25rem; }
.filters label { flex: 1 1 150px; }
.chips { display: flex; gap: .4rem; flex-basis: 100%; flex-wrap: wrap; }
.chip { padding: .3rem .75rem; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--muted); font-size: .9rem; background: var(--surface); }
.chip[aria-current] { border-color: var(--primary); color: var(--primary); font-weight: 500; }

/* Distribución con panel lateral */
.split { display: grid; grid-template-columns: 1fr 340px; gap: 2rem; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; position: sticky; top: 76px; }

/* Reporte */
.report-summary { display: grid; gap: 2rem; margin: 2rem 0 2.5rem; }
.report-total .big { display: block; font-size: clamp(3rem, 9vw, 5rem); font-weight: 300; letter-spacing: -.04em; line-height: 1; }
.bars h2 { margin-bottom: .75rem; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr 4rem; gap: .75rem; align-items: center; padding: .3rem 0; }
.bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 5px; }
.bar-val { text-align: right; font-weight: 600; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day { margin-bottom: 1.5rem; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 1rem .4rem; }
.day-head h3 { margin: 0; font-weight: 500; color: var(--muted); }
.day-head .dur { color: var(--muted); }
.empty { text-align: center; padding: 2rem 1rem; }

@media (max-width: 760px) {
  .grid-2, .split { grid-template-columns: 1fr; }
  .panel { position: static; }
  .timer { padding: 1.25rem; }
  .nav { margin-left: 0; width: 100%; padding-bottom: .4rem; }
  .entry-list li { flex-direction: column; gap: .4rem; }
  .entry-side { justify-content: space-between; align-items: center; }
  .entry-side .dur { text-align: left; min-width: 0; }
  .bar-row { grid-template-columns: 1fr 4rem; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
}
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
@media print {
  :root { --bg: #fff; --surface: #fff; --ink: #000; --muted: #444; --line: #ccc; --primary: #2747d6; }
  .topbar, .no-print { display: none !important; }
  main.wrap { padding: 0; width: 100%; }
  .entry-list, .table-wrap { border: 0; }
  .day { break-inside: avoid; }
}
