:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e6;
  --text: #1d2330;
  --muted: #6b7380;
  --primary: #4f6bed;
  --primary-text: #ffffff;
  --danger: #d64545;
  --warn: #e08a1e;
  --ok: #2e9d5b;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 1px 3px rgb(0 0 0 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1d2128;
    --surface-2: #262b33;
    --border: #323842;
    --text: #e6e8ec;
    --muted: #949ba6;
    --primary: #6f86f5;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h1 a.muted { color: var(--muted); }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
h2 + h2, .list + h2 { margin-top: 1.25rem; }
.muted { color: var(--muted); }
small { font-size: .82em; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { padding: .35rem .7rem; border-radius: 6px; color: var(--muted); }
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.timer-pill {
  margin-left: auto; display: flex; align-items: center; gap: .5rem;
  background: var(--surface-2); padding: .25rem .35rem .25rem .75rem; border-radius: 99px;
}
.timer-pill a { color: var(--text); max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer-pill .dot { animation: pulse 1.5s infinite; }
.elapsed { font-variant-numeric: tabular-nums; font-weight: 600; }
@keyframes pulse { 50% { opacity: .3; } }

main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.flash { background: var(--surface); border-left: 4px solid var(--ok); padding: .6rem 1rem; border-radius: 6px; box-shadow: var(--shadow); }
.alert { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); padding: .5rem .75rem; border-radius: 6px; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; align-items: start; }
.task-layout { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .task-layout { grid-template-columns: 1fr; } }

.dot { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; background: var(--c, var(--primary)); margin-right: .45rem; flex: none; }
.dot.big { width: .9rem; height: .9rem; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; font: inherit; cursor: pointer;
  padding: .45rem .9rem; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: .1rem .3rem; }
.link-btn:hover { color: var(--danger); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: .45rem .6rem; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent); border-color: var(--primary); }
input[type=color] { padding: .15rem; height: 2.3rem; width: 4rem; }
textarea { width: 100%; resize: vertical; }
.form { display: flex; flex-direction: column; gap: .8rem; }
.form label, .form-row label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.form label > input, .form label > select, .form label > textarea { color: var(--text); font-size: .95rem; }
.form-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; }
.form-row > label { flex: 1 1 8rem; }
.form-row.compact { margin-bottom: .75rem; }
.form-row.compact input[name=note] { flex: 1 1 10rem; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.hint { font-size: .82rem; margin: 0; }
.danger-zone { margin-top: 1rem; text-align: right; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; color: var(--muted); font-size: .85rem; box-shadow: var(--shadow); }
.stat span { display: block; font-size: 1.5rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.stat.warn span { color: var(--danger); }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.task-line a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-line small { color: var(--muted); }
.project-line a { flex: 0 0 40%; display: flex; align-items: center; color: var(--text); }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; background: var(--c); }
.entry > :nth-child(3) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.entry a { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.due { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.due.late { color: var(--danger); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
td:nth-child(4) { white-space: normal; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.dim td { opacity: .55; }
.badge { font-size: .78rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); }
.badge.activo { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.pausado { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.comment { border-bottom: 1px solid var(--border); padding: .4rem 0; }
.comment p { margin: .2rem 0 .3rem; overflow-wrap: anywhere; }
.comment-head { display: flex; justify-content: space-between; align-items: center; }
.settings summary { cursor: pointer; font-weight: 600; }
.settings form { margin-top: .9rem; }

/* ---------- Kanban ---------- */
.board { display: grid; grid-template-columns: repeat(3, minmax(260px, 1fr)); gap: .9rem; overflow-x: auto; padding-bottom: .5rem; align-items: start; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: .6rem; border: 2px solid transparent; }
.column.over { border-color: var(--primary); }
.column header { font-weight: 600; font-size: .9rem; padding: .2rem .3rem .6rem; display: flex; justify-content: space-between; }
.count { color: var(--muted); font-weight: 400; }
.cards { display: flex; flex-direction: column; gap: .5rem; min-height: 2rem; }
.task-card {
  display: flex; flex-direction: column; gap: .3rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--c);
  border-radius: 8px; padding: .55rem .7rem; box-shadow: var(--shadow); cursor: grab;
}
.task-card:hover { border-color: var(--primary); border-left-color: var(--c); }
.task-card.dragging { opacity: .45; }
.task-card .title { font-weight: 500; overflow-wrap: anywhere; color: var(--text); }
.task-card .title:hover { color: var(--primary); }
.task-card.prio-2 .title::before { content: "▲ "; color: var(--danger); font-size: .8em; }
.task-card.prio-0 { opacity: .8; }
.task-card .proj { color: var(--muted); font-size: .75rem; }
.task-card .meta { display: flex; gap: .6rem; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }
.column[data-status=hecho] .task-card .title { text-decoration: line-through; color: var(--muted); }
.status-switch { display: flex; gap: 3px; margin-top: .15rem; }
.status-switch button {
  flex: 1; font: inherit; font-size: .72rem; padding: .2rem .25rem; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border); border-radius: 5px; background: transparent; color: var(--muted);
}
.status-switch button:hover { background: var(--surface-2); color: var(--text); }
.status-switch button.active { cursor: default; color: #fff; font-weight: 600; border-color: transparent; }
.status-switch .st-pendiente.active { background: var(--muted); }
.status-switch .st-en_curso.active { background: var(--warn); }
.status-switch .st-hecho.active { background: var(--ok); }
.quick-add { margin-top: .5rem; display: flex; flex-direction: column; gap: .35rem; }
.quick-add input, .quick-add select { width: 100%; background: transparent; border-style: dashed; }
.quick-add input:focus { background: var(--surface); border-style: solid; }

/* ---------- Calendario ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-head { background: var(--surface-2); padding: .4rem; font-size: .8rem; font-weight: 600; text-align: center; color: var(--muted); }
.cal-day { background: var(--surface); min-height: 110px; padding: .3rem; display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.cal-day.empty { background: var(--bg); }
.cal-day.past { background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
.cal-day.today .cal-num { color: var(--primary); font-weight: 700; }
.cal-num { font-size: .82rem; display: flex; justify-content: space-between; color: var(--muted); }
.cal-num small { color: var(--ok); }
.cal-task {
  font-size: .78rem; padding: .1rem .35rem; border-radius: 4px; color: var(--text);
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-task:hover { text-decoration: none; filter: brightness(.95); }
.cal-task.done { text-decoration: line-through; opacity: .55; }
.cal-task.late { outline: 1px solid var(--danger); }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: min(360px, 100%); display: flex; flex-direction: column; gap: 1rem; box-shadow: var(--shadow); }
.login-box h1 { justify-content: center; }
.login-box label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }

/* ---------- Móvil ---------- */
@media (max-width: 640px) {
  main { padding: .9rem; }
  .topbar { gap: .6rem; padding: .5rem .9rem; }
  .timer-pill { margin-left: 0; width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(3, 85vw); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .cal-day { min-height: 70px; }
  .cal-task { font-size: 0; height: 6px; padding: 0; border-left: 0; background: var(--c); }
}

/* ---------- Subtareas ---------- */
.sub-progress { margin-bottom: .6rem; }
.subtasks { list-style: none; margin: 0 0 .6rem; padding: 0; }
.subtask { display: flex; align-items: center; gap: .4rem; padding: .15rem 0; border-bottom: 1px solid var(--border); }
.subtask .subtask-rename { flex: 1; min-width: 0; }
.subtask .subtask-rename input { width: 100%; border-color: transparent; background: transparent; padding: .35rem .4rem; }
.subtask .subtask-rename input:hover { border-color: var(--border); }
.subtask .subtask-rename input:focus { background: var(--surface); border-color: var(--primary); }
.subtask.st-hecho .subtask-rename input { text-decoration: line-through; color: var(--muted); }
.sub-symbol {
  width: 1.9rem; height: 1.9rem; border-radius: 50%; cursor: pointer; flex: none;
  font: 600 1.05rem/1 system-ui, sans-serif; display: grid; place-items: center;
  border: 2px solid var(--muted); background: transparent; color: var(--muted);
}
.sub-symbol:hover { transform: scale(1.08); }
.st-en_curso .sub-symbol { border-color: var(--warn); color: var(--warn); }
.st-hecho .sub-symbol { border-color: var(--ok); background: var(--ok); color: #fff; }
.subtask-add { display: flex; gap: .5rem; align-items: flex-start; }
.subtask-add textarea { flex: 1; min-height: 2.3rem; }
.legend { margin-right: .7rem; white-space: nowrap; }
.legend.st-en_curso b { color: var(--warn); }
.legend.st-hecho b { color: var(--ok); }
.task-card .meta .sub-done { color: var(--ok); font-weight: 600; }

/* ---------- Voz ---------- */
.voice-fab {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 30;
  width: 3.5rem; height: 3.5rem; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: #fff; font-size: 1.5rem; box-shadow: 0 4px 14px rgb(0 0 0 / .25);
}
.voice-fab:hover { filter: brightness(1.08); }
.voice-fab.listening { background: var(--danger); animation: voice-pulse 1.2s infinite; }
@keyframes voice-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 60%, transparent); } 100% { box-shadow: 0 0 0 18px transparent; } }
.voice-panel {
  position: fixed; right: 1.25rem; bottom: 5.5rem; z-index: 30; width: min(440px, calc(100vw - 2.5rem));
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius); padding: .8rem 1rem; box-shadow: 0 6px 24px rgb(0 0 0 / .18); cursor: pointer;
}
.voice-panel.ok { border-left-color: var(--ok); }
.voice-panel.error { border-left-color: var(--danger); }
.voice-panel.listening { border-left-color: var(--danger); }
.voice-state { font-weight: 600; font-size: .85rem; color: var(--muted); }
.voice-panel.ok .voice-state { color: var(--ok); }
.voice-panel.error .voice-state { color: var(--danger); }
.voice-text { white-space: pre-line; margin-top: .2rem; }
main { padding-bottom: 6rem; }

.dictate-wrap { position: relative; display: flex; min-width: 0; }
.dictate-wrap > input, .dictate-wrap > textarea { flex: 1; width: 100%; padding-right: 2.2rem; }
.form label > .dictate-wrap { color: var(--text); font-size: .95rem; }
.dictate {
  position: absolute; right: .3rem; top: .3rem; width: 1.75rem; height: 1.75rem; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer; font-size: .9rem; opacity: .45;
}
.dictate:hover { opacity: 1; background: var(--surface-2); }
.dictate.listening { opacity: 1; background: var(--danger); animation: voice-pulse 1.2s infinite; }
@media (max-width: 640px) { .voice-fab { right: .9rem; bottom: .9rem; } .voice-panel { right: .9rem; bottom: 5rem; } }
