/* Todo: calm and clear. Category colours are the owner's; the yellow/orange/red accents mark deadlines only. */
:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --text: #1c1d20;
  --muted: #6b6e76;
  --line: #e4e2dc;
  --soft: #f0efea;
  --accent: #2f6fd0;
  --accent-text: #ffffff;
  --danger: #c23a2f;
  --tomorrow: #e2b100;
  --today: #ef7d00;
  --overdue: #d4342a;
  --tomorrow-text: #8a6a00;
  --today-text: #b35a00;
  --overdue-text: #b3261e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --card: #212226;
    --text: #ececee;
    --muted: #9a9ca4;
    --line: #34353a;
    --soft: #2a2b30;
    --accent: #5b93ea;
    --accent-text: #0e1420;
    --danger: #ef6b60;
    --tomorrow-text: #f0c93a;
    --today-text: #ff9e3d;
    --overdue-text: #ff6f63;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
#root { max-width: 1240px; margin: 0 auto; padding: 16px 16px 80px; }
button, input, select { font: inherit; color: inherit; }
.loading, .muted { color: var(--muted); }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.top h1 { font-size: 22px; letter-spacing: -.01em; margin-right: auto; }
.mode { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.mode button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.mode button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.tools { display: flex; gap: 4px; }

button { cursor: pointer; }
.ghost { background: none; border: 1px solid transparent; border-radius: 8px; padding: 5px 10px; color: var(--muted); }
.ghost:hover { background: var(--soft); color: var(--text); }
.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px; padding: 7px 14px; font-weight: 600; }
.small, .edit-actions button:not(.primary), .postpone button {
  background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 3px 9px; font-size: 13px;
}
.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- upcoming card ---------- */
.upcoming {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 10px 14px; margin-bottom: 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.upcoming h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.upcoming ol { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.up-item {
  display: flex; align-items: baseline; gap: 8px; background: var(--soft); border: 0; border-radius: 8px;
  padding: 6px 10px; text-align: left; max-width: 100%;
}
.up-date { font-weight: 700; white-space: nowrap; }
.up-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.up-list { font-size: 12px; color: var(--muted); }

/* ---------- lists ---------- */
.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .lists { grid-template-columns: 1fr; } }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 14px 10px; min-width: 0; }
.list-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.list-head h2 { font-size: 18px; }
.count { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); margin: 10px 2px; }
.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 2px 4px; }

.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: flex-start; gap: 6px; padding: 7px 6px 7px 0; border-bottom: 1px solid var(--line);
  border-left: 4px solid transparent; background: var(--card); border-radius: 4px;
}
.items:last-child > .item:last-child { border-bottom: 0; }
.handle, .handle-space { flex: 0 0 22px; height: 24px; }
.handle {
  border: 0; background: none; color: var(--muted); opacity: .45; cursor: grab; padding: 0; touch-action: none;
  font-size: 14px; letter-spacing: -3px; line-height: 24px;
}
.item:hover .handle, .handle:focus-visible { opacity: 1; }
.check {
  flex: 0 0 22px; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--muted);
  background: none; padding: 0; position: relative;
}
.check:hover { border-color: var(--accent); }
.check.checked { background: var(--accent); border-color: var(--accent); }
.check.checked::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid var(--accent-text); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.body { flex: 1; min-width: 0; cursor: pointer; border-radius: 6px; padding: 0 4px; }
.body.static { cursor: default; }
.line1 { display: flex; align-items: baseline; gap: 8px; }
.title { overflow-wrap: anywhere; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-text); background: var(--accent); border-radius: 5px; padding: 0 5px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.meta:empty { display: none; }
.due { white-space: nowrap; }
.due-label { font-weight: 700; margin-right: 5px; }
.cat { display: inline-flex; align-items: center; gap: 5px; color: var(--text); background: color-mix(in srgb, var(--cat) 16%, transparent); border-radius: 999px; padding: 0 8px 0 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cat); }
.owner { white-space: nowrap; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.link::after { content: " ↗"; font-size: 11px; }
.note { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.hint { font-size: 13px; font-style: italic; color: var(--muted); margin-top: 2px; }
.when { white-space: nowrap; }

.postpone { display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.item:hover .postpone, .postpone:focus-within { opacity: 1; }
@media (hover: none) { .postpone { display: none; } }

/* Deadline focus: bigger, bold, an accent border. */
.item.focus { padding-top: 10px; padding-bottom: 10px; }
.item.focus .title { font-weight: 700; font-size: 16.5px; }
.focus-tomorrow { border-left-color: var(--tomorrow); }
.focus-today { border-left-color: var(--today); }
.focus-overdue { border-left-color: var(--overdue); }
.focus-tomorrow .due { color: var(--tomorrow-text); }
.focus-today .due { color: var(--today-text); }
.focus-overdue .due { color: var(--overdue-text); }

.done-item .title { color: var(--muted); text-decoration: line-through; }
.done { margin-top: 10px; }
.done summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 4px 2px; }

.item.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 22%, var(--card)); } to { background: var(--card); } }

/* drag */
.item.dragging { z-index: 1000; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); opacity: .95; pointer-events: none; }
.placeholder { list-style: none; border: 2px dashed var(--line); border-radius: 6px; margin: 2px 0; }
body:has(.dragging) { cursor: grabbing; user-select: none; }

/* ---------- quick add ---------- */
.quick { margin-bottom: 6px; }
.quick-row { display: flex; gap: 6px; }
input:not([type="color"]), select {
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); padding: 6px 9px; min-width: 0;
}
.quick-title { flex: 1; }
.add { background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; }
.quick-details { display: none; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.quick:focus-within .quick-details, .quick.has-text .quick-details { display: flex; }
.quick-details > * { flex: 1 1 120px; }
.cat-field { display: flex; gap: 4px; align-items: center; }
.cat-field input:not([type="color"]) { flex: 1; width: 100%; }
input[type="color"] { width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; flex: 0 0 32px; }
input[type="color"][hidden] { display: none; }

/* ---------- editing ---------- */
.item.editing { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; margin: 4px 0; }
.item.editing > input[name="title"] { font-weight: 600; }
.edit-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.edit-row > .cat-field, .edit-row > input { flex: 1 1 140px; }
.field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.found { margin: 0; font-size: 13px; color: var(--muted); }
.edit-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.edit-actions .danger { margin-left: auto; }

/* ---------- dialogs ---------- */
dialog.panel {
  border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); padding: 16px 18px 20px;
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
dialog.panel::backdrop { background: rgba(0, 0, 0, .35); }
.panel-head { display: flex; align-items: center; margin-bottom: 8px; }
.panel-head h2 { font-size: 18px; margin-right: auto; }
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
.set-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.set-row { display: flex; gap: 6px; align-items: center; }
.set-row input:not([type="color"]) { flex: 1; }
.panel input[type="search"] { width: 100%; margin: 4px 0 6px; }
.archive-results .item { padding-left: 4px; }
.panel a { color: var(--accent); }

/* ---------- login ---------- */
.login { max-width: 320px; margin: 18vh auto 0; display: grid; gap: 10px; text-align: center; }
.login h1 { font-size: 26px; margin-bottom: 8px; }
.login input { padding: 9px 12px; }
.login-msg { color: var(--danger); min-height: 1.4em; margin: 0; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 2000; width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 12px; background: var(--text); color: var(--bg); border-radius: 10px; padding: 9px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }

@media (max-width: 520px) {
  .tools { order: 2; }
  .mode { order: 3; width: 100%; }
  .mode button { flex: 1; }
  .up-title { max-width: 180px; }
}
