:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --text: #1c1c28;
  --muted: #6b6b80;
  --border: #e3e3ec;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --urgent: #dc2626;
  --high: #ea7a0c;
  --normal: #2563eb;
  --low: #8a8a9a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  color-scheme: light;
}
/* Dark colours: when the device is dark (unless Light was chosen), or when Dark was chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111118;
    --surface: #1b1b25;
    --text: #ececf3;
    --muted: #9a9ab0;
    --border: #2c2c3a;
    --accent: #818cf8;
    --accent-text: #0f0f1a;
    --urgent: #f87171;
    --high: #fb923c;
    --normal: #60a5fa;
    --low: #8f8fa3;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111118;
  --surface: #1b1b25;
  --text: #ececf3;
  --muted: #9a9ab0;
  --border: #2c2c3a;
  --accent: #818cf8;
  --accent-text: #0f0f1a;
  --urgent: #f87171;
  --high: #fb923c;
  --normal: #60a5fa;
  --low: #8f8fa3;
  --shadow: none;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a.button { cursor: pointer; border: 0; background: none; border-radius: 10px; padding: .5em .9em; }
a.button { display: inline-block; color: inherit; text-decoration: none; }
a.button.ghost { border: 1px solid var(--border); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { border: 1px solid var(--border); background: var(--surface); }
.danger { color: var(--urgent); }
.icon-btn { padding: .4em .55em; font-size: 1.2em; line-height: 1; }
.icon-btn:hover, .ghost:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.error { color: var(--urgent); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
  padding: calc(.6rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .6rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; font-size: 1.1rem; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--low); }
.sync-dot.ok { background: #16a34a; }
.sync-dot.syncing { background: var(--high); }
.sync-dot.offline { background: var(--urgent); }
#search {
  flex: 1 1 160px; min-width: 0;
  padding: .5em .8em; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
}
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.view-toggle button { border-radius: 0; padding: .45em .8em; }
.view-toggle button.active { background: var(--accent); color: var(--accent-text); }

.banner { margin: .8rem auto 0; max-width: 820px; padding: .6rem 1rem; border-radius: 10px; background: color-mix(in srgb, var(--high) 15%, var(--surface)); font-size: .9rem; }

main { max-width: 820px; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-left)) 4rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.composer { padding: .8rem; }
.composer.drop { outline: 2px dashed var(--accent); }
.composer textarea {
  width: 100%; resize: none; border: 0; outline: 0; background: transparent; min-height: 3.5em;
}
.interim { color: var(--muted); font-style: italic; min-height: 0; }
.interim:empty { display: none; }
.composer-actions { display: flex; align-items: center; gap: .25rem; margin-top: .3rem; }
.hint { color: var(--muted); font-size: .8rem; margin-right: .5rem; }
@media (hover: none) { .hint { display: none; } }
.recording { background: color-mix(in srgb, var(--urgent) 20%, transparent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--urgent) 20%, transparent); } }

.thumbs { display: flex; flex-wrap: wrap; gap: .5rem; }
.thumbs:empty { display: none; }
.thumb { position: relative; }
.thumb img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; display: block; }
.thumb button {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0;
  border-radius: 50%; background: var(--text); color: var(--bg); font-size: .7rem;
}

.chips { display: flex; gap: .4rem; overflow-x: auto; padding: 1rem 0 .2rem; scrollbar-width: none; }
.chip { white-space: nowrap; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: .3em .85em; font-size: .9rem; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.group h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.4rem 0 .5rem; display: flex; gap: .5rem; align-items: center; }
.group.p-urgent h2 { color: var(--urgent); }
.group.p-high h2 { color: var(--high); }
.count { background: var(--border); color: var(--muted); border-radius: 999px; padding: 0 .5em; font-size: .75rem; }

.note { display: flex; gap: .7rem; padding: .8rem .9rem; margin-bottom: .55rem; cursor: pointer; border-left: 4px solid var(--low); }
.note.p-urgent { border-left-color: var(--urgent); }
.note.p-high { border-left-color: var(--high); }
.note.p-normal { border-left-color: var(--normal); }
.note.done { opacity: .6; }
.note.done h3 { text-decoration: line-through; }
.check {
  flex: none; width: 24px; height: 24px; padding: 0; margin-top: 2px;
  border: 2px solid var(--border); border-radius: 50%; font-size: .8rem; color: var(--accent-text);
}
.note.done .check { background: var(--accent); border-color: var(--accent); }
.check:hover { border-color: var(--accent); }
.note-main { flex: 1; min-width: 0; }
.note-head { display: flex; gap: .4rem; align-items: baseline; }
.note h3 { margin: 0; font-size: 1rem; font-weight: 600; overflow-wrap: anywhere; }
.note-text { margin: .25rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.note-images { display: flex; gap: .4rem; margin-top: .5rem; overflow-x: auto; }
.note-images img { height: 84px; max-width: 160px; object-fit: cover; border-radius: 8px; background: var(--border); }
.meta { display: flex; flex-wrap: wrap; gap: .35rem .5rem; align-items: center; margin-top: .5rem; font-size: .78rem; color: var(--muted); }
.badge { font-weight: 600; border-radius: 6px; padding: .05em .45em; }
.badge.p-urgent { color: var(--urgent); background: color-mix(in srgb, var(--urgent) 12%, transparent); }
.badge.p-high { color: var(--high); background: color-mix(in srgb, var(--high) 12%, transparent); }
.badge.p-normal { color: var(--normal); background: color-mix(in srgb, var(--normal) 12%, transparent); }
.badge.p-low { color: var(--low); background: color-mix(in srgb, var(--low) 15%, transparent); }
.group-chip { border: 1px solid var(--border); border-radius: 6px; padding: 0 .4em; }
.due.overdue { color: var(--urgent); font-weight: 600; }
.due.soon { color: var(--high); }
.tag { color: var(--accent); }
.time { margin-left: auto; }
.ai-pending { animation: spin 1.6s linear infinite; display: inline-block; font-size: .85rem; }
@keyframes spin { 50% { opacity: .3; } }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.done-toggle { display: block; margin: 1.5rem auto 0; }

dialog { border: 0; padding: 0; color: var(--text); }
dialog::backdrop { background: rgba(10, 10, 20, .5); }
.sheet { width: min(680px, 100vw - 1rem); max-height: 92vh; border-radius: 18px; background: var(--surface); }
.sheet-inner { padding: 1rem; display: flex; flex-direction: column; gap: .8rem; }
.sheet-head { display: flex; align-items: center; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.1rem; }
.sheet .composer { border: 1px solid var(--border); border-radius: 12px; }
.ai-box { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); border-radius: 10px; padding: .2rem .8rem; font-size: .9rem; }
.ai-box p { margin: .5rem 0; }
.overrides { display: flex; gap: .8rem; flex-wrap: wrap; }
.overrides label { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; color: var(--muted); flex: 1 1 180px; }
.overrides input, .overrides select, #loginPassword {
  padding: .5em .7em; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem;
}
.sheet-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
@media (max-width: 600px) {
  .sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 95vh; padding-bottom: env(safe-area-inset-bottom); }
  #reorganizeBtn { order: 3; }
}

.camera { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; background: #000; }
.camera video { width: 100%; height: 100%; object-fit: contain; }
.camera.flash video { opacity: .3; }
.camera-actions {
  position: absolute; left: 0; right: 0; bottom: calc(1.5rem + env(safe-area-inset-bottom));
  display: flex; justify-content: space-around; align-items: center;
}
.icon-btn.light { color: #fff; background: rgba(255, 255, 255, .15); border-radius: 50%; width: 52px; height: 52px; }
.shutter { width: 74px; height: 74px; border-radius: 50%; background: #fff; border: 5px solid rgba(255, 255, 255, .4); background-clip: padding-box; }
.camera-count { position: absolute; top: calc(1rem + env(safe-area-inset-top)); width: 100%; text-align: center; color: #fff; }

.viewer { background: transparent; max-width: 100vw; max-height: 100vh; }
.viewer img { max-width: 96vw; max-height: 92vh; display: block; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 100; max-width: 90vw;
}

.field { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.field input {
  padding: .6em .75em; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem;
}
/* Password fields: Show / Hide what you typed. */
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; min-width: 0; padding-right: 4.5em; }
.pw-toggle {
  position: absolute; right: .35em; top: 50%; transform: translateY(-50%);
  padding: .3em .6em; border-radius: 8px; color: var(--accent); font-size: .85rem; font-weight: 600;
}
#loginForm h2, #account h2 { margin: 0; }
#loginForm .muted { margin: 0; }
.switch { margin: 0; text-align: center; font-size: .9rem; color: var(--muted); }
.switch button { color: var(--accent); font-weight: 600; padding: .2em .3em; }
.avatar-btn {
  width: 34px; height: 34px; padding: 0; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: .85rem; flex: none;
}
.stack { display: flex; flex-direction: column; gap: .6rem; border-top: 1px solid var(--border); padding-top: .8rem; }
.stack h3 { margin: 0; font-size: 1rem; }
#pwMessage:empty { display: none; }
#pwMessage { margin: 0; font-size: .9rem; }
#pwMessage.ok { color: #16a34a; }
#pwMessage.err { color: var(--urgent); }
#appAddress code { font-size: .95rem; word-break: break-all; }

/* Continue with Google / Apple / … */
.providers { display: grid; gap: 8px; margin: 4px 0 8px; }
.provider-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: inherit; font: inherit; font-weight: 600; text-decoration: none;
}
.provider-btn:hover { background: var(--bg); }
.provider-mark {
  width: 22px; height: 22px; border-radius: 6px; display: inline-grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 700; flex: none;
}
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; margin: 6px 0; }
.or::before, .or::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.identity-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.identity-list li { display: flex; align-items: center; gap: 10px; }
.identity-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.add-chip { border-style: dashed; color: var(--accent); }

.theme-switch { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; width: fit-content; }
.theme-switch button { border-radius: 0; }
.theme-switch button.active { background: var(--accent); color: var(--accent-text); }

/* Lists */
.list-preview { margin: 6px 0 2px; }
.list-progress { height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; }
.list-progress span { display: block; height: 100%; background: #16a34a; }
.list-count { font-size: .8rem; color: var(--muted); }
.list-preview ul { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 2px; }
.list-preview li { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.list-preview li.more { color: var(--muted); font-size: .85rem; padding-left: 30px; }
.check.small { width: 20px; height: 20px; min-width: 20px; font-size: .7rem; padding: 0; }
.list-preview li.p-urgent .check { border-color: var(--urgent); }
.list-preview li.p-high .check { border-color: var(--high); }
.items-box { display: grid; gap: 8px; }
.items-head { display: flex; align-items: baseline; gap: 10px; }
.items-head h3 { margin: 0; font-size: 1rem; }
.item-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.item { display: flex; align-items: center; gap: 8px; border-left: 3px solid var(--normal); padding-left: 8px; }
.item.p-urgent { border-left-color: var(--urgent); }
.item.p-high { border-left-color: var(--high); }
.item.p-low { border-left-color: var(--low); }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.item-text { flex: 1; min-width: 0; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: .35em .5em; }
.item-text:focus { border-color: var(--border); background: var(--surface); outline: none; }
.item-priority { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: .25em .4em; font-size: .85rem; }
.add-item { display: flex; gap: 8px; }
.add-item input { flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: .5em .7em; background: var(--surface); }
