:root {
  --bg: #f4f5f8; --card: #ffffff; --text: #171a21; --muted: #667085; --line: #e3e6ec;
  --accent: #1f4fd8; --accent-text: #ffffff; --danger: #c62828; --warn-bg: #fdecea; --warn-text: #a61b1b;
  --ok-bg: #e8f1ff; --ok-text: #1f4fd8; --chip: #e9ecf2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #191c23; --text: #eceef2; --muted: #98a2b3; --line: #2a2f3a;
    --accent: #6b93ff; --accent-text: #0b1020; --danger: #ff6b6b; --warn-bg: #3a1a1a; --warn-text: #ffb4b4;
    --ok-bg: #18233f; --ok-text: #a9c1ff; --chip: #232832;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); font-size: 14px; margin: 4px 0; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 6px 0; }

/* auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; text-align: center; }
.auth-card img { border-radius: 14px; }
.auth-card h1 { font-size: 22px; margin: 10px 0 4px; }
.auth-card label { display: block; text-align: left; font-size: 14px; color: var(--muted); margin-top: 12px; }
.auth-card input { width: 100%; margin-top: 4px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(env(safe-area-inset-top) + 10px) 16px 8px; border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 4px; max-width: 760px; margin: 0 auto; }
.top-row h1 { font-size: 22px; margin: 0; flex: 1; }
.icon-btn { position: relative; border: 0; background: none; padding: 9px; border-radius: 50%; color: var(--text); display: grid; place-items: center; }
.icon-btn:active { background: var(--chip); }
.dot { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.search { max-width: 760px; margin: 8px auto 0; display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 11px 0; color: var(--text); font-size: 16px; -webkit-appearance: none; appearance: none; }
.search:focus-within { border-color: var(--accent); }
.chips { max-width: 760px; margin: 8px auto 0; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 0; background: var(--chip); color: var(--text); padding: 7px 14px; border-radius: 999px; white-space: nowrap; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-text); }

.chips.tags { margin-top: 6px; }
.chips.tags .chip { font-size: 13px; padding: 5px 11px; }
.tag-hints { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.tag-hints button { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px; padding: 3px 9px; font-size: 13px; }

/* list */
.list { max-width: 760px; margin: 0 auto; padding: 12px 16px calc(env(safe-area-inset-bottom) + 96px); display: grid; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; text-align: left; width: 100%; display: block; }
.card.done { opacity: .62; }
.card-title { font-weight: 600; overflow-wrap: anywhere; }
.card.done .card-title { text-decoration: line-through; }
.card-body { color: var(--muted); font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--ok-bg); color: var(--ok-text); }
.badge.due { background: var(--warn-bg); color: var(--warn-text); font-weight: 600; }
.badge.plain { background: var(--chip); color: var(--muted); }
.thumbs { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; background: var(--chip); }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }

.fab { position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 18px); width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 6; }

/* sheets */
dialog.sheet { border: 0; padding: 0; background: var(--card); color: var(--text); width: 100%; max-width: 920px; max-height: 100dvh; border-radius: 16px; }
dialog.sheet.small { max-width: 520px; }
dialog.sheet::backdrop { background: rgba(0,0,0,.45); }
@media (max-width: 680px) {
  dialog.sheet { margin: 0; max-width: none; width: 100vw; height: 100dvh; max-height: none; border-radius: 0; }
  dialog.sheet.small { height: auto; margin: auto 0 0; border-radius: 16px 16px 0 0; }
}
.sheet-head { position: sticky; top: 0; background: var(--card); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: calc(env(safe-area-inset-top) + 12px) 14px 12px; border-bottom: 1px solid var(--line); z-index: 1; }
.sheet.small .sheet-head { padding-top: 12px; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head > :first-child { justify-self: start; }
.sheet-body { padding: 14px 16px calc(env(safe-area-inset-bottom) + 20px); overflow-y: auto; }
.link { border: 0; background: none; color: var(--accent); padding: 6px 4px; font-size: 16px; cursor: pointer; }
.link.strong { font-weight: 700; }
.title-input { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 12px; font-size: 17px; font-weight: 600; margin-bottom: 10px; }
textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 12px; resize: vertical; min-height: 240px; max-height: 75dvh; font-size: 16px; line-height: 1.5; }
.field { margin-top: 18px; display: grid; gap: 8px; }
.field-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.field input[type=datetime-local], .field input[type=date], .field select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; min-height: 44px; }
.remind-btn { width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; min-height: 44px; color: var(--muted); }
.remind-btn.set { color: var(--text); font-weight: 600; }
dialog.picker { border: 0; border-radius: 16px; padding: 14px; background: var(--card); color: var(--text); width: min(340px, calc(100vw - 32px)); }
dialog.picker::backdrop { background: rgba(0,0,0,.5); }
.pk-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.pk-nav { border: 0; background: var(--chip); color: var(--text); width: 38px; height: 38px; border-radius: 50%; font-size: 22px; line-height: 1; }
.pk-week, .pk-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.pk-week span { font-size: 12px; color: var(--muted); padding: 4px 0; }
.pk-day { border: 0; background: none; color: var(--text); aspect-ratio: 1; border-radius: 50%; font-size: 15px; padding: 0; }
.pk-day:hover { background: var(--chip); }
.pk-day.today { outline: 1px solid var(--accent); outline-offset: -2px; }
.pk-day.sel { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.pk-chosen { text-align: center; margin: 10px 0 6px; font-weight: 600; }
.pk-time { display: flex; align-items: center; justify-content: center; gap: 8px; }
.pk-time span { color: var(--muted); font-size: 14px; margin-right: 4px; }
.pk-time select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 18px; font-variant-numeric: tabular-nums; }
.pk-night { display: block; margin: 6px auto 0; font-size: 13px; padding: 4px 6px; }
.pk-foot { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; margin-top: 12px; }
.inline { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.quick button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.presets { display: grid; gap: 6px; }
.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.preset-label { flex: 0 0 62px; font-size: 13px; color: var(--muted); }
.preset-hint { font-size: 12px; color: var(--muted); margin-left: 4px; }
.preset-row button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 10px; font-size: 14px; font-variant-numeric: tabular-nums; min-width: 40px; }
.preset-row button:disabled { opacity: .32; cursor: default; }
.preset-row button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
/* Phones: seven equal chips per line, label above and hint below. */
@media (max-width: 520px) {
  .preset-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
  .preset-label, .preset-hint { grid-column: 1 / -1; margin: 0; }
  .preset-row button { padding: 7px 0; font-size: 13px; min-width: 0; }
}
.photo-hint, .repeat-hint { margin: 0; font-size: 13px; }
dialog.sheet.dropping { outline: 3px dashed var(--accent); outline-offset: -8px; }
.photo-row { display: flex; flex-wrap: wrap; gap: 8px; }
.photo { position: relative; }
.photo img { cursor: zoom-in; width: 84px; height: 84px; object-fit: cover; border-radius: 10px; display: block; background: var(--chip); }
.photo button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: 15px; line-height: 1; }
.primary, .secondary, .danger { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid transparent; font-weight: 600; font-size: 16px; }
.primary { background: var(--accent); color: var(--accent-text); margin-top: 8px; }
.secondary { background: var(--bg); border-color: var(--line); }
.danger { background: none; border-color: var(--danger); color: var(--danger); }
.primary:disabled { opacity: .6; }
.save-main { margin-top: 18px; }

/* devices + mute */
.devices { display: grid; gap: 10px; }
.device { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; }
.device-info { display: grid; gap: 2px; }
.device-info span { font-size: 14px; }
.device-muted { color: var(--warn-text); font-weight: 600; }
.device-ctl { display: flex; gap: 8px; }
.device-ctl select { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; }
.device-ctl .secondary { width: auto; flex: 0 0 auto; padding: 9px 14px; }
.muted-bell { opacity: .4; }

/* Wide screens: text on the left, reminder / photos / actions on the right, nothing to scroll. */
@media (min-width: 1000px) {
  dialog.sheet:not(.small) { max-width: 1280px; }
  .editor-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 0 28px; align-items: start; }
  .col-side > .field:first-child { margin-top: 0; }
  .col-main textarea { min-height: min(56dvh, 520px); }
}
@media (min-width: 520px) {
  .actions { grid-template-columns: 1fr 1fr; }
  .actions .quick, .actions .danger, .actions .wide { grid-column: 1 / -1; }
}
dialog.viewer { border: 0; padding: 0; margin: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; background: rgba(0,0,0,.92); cursor: zoom-out; }
dialog.viewer[open] { display: grid; place-items: center; }
dialog.viewer::backdrop { background: rgba(0,0,0,.6); }
.viewer img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 90px); background: #222; color: #fff; padding: 10px 16px; border-radius: 18px; z-index: 60; font-size: 14px; max-width: 90vw; text-align: center; }
/* On a phone the save button sits in the top bar, always in reach; the one at the bottom is dropped. */
.save-top { display: none; }
.save-top:disabled { opacity: .5; }
@media (max-width: 680px) {
  .save-top { display: inline-block; }
  .save-main { display: none; }
}
/* The postpone box is hidden for a new note; the box after it then starts the column. */
@media (min-width: 1000px) { .col-side > .field[hidden] + .field { margin-top: 0; } }
.toast.tap { cursor: pointer; }
/* A note that was just saved lights up for a moment so it can be found in the list. */
.card.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); transition: box-shadow .3s; }
/* Without this the centred message could only be half the screen wide. */
.toast { width: max-content; }

/* End date of a repeat: typed day/month/year with a mouse, the phone's own date wheel on touch screens. */
.field #untilText { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: inherit; font-size: 16px; min-height: 44px; }
.field #untilText.bad { border-color: var(--danger); }
@media (pointer: fine) { .field #until { display: none; } }
@media (pointer: coarse) { .field #untilText { display: none; } }
