:root {
  --bg: #0f1117;
  --card: #1e2130;
  --card-hover: #232640;
  --border: #2d3148;
  --border-hover: #4b5563;
  --text: #e2e8f0;
  --text-bright: #f8fafc;
  --muted: #64748b;
  --muted-bright: #94a3b8;
  --red: #f87171;
  --yellow: #fbbf24;
  --green: #34d399;
  --indigo: #818cf8;
  --sky: #38bdf8;
  --radius: 10px;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 28px 16px 96px;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 820px; margin: 0 auto; }
.hidden { display: none !important; }

/* ---------- gate ---------- */
#gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.gate-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; width: 100%; max-width: 380px;
}
.gate-box h2 { font-size: 1.05rem; color: var(--text-bright); margin-bottom: 6px; }
.gate-box p { font-size: 0.8rem; color: var(--muted); margin-bottom: 18px; line-height: 1.5; }
.gate-err { color: var(--red); font-size: 0.78rem; margin-top: 10px; min-height: 1em; }

/* ---------- header ---------- */
header { margin-bottom: 22px; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
header h1 { font-size: 1.4rem; font-weight: 700; color: var(--text-bright); }
.subtitle { font-size: 0.82rem; color: var(--muted); margin-top: 3px; }

.week-nav {
  display: flex; align-items: center; gap: 8px;
  margin-top: 16px; flex-wrap: wrap;
}
.week-label {
  font-size: 0.92rem; font-weight: 600; color: var(--text-bright);
  min-width: 190px; text-align: center;
}
.week-label .rel { display: block; font-size: 0.7rem; font-weight: 500; color: var(--muted); margin-top: 1px; }

select, input, textarea {
  font-family: inherit; font-size: 0.85rem;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; outline: none; width: 100%;
}
select:focus, input:focus, textarea:focus { border-color: var(--indigo); }
select { cursor: pointer; }
.week-nav select { width: auto; max-width: 200px; }

/* ---------- buttons ---------- */
button {
  font-family: inherit; cursor: pointer;
  border: 1px solid var(--border); background: var(--card);
  color: var(--muted-bright); border-radius: 8px;
  padding: 7px 12px; font-size: 0.8rem; font-weight: 600;
  transition: border-color .15s, color .15s, background .15s;
}
button:hover:not(:disabled) { border-color: var(--border-hover); color: var(--text-bright); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--indigo); border-color: var(--indigo); color: #10121c; }
button.primary:hover:not(:disabled) { background: #9aa6fa; border-color: #9aa6fa; color: #10121c; }
button.danger:hover:not(:disabled) { border-color: var(--red); color: var(--red); }
.icon-btn { padding: 6px 9px; font-size: 0.85rem; line-height: 1; }
.nav-btn { padding: 7px 11px; font-size: 0.9rem; line-height: 1; }

/* ---------- stats ---------- */
.stats { display: flex; gap: 10px; margin: 22px 0 16px; flex-wrap: wrap; }
.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 16px; flex: 1; min-width: 104px;
}
.stat-num { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 0.71rem; color: var(--muted); margin-top: 2px; }
.stat-num.red { color: var(--red); }
.stat-num.yellow { color: var(--yellow); }
.stat-num.green { color: var(--green); }
.stat-num.done { color: var(--indigo); }

.progress-bar { height: 4px; background: var(--border); border-radius: 4px; margin-bottom: 20px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--indigo), var(--green)); border-radius: 4px; transition: width .3s; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filter-btn {
  font-size: 0.75rem; font-weight: 600; padding: 5px 13px;
  border-radius: 20px; letter-spacing: .03em;
}
.filter-btn.active { background: var(--border); color: var(--text-bright); border-color: var(--border-hover); }
.toolbar .spacer { flex: 1; }

/* ---------- banner ---------- */
.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(56,189,248,.08); border: 1px solid rgba(56,189,248,.28);
  border-radius: var(--radius); padding: 12px 15px; margin-bottom: 16px;
  font-size: 0.82rem; color: #bae6fd;
}
.banner .spacer { flex: 1; }

/* ---------- sections + tasks ---------- */
.section { margin-bottom: 22px; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.76rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; margin-bottom: 10px; padding-left: 4px;
  color: var(--muted-bright);
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.alta { background: var(--red); }
.dot.media { background: var(--yellow); }
.dot.baja { background: var(--green); }
.section-count { color: var(--muted); font-weight: 600; }

.task {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 8px;
  display: flex; align-items: flex-start; gap: 12px;
  transition: border-color .15s, background .15s, opacity .15s;
}
.task:hover { border-color: var(--border-hover); background: var(--card-hover); }
.task.done { opacity: .45; border-color: var(--card); }
.task.done:hover { opacity: .7; }
.task.done .task-title { text-decoration: line-through; color: #475569; }
.task.is-today { border-color: rgba(56,189,248,.5); }
.task.is-today:not(.done) { box-shadow: inset 3px 0 0 var(--sky); }

.checkbox {
  width: 20px; height: 20px; border-radius: 6px; cursor: pointer;
  border: 2px solid var(--border-hover); flex-shrink: 0; margin-top: 1px;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
  background: none; padding: 0;
}
.checkbox:hover { border-color: var(--indigo); }
.task.done .checkbox { background: var(--indigo); border-color: var(--indigo); }
.checkbox svg { display: none; }
.task.done .checkbox svg { display: block; }

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 0.9rem; font-weight: 500; line-height: 1.4; color: var(--text); overflow-wrap: anywhere; }
.task-note { font-size: 0.78rem; color: var(--muted); margin-top: 4px; line-height: 1.45; overflow-wrap: anywhere; }
.task-meta { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.badge {
  font-size: 0.67rem; font-weight: 700; padding: 2px 8px;
  border-radius: 20px; flex-shrink: 0; text-transform: uppercase; letter-spacing: .05em;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.alta { background: rgba(248,113,113,.15); color: var(--red); border-color: rgba(248,113,113,.3); }
.badge.media { background: rgba(251,191,36,.12); color: var(--yellow); border-color: rgba(251,191,36,.25); }
.badge.baja { background: rgba(52,211,153,.1); color: var(--green); border-color: rgba(52,211,153,.2); }
.badge.today { background: rgba(56,189,248,.14); color: var(--sky); border-color: rgba(56,189,248,.3); }
.badge.carried { background: rgba(251,146,60,.12); color: #fb923c; border-color: rgba(251,146,60,.28); }
.badge.src { background: none; color: var(--muted); border-color: var(--border); text-transform: none; letter-spacing: 0; font-weight: 600; }

.task-actions { display: flex; gap: 4px; flex-shrink: 0; align-items: center; }
.task-actions button { padding: 5px 8px; font-size: 0.85rem; line-height: 1; background: none; border-color: transparent; }
.task-actions button:hover:not(:disabled) { background: var(--bg); border-color: var(--border-hover); }
.task-actions button.on { color: var(--sky); border-color: rgba(56,189,248,.4); }

.empty {
  text-align: center; padding: 44px 20px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius); font-size: 0.86rem; line-height: 1.6;
}
.empty .big { font-size: 1.8rem; display: block; margin-bottom: 10px; }

/* ---------- add form ---------- */
.add-form {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 18px;
}
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 140px; }
textarea { resize: vertical; min-height: 62px; line-height: 1.45; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 90; background: rgba(6,8,14,.7);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 22px; width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto;
}
.modal-box h3 { font-size: 1rem; color: var(--text-bright); margin-bottom: 16px; }
.history { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.history h4 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.hist-item { display: flex; gap: 10px; font-size: 0.76rem; color: var(--muted-bright); padding: 5px 0; border-bottom: 1px solid rgba(45,49,72,.5); }
.hist-item:last-child { border-bottom: none; }
.hist-when { color: var(--muted); white-space: nowrap; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(90px);
  background: var(--card); border: 1px solid var(--border-hover); color: var(--text-bright);
  padding: 11px 20px; border-radius: 30px; font-size: 0.82rem; font-weight: 600;
  z-index: 120; transition: transform .25s ease; box-shadow: 0 8px 28px rgba(0,0,0,.45);
  max-width: 90vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--red); color: var(--red); }

/* ---------- mobile ---------- */
@media (max-width: 560px) {
  body { padding: 20px 12px 90px; }
  header h1 { font-size: 1.2rem; }
  .week-nav { justify-content: space-between; }
  .week-label { min-width: 0; flex: 1; font-size: 0.85rem; }
  .week-nav select { max-width: 100%; width: 100%; order: 5; }
  .stat { min-width: calc(50% - 5px); }
  .task { flex-wrap: wrap; }
  .task-actions { width: 100%; justify-content: flex-end; margin-top: 4px; border-top: 1px solid var(--border); padding-top: 8px; }
  .task-actions button { padding: 6px 12px; }
}
