:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #e9edf4;
  --text: #16203a;
  --muted: #4d5a75;
  --border: #ccd3e0;
  --accent: #2f4fc9;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --high: #c0392b;
  --medium: #b86e00;
  --low: #2a7a4b;
  --focus: #1a73e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 32, 58, .08), 0 4px 14px rgba(22, 32, 58, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0e1424;
  --surface: #172036;
  --surface-2: #222d49;
  --text: #e8ecf6;
  --muted: #a5b0c8;
  --border: #33415f;
  --accent: #8ea4ff;
  --accent-text: #0e1424;
  --danger: #ff8a80;
  --high: #ff8a7a;
  --medium: #ffc266;
  --low: #7fd8a0;
  --focus: #9ec1ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }
.container { width: min(100% - 2rem, 860px); margin-inline: auto; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: .5rem; top: -4rem; background: var(--accent); color: var(--accent-text); padding: .5rem 1rem; border-radius: 6px; z-index: 100; }
.skip-link:focus { top: .5rem; }

/* Header */
.app-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 1.1rem 0; }
.header-inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
h1 { margin: 0; font-size: 1.7rem; letter-spacing: -.02em; }
.subtitle { margin: .1rem 0 0; color: var(--muted); font-size: .92rem; }
.header-actions { display: flex; gap: .6rem; align-items: center; }

/* Buttons */
.btn { font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; min-height: 40px; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
:root[data-theme="dark"] .btn-danger { color: #0e1424; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.1); }
.btn-danger-ghost { color: var(--danger); }
.btn-icon { width: 40px; padding: 0; font-size: 1.1rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: .3rem .7rem; min-height: 34px; font-size: .88rem; }

/* Toolbar */
.toolbar { display: grid; grid-template-columns: 1fr 220px; gap: 1rem; margin: 1.5rem 0 1rem; align-items: end; }
.filters { grid-column: 1 / -1; display: flex; gap: .5rem; flex-wrap: wrap; }
.chip { font: inherit; padding: .4rem .9rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; min-height: 38px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

/* Form controls */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.toolbar .field { margin-bottom: 0; }
label { font-weight: 600; font-size: .9rem; }
.req { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; width: 100%; min-height: 42px; }
textarea { resize: vertical; }
input[aria-invalid="true"] { border-color: var(--danger); }
.error { color: var(--danger); font-size: .85rem; margin: 0; min-height: 0; }
.error:empty { display: none; }
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }

/* States */
.state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.state.empty { background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius); }
.state h2 { margin: 0 0 .3rem; color: var(--text); }
.spinner { display: inline-block; width: 1.1rem; height: 1.1rem; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Task cards */
.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .8rem; }
.task-card { display: grid; grid-template-columns: auto 1fr; gap: .8rem; background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--low); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.task-card.p-medium { border-left-color: var(--medium); }
.task-card.p-high { border-left-color: var(--high); }
.task-card input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; margin-top: .2rem; accent-color: var(--accent); cursor: pointer; }
.task-title { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.task-card.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-desc { margin: .3rem 0 0; color: var(--muted); overflow-wrap: anywhere; white-space: pre-wrap; }
.meta { display: flex; flex-wrap: wrap; gap: .4rem .5rem; margin-top: .6rem; font-size: .82rem; }
.badge { padding: .1rem .6rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.badge.priority-high { color: var(--high); border-color: var(--high); font-weight: 600; }
.badge.priority-medium { color: var(--medium); border-color: var(--medium); font-weight: 600; }
.badge.priority-low { color: var(--low); border-color: var(--low); font-weight: 600; }
.badge.overdue { color: var(--danger); border-color: var(--danger); font-weight: 600; }
.card-actions { display: flex; gap: .5rem; margin-top: .8rem; }
.list-footer { text-align: right; margin-top: 1rem; }

/* Dialogs */
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 1.5rem; width: min(100% - 2rem, 560px); box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(10, 15, 30, .6); }
dialog h2 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

/* Toast */
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.app-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 2rem 0; }

@media (max-width: 640px) {
  .toolbar { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .header-actions { width: 100%; justify-content: space-between; }
  .dialog-actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}