:root {
  --bg: #ffffff;
  --fg: #202124;
  --muted: #5f6368;
  --border: #e0e0e0;
  --hover: rgba(95, 99, 104, 0.12);
  --active-nav: #feefc3;
  --shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 2px 6px 2px rgba(60, 64, 67, 0.15);
  --pop-bg: #ffffff;
  --accent: #f6bf26;
  --check: #5f6368;
  --c-default: #ffffff; --c-coral: #faafa8; --c-peach: #f39f76; --c-sand: #fff8b8;
  --c-mint: #e2f6d3; --c-sage: #b4ddd3; --c-fog: #d4e4ed; --c-storm: #aeccdc;
  --c-dusk: #d3bfdb; --c-blossom: #f6e2dd; --c-clay: #e9e3d4; --c-chalk: #efeff1;
  --sidebar-w: 280px;
  --sidebar-w-collapsed: 72px;
  font-family: "Google Sans", Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124;
    --fg: #e8eaed;
    --muted: #9aa0a6;
    --border: #5f6368;
    --hover: rgba(232, 234, 237, 0.08);
    --active-nav: #41331c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.6), 0 2px 6px 2px rgba(0, 0, 0, 0.3);
    --pop-bg: #2d2e30;
    --check: #9aa0a6;
    --c-default: #202124; --c-coral: #77172e; --c-peach: #692b17; --c-sand: #7c4a03;
    --c-mint: #264d3b; --c-sage: #0c625d; --c-fog: #256377; --c-storm: #284255;
    --c-dusk: #472e5b; --c-blossom: #6c394f; --c-clay: #4b443a; --c-chalk: #232427;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font-size: 14px; line-height: 1.45; }
body.modal-open { overflow: hidden; }
button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.color-default { background: var(--c-default); } .color-coral { background: var(--c-coral); }
.color-peach { background: var(--c-peach); } .color-sand { background: var(--c-sand); }
.color-mint { background: var(--c-mint); } .color-sage { background: var(--c-sage); }
.color-fog { background: var(--c-fog); } .color-storm { background: var(--c-storm); }
.color-dusk { background: var(--c-dusk); } .color-blossom { background: var(--c-blossom); }
.color-clay { background: var(--c-clay); } .color-chalk { background: var(--c-chalk); }

/* ---------- icons & buttons ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.text-btn {
  border: 0; background: transparent; padding: 8px 20px; border-radius: 4px;
  font-weight: 500; cursor: pointer; color: var(--fg);
}
.text-btn:hover { background: var(--hover); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px;
  display: flex; align-items: center; gap: 4px; padding: 8px 12px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 200px; padding-right: 24px; font-size: 22px; color: var(--muted); }
.brand img { width: 36px; height: 36px; }
#viewTitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.search {
  flex: 1; max-width: 720px; height: 46px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-radius: 8px; background: var(--hover); cursor: text;
}
.search:focus-within { background: var(--bg); box-shadow: var(--shadow); }
.search-icon svg { width: 22px; height: 22px; fill: var(--muted); display: block; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 16px; min-width: 0; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; padding-left: 12px; }
.avatar {
  width: 32px; height: 32px; margin-left: 8px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #1a73e8; color: #fff; font-weight: 600; font-size: 15px; border: 0; padding: 0; cursor: pointer;
}
.account-pop { min-width: 200px; padding: 4px; }
.account-name { padding: 4px 8px 10px; color: var(--muted); font-size: 13px; }
.account-pop .text-btn { width: 100%; text-align: left; padding: 8px; }

/* ---------- sign-in ---------- */
#loginRoot:empty { display: none; }
#loginRoot {
  position: fixed; inset: 0; z-index: 300; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
body.signed-out { overflow: hidden; }
.login-card {
  width: 100%; max-width: 360px; padding: 36px 32px 32px; border: 1px solid var(--border);
  border-radius: 12px; display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card img { align-self: center; }
.login-card h1 { margin: 0; font-size: 24px; font-weight: 500; }
.login-sub { margin: -8px 0 6px; color: var(--muted); }
.login-card label { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 13px; color: var(--muted); }
.login-card input {
  height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; font-size: 16px; outline: 0;
}
.login-card input:focus { border-color: #1a73e8; box-shadow: 0 0 0 1px #1a73e8; }
.login-btn {
  margin-top: 8px; height: 44px; border: 0; border-radius: 6px; background: #1a73e8; color: #fff;
  font-weight: 600; font-size: 15px; cursor: pointer;
}
.login-btn:disabled { opacity: 0.7; cursor: default; }
.login-error { background: rgba(217, 48, 37, 0.1); color: #d93025; border-radius: 6px; padding: 8px 12px; font-size: 13px; text-align: left; }
@media (prefers-color-scheme: dark) { .login-error { color: #f28b82; } }

/* ---------- layout & sidebar ---------- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: 64px; flex: none; width: var(--sidebar-w);
  height: calc(100vh - 64px); overflow-y: auto; padding: 8px 0; transition: width 0.15s;
}
.nav-item {
  display: flex; align-items: center; gap: 20px; width: calc(100% - 12px); height: 48px;
  padding: 0 12px 0 24px; border: 0; border-radius: 0 24px 24px 0; background: transparent;
  cursor: pointer; text-align: left; font-size: 14px; font-weight: 500; color: var(--fg);
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active-nav); }
.nav-icon svg { width: 24px; height: 24px; fill: var(--muted); display: block; }
.nav-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .nav-item { width: 48px; margin-left: 12px; padding: 0 12px; border-radius: 50%; }
body.sidebar-collapsed .nav-text { display: none; }
.scrim { display: none; }

main { flex: 1; min-width: 0; padding: 32px 16px 80px; }

/* ---------- composer & editor ---------- */
.composer-wrap { max-width: 600px; margin: 0 auto 32px; }
.composer.collapsed {
  display: flex; align-items: center; padding: 2px 4px 2px 16px; border-radius: 8px;
  box-shadow: var(--shadow); background: var(--c-default);
}
.composer-placeholder { flex: 1; padding: 12px 0; font-size: 16px; font-weight: 500; color: var(--muted); cursor: text; outline: none; }

.editor { border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; }
.editor.composer { border: 1px solid transparent; }
.editor-top { display: flex; align-items: flex-start; padding: 8px 4px 0 16px; }
.title-input, .body-input, .item-text {
  display: block; width: 100%; border: 0; outline: 0; resize: none; background: transparent;
  overflow: hidden; padding: 0;
}
.title-input { flex: 1; padding: 10px 0 6px; font-size: 18px; font-weight: 500; line-height: 1.4; }
.body-input { padding: 6px 16px 12px; font-size: 15px; line-height: 1.5; min-height: 46px; }
.title-input::placeholder, .body-input::placeholder, .item-text::placeholder { color: var(--muted); }
.pin-btn.active, .card-pin.active { color: var(--fg); }
.pin-btn.active svg, .card-pin.active svg { transform: rotate(0); }
.pin-btn svg, .card-pin svg { transform: rotate(45deg); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px 10px; max-width: 100%;
  border: 0; border-radius: 12px; background: rgba(0, 0, 0, 0.08); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .chip { background: rgba(255, 255, 255, 0.12); } }
.chip .chip-x { width: 18px; height: 18px; margin-right: -6px; }
.chip .chip-x svg { width: 14px; height: 14px; }

.editor-footer { display: flex; align-items: center; gap: 8px; padding: 4px 8px 6px; }
.toolbar { display: flex; flex-wrap: wrap; }
.toolbar .icon-btn { width: 34px; height: 34px; }
.toolbar .icon-btn svg { width: 18px; height: 18px; }
.edited { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.editor-footer .text-btn { margin-left: auto; }
.edited + .text-btn { margin-left: 0; }

/* checklist */
.checklist { padding: 4px 0 8px; }
.check-row { display: flex; align-items: flex-start; gap: 6px; padding: 2px 8px 2px 16px; }
.check-row:hover .item-del { visibility: visible; }
.item-del { visibility: hidden; }
.item-check { margin: 4px 4px 0 0; width: 16px; height: 16px; flex: none; accent-color: var(--check); cursor: pointer; }
.item-text { flex: 1; padding: 2px 0; font-size: 15px; line-height: 1.5; }
.item-text.done { text-decoration: line-through; color: var(--muted); }
.add-row { border-top: 1px solid transparent; border-bottom: 1px solid transparent; }
.add-row:focus-within { border-color: var(--border); }
.add-plus svg { width: 18px; height: 18px; fill: var(--muted); display: block; margin: 3px 4px 0 -1px; }
.done-toggle {
  display: block; margin: 6px 0 2px; padding: 6px 16px 6px 40px; border: 0; width: 100%;
  border-top: 1px solid var(--border); background: transparent; text-align: left;
  color: var(--muted); cursor: pointer; font-size: 14px;
}

/* ---------- grid & cards ---------- */
.content { max-width: 1280px; margin: 0 auto; }
.section-title { margin: 24px 0 8px 8px; font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.grid { columns: 240px; column-gap: 16px; }
.layout-list .grid { columns: auto; max-width: 600px; margin: 0 auto; }
.layout-list .section-title { max-width: 600px; margin-left: auto; margin-right: auto; }

.card {
  position: relative; display: block; width: 100%; break-inside: avoid; margin: 0 0 16px;
  border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px 4px;
  cursor: default; transition: box-shadow 0.15s; outline: none;
}
.card:not(.color-default) { border-color: transparent; }
.card:hover, .card:focus-visible { box-shadow: var(--shadow); }
.card-title { font-size: 16px; font-weight: 500; line-height: 1.4; margin: 0 32px 8px 0; word-wrap: break-word; }
.card-body { font-size: 14px; white-space: pre-wrap; word-wrap: break-word; max-height: 360px; overflow: hidden; margin-bottom: 8px; }
.card-title + .card-body { margin-top: -2px; }
.card-empty { color: var(--muted); font-size: 20px; padding: 6px 0 14px; }
.card-items { margin-bottom: 8px; }
.card-item { display: flex; align-items: flex-start; gap: 8px; padding: 2px 0; cursor: pointer; }
.card-item input { margin: 3px 0 0; accent-color: var(--check); flex: none; cursor: pointer; }
.card-item span { word-wrap: break-word; min-width: 0; }
.card-more { color: var(--muted); padding: 2px 0 0 24px; font-size: 13px; }
.card .chips { padding: 0 0 6px; }
.card-pin { position: absolute; top: 4px; right: 4px; opacity: 0; width: 34px; height: 34px; }
.card-pin.active, .card:hover .card-pin, .card:focus-within .card-pin { opacity: 1; }
.card-toolbar { display: flex; gap: 2px; margin: 0 -8px; opacity: 0; transition: opacity 0.15s; }
.card:hover .card-toolbar, .card:focus-within .card-toolbar { opacity: 1; }
.card-toolbar .icon-btn { width: 34px; height: 34px; }
.card-toolbar .icon-btn svg { width: 18px; height: 18px; }
@media (hover: none) { .card-toolbar, .card-pin { opacity: 1; } }

.empty { text-align: center; color: var(--muted); padding: 12vh 16px 0; }
.empty-icon svg { width: 120px; height: 120px; fill: currentColor; opacity: 0.2; }
.empty p { font-size: 22px; margin: 16px 0; }
.loading { text-align: center; color: var(--muted); padding: 10vh 0; }
.fatal { max-width: 520px; margin: 10vh auto; text-align: center; }
.fatal h2 { font-weight: 500; }
.fatal p { color: var(--muted); line-height: 1.6; }
.fatal .text-btn { border: 1px solid var(--border); }
.trash-bar { display: flex; align-items: center; justify-content: center; gap: 16px; font-style: italic; color: var(--muted); margin-bottom: 24px; }
.trash-bar .text-btn { font-style: normal; color: #1a73e8; }

/* ---------- popovers ---------- */
.popover {
  position: absolute; z-index: 100; background: var(--pop-bg); color: var(--fg);
  border-radius: 8px; box-shadow: var(--shadow); padding: 8px;
}
.swatches { display: grid; grid-template-columns: repeat(6, 32px); gap: 4px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.swatch.color-default { border-color: var(--border); }
.swatch:hover { border-color: var(--fg); }
.swatch.selected { border-color: #a142f4; }
.swatch svg { width: 16px; height: 16px; fill: var(--fg); }
.label-pop { width: 240px; }
.pop-title { font-size: 14px; padding: 4px 4px 8px; }
.pop-title.big { font-size: 16px; font-weight: 500; padding: 0 0 12px; }
.label-search { width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent; padding: 4px; outline: 0; font-size: 13px; }
.label-list { max-height: 240px; overflow-y: auto; padding-top: 6px; }
.label-row { display: flex; align-items: center; gap: 10px; padding: 5px 4px; cursor: pointer; font-size: 13px; }
.label-row input { accent-color: var(--check); }
.label-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-create { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 4px; border: 0; border-top: 1px solid var(--border); background: transparent; cursor: pointer; text-align: left; font-size: 13px; }
.label-create svg { width: 18px; height: 18px; fill: var(--muted); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(32, 33, 36, 0.6);
  display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; overflow-y: auto;
}
.editor.modal { width: 600px; max-width: 100%; max-height: 80vh; overflow-y: auto; }
.editor.modal .body-input { min-height: 80px; }
.editor.modal .editor-footer { position: sticky; bottom: 0; background: inherit; border-radius: 0 0 8px 8px; }
.labels-dialog { width: 320px; max-width: 100%; background: var(--pop-bg); border-radius: 8px; box-shadow: var(--shadow); padding: 16px 12px 4px; }
.label-edit-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.label-edit-row input { flex: 1; border: 0; border-bottom: 1px solid transparent; background: transparent; padding: 6px 2px; outline: 0; font-weight: 500; min-width: 0; }
.label-edit-row input:focus { border-bottom-color: var(--border); }
.row-icon { width: 40px; display: inline-flex; justify-content: center; }
.row-icon svg { width: 18px; height: 18px; fill: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 24px; bottom: 24px; z-index: 200; display: flex; align-items: center; gap: 24px;
  max-width: calc(100vw - 48px); padding: 14px 16px 14px 24px; border-radius: 4px;
  background: #323232; color: #fff; box-shadow: var(--shadow);
}
.toast-action { border: 0; background: transparent; color: #fdd663; font-weight: 600; cursor: pointer; padding: 4px 8px; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .brand { min-width: 0; padding-right: 8px; }
  .brand img { display: none; }
  #viewTitle { font-size: 18px; max-width: 110px; }
  #refreshBtn, #layoutBtn { display: none; }
  .sidebar {
    position: fixed; top: 64px; left: 0; z-index: 30; background: var(--bg);
    transform: translateX(-100%); transition: transform 0.2s; visibility: hidden;
  }
  .brand { display: none; }
  body.sidebar-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow); }
  body.sidebar-open .scrim { display: block; position: fixed; inset: 64px 0 0; z-index: 25; background: rgba(0, 0, 0, 0.3); }
  main { padding: 16px 8px 80px; }
  .grid { columns: 2; column-gap: 8px; }
  .card { margin-bottom: 8px; padding: 10px 12px 2px; }
  .modal-overlay { padding: 0; }
  .editor.modal { width: 100%; max-height: 100vh; min-height: 100vh; border-radius: 0; }
  .toast { left: 12px; right: 12px; bottom: 12px; }
}
