:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #646b73;
  --border: #dcdad5;
  --accent: #5b4bd6;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --ok: #23863a;
}

/* Dark: chosen in Settings, or following the system when the theme is "system". */
:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1e2125;
  --text: #e6e8eb;
  --muted: #9aa1a9;
  --border: #33373d;
  --accent: #8f83ff;
  --accent-text: #111111;
  --danger: #ff6b5e;
  --ok: #4cc26a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e6e8eb;
    --muted: #9aa1a9;
    --border: #33373d;
    --accent: #8f83ff;
    --accent-text: #111111;
    --danger: #ff6b5e;
    --ok: #4cc26a;
  }
}

/* A custom accent (Settings > Preferences); theme.js computes readable light and
   dark variants of the picked color. These selectors are more specific than the
   theme blocks above, so they win in both modes. */
:root[data-accent] { --accent: var(--accent-l); --accent-text: var(--accent-text-l); }
:root[data-accent][data-theme="dark"] { --accent: var(--accent-d); --accent-text: var(--accent-text-d); }
@media (prefers-color-scheme: dark) {
  :root[data-accent]:not([data-theme="light"]) { --accent: var(--accent-d); --accent-text: var(--accent-text-d); }
}

* { box-sizing: border-box; }

/* The hidden attribute must win over component display rules (e.g. .topbar's
   display: flex), or "hidden" elements stay visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar nav { display: flex; gap: 16px; align-items: center; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand img { display: block; }
a { color: var(--accent); }

main { max-width: 720px; margin: 0 auto; padding: 24px 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 1.15rem; }

label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

input, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input[type="checkbox"] { width: auto; margin-right: 8px; }
.check { display: flex; align-items: center; font-weight: 600; }

button {
  font: inherit;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
.actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.msg { margin-top: 12px; font-size: 0.9rem; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

.auth { max-width: 380px; margin: 40px auto; }
.muted { color: var(--muted); }

.status { margin: -6px 0 8px; font-size: 0.9rem; color: var(--muted); }
.status::before { content: "●"; margin-right: 6px; }
.status.connected::before { color: var(--ok); }
.status.connecting::before { color: #d9a400; }
.status.error { color: var(--danger); }

/* ---- Inbox ---- */
.capture { padding: 14px; }
.capture-row { display: flex; gap: 10px; }
.capture-row input { flex: 1; }
.capture .msg:empty { display: none; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.item { padding: 14px 16px; margin-bottom: 12px; }
.item-head { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 0.8rem; margin-bottom: 6px; }
.item-row { display: flex; gap: 14px; align-items: flex-start; }
.item-main { flex: 1; min-width: 0; }
.item-title { display: block; font-weight: 600; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
a.item-title:hover { color: var(--accent); text-decoration: underline; }
.item-site { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-desc {
  margin: 6px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item-body { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.item-thumb { width: 96px; height: 72px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: var(--bg); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { padding: 0; border: none; background: none; color: var(--accent); font-size: 0.85rem; }
.tag:hover { text-decoration: underline; }
button.link.danger { color: var(--muted); font-size: 0.8rem; }
button.link.danger:hover { color: var(--danger); }
.actions.center { justify-content: center; }

.item.done .item-title, .item.done .item-body { color: var(--muted); text-decoration: line-through; }
.reminder-when { font-size: 0.9rem; margin-top: 2px; }
.entries { list-style: none; padding: 0; margin: 8px 0 0; }
.entries li { padding: 2px 0; }
.entries label { display: flex; align-items: center; font-weight: normal; margin: 0; font-size: 0.95rem; cursor: pointer; }
.entries li.checked label { color: var(--muted); text-decoration: line-through; }
.item-actions { margin-top: 10px; }
button.small { padding: 4px 12px; font-size: 0.85rem; }

#search { margin-bottom: 12px; }

/* ---- Embeds ---- */
.embed { margin-top: 10px; }
.embed-frame { display: block; width: 100%; border: 0; border-radius: 8px; background: var(--bg); }
.embed-frame.video { aspect-ratio: 16 / 9; }
.embed-frame.tall { max-width: 340px; height: 640px; }
.embed-frame.post { max-width: 550px; height: 520px; }

/* ---- Reminders ---- */
.rem-section h2 { font-size: 1rem; margin: 22px 0 10px; }
.rem-section h2 .count { color: var(--muted); font-weight: normal; }
.rem-section.overdue h2 { color: var(--danger); }
.rem-section.overdue .item { border-left: 3px solid var(--danger); }
.item-actions.actions { margin-top: 10px; }
a.tag { text-decoration: none; }
a.tag:hover { text-decoration: underline; }

/* ---- Accent picker ---- */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatch {
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.swatch.selected { box-shadow: 0 0 0 2px var(--text); }
.swatch-custom { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.swatch-custom input[type="color"] { width: 40px; height: 32px; padding: 2px; border-radius: 7px; cursor: pointer; }
.swatch-custom.selected { color: var(--text); font-weight: 600; }

/* ---- Bookmarklet ---- */
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}
.bookmarklet {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  font-weight: 600;
  cursor: grab;
}
body.popup .topbar { display: none; }
body.popup main { padding-top: 12px; }
.save-url { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; margin: 0 0 4px; }

.item-image { display: block; max-width: 100%; max-height: 420px; margin-top: 8px; border-radius: 8px; background: var(--bg); }

.digest-row { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.digest-row input[type="time"] { width: auto; min-width: 8.5em; flex-shrink: 0; }
.digest-row .hint { margin: 0; }

.digest-sections { margin: 10px 0 0 26px; }
.digest-sections .hint { margin: 0 0 2px; }
.check.sub { font-weight: normal; margin: 4px 0; font-size: 0.95rem; }

/* ---- Mind page: card grid ---- */
main { transition: max-width 0.15s ease; }
main.wide { max-width: 1680px; }
.mind-top { max-width: 720px; margin: 0 auto; }
.filter-bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.filter-bar .filters { margin-bottom: 0; }
.layout-switch { display: flex; gap: 6px; flex-shrink: 0; }
.layout-switch .chip { font-size: 0.85rem; }

.items.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(400px, 100%), 1fr));
  grid-auto-rows: 4px;  /* GRID_ROW in app.js */
  column-gap: 14px;     /* GRID_GAP in app.js */
  align-items: start;   /* cards keep their natural height; app.js sizes their row span */
}
.items.grid > .item { margin-bottom: 0; }
.items.grid > .empty { grid-column: 1 / -1; }
.items:not(.grid) { max-width: 720px; margin: 0 auto; }
/* Narrow cards: keep thumbnails from crowding the text. */
.items.grid .item-thumb { width: 72px; height: 56px; }
.items.grid .embed-frame.tall { max-width: 100%; }
/* One column either way on a phone, so the Grid/List switch has nothing to do. */
@media (max-width: 700px) { .layout-switch { display: none; } }

/* ---- Drag to rearrange (Mind page) ---- */
.drag-handle {
  border: none; background: none; padding: 0 6px 0 0; margin: 0;
  color: var(--muted); font-size: 1rem; line-height: 1;
  cursor: grab; touch-action: none;  /* so a finger drag moves the card instead of scrolling */
}
.drag-handle:hover, .drag-handle:focus-visible { color: var(--accent); }
.items.no-drag .drag-handle { display: none; }
.item.dragging {
  position: relative; z-index: 2;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  outline: 2px solid var(--accent);
  opacity: 0.95;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }

/* ---- Admin console ---- */
.admin-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.admin-head h1 { font-size: 1.4rem; margin: 0; }
.admin-tabs .chip { text-decoration: none; }
.admin-user { padding: 12px 14px; margin-bottom: 10px; }
.admin-user.disabled { opacity: 0.65; }
.admin-user-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-user-info { min-width: 0; }
.admin-user-name { font-weight: 600; overflow-wrap: anywhere; }
.badge { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 5px; background: var(--bg); border: 1px solid var(--border); font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.actions.tight { margin-top: 0; gap: 6px; }
.temp-password { margin-top: 10px; padding: 8px 10px; border-radius: 7px; border: 1px solid #e0b84c; background: rgba(224, 184, 76, 0.15); font-size: 0.9rem; }
.temp-password code { font-weight: 700; user-select: all; }
.danger-box { margin-top: 10px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); font-size: 0.9rem; }
.danger-box p { margin: 6px 0; }
.confirm-row { display: flex; gap: 8px; margin: 6px 0 10px; }
.confirm-row input { flex: 1; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
/* Text-style delete links (cards, list editor) stay plain text, not red buttons. */
button.link.danger { background: none; border: none; padding: 0; color: var(--muted); }
button.link.danger:hover { color: var(--danger); }
button.danger:disabled { opacity: 0.4; cursor: not-allowed; }
button.danger-outline { color: var(--danger); border-color: var(--danger); }
.error-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; overflow-wrap: anywhere; }
.center { text-align: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); column-gap: 14px; }
.section-title { font-size: 1rem; margin: 22px 0 10px; }

/* ---- Edit window ---- */
.item.editable { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.item.editable:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.item-tools { display: flex; gap: 12px; }
.item-tools button.link { font-size: 0.8rem; }
.item-tools button.link:not(.danger) { color: var(--muted); }
.item-tools button.link:not(.danger):hover { color: var(--accent); }
dialog.editor {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}
dialog.editor::backdrop { background: rgba(0, 0, 0, 0.45); }
.editor-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.editor-head h2 { margin: 0; font-size: 1.15rem; }
.editor-head h2 .muted { font-weight: normal; font-size: 0.95rem; }
.editor-head button.link { color: var(--muted); font-size: 1.1rem; }
.field-link { align-self: center; white-space: nowrap; font-size: 0.9rem; }
.edit-image { display: block; max-width: 100%; max-height: 240px; margin: 14px auto 0; border-radius: 8px; }
.entry-edit { list-style: none; padding: 0; margin: 0 0 8px; }
.entry-edit li { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.entry-edit li input:not([type]) { flex: 1; padding: 6px 9px; }
.entry-edit li button.link { padding: 0 4px; font-size: 0.95rem; }
.editor .msg:empty { display: none; }

/* ---- Pins, archive, trash, shared lists ---- */
.item-head { align-items: center; }
/* One line: the tools always fit, and a long label is cut short with "…". */
.item-head > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-tools { gap: 10px; align-items: center; flex-shrink: 0; white-space: nowrap; }
.item-tools button.pin { font-size: 0.85rem; line-height: 1; }
.item-tools button.pin:not(.on) { filter: grayscale(1); opacity: 0.45; }
.item-tools button.pin:not(.on):hover { opacity: 0.9; }
.item.pinned { border-top: 3px solid var(--accent); }
.item-head .badge { margin-left: 6px; padding: 0 6px; font-size: 0.7rem; }
.item-shared { margin-top: 6px; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.chip-gap { flex: 0 0 4px; }
.state-note { margin: -4px 0 14px; font-size: 0.9rem; text-align: center; }
.shared-box { margin-bottom: 18px; }
.shared-box .section-title { max-width: 720px; margin: 0 auto 10px; font-size: 1rem; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  padding: 10px 14px 10px 16px; border-radius: 9px;
  background: var(--text); color: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); font-size: 0.92rem;
}
.toast button.link { color: var(--surface); font-weight: 700; text-decoration: underline; }
.toast button.toast-close { font-weight: normal; text-decoration: none; opacity: 0.7; }
main.wide .shared-box .section-title { max-width: none; }
