:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1b2a2e;
  --muted: #62747a;
  --line: #e2ddd1;
  --line-strong: #cbc4b3;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #dff3ef;
  --confirm-soft: #d6f0ea;
  --confirm-ink: #0b4f49;
  --maybe: #b7791f;
  --maybe-soft: #fff3d1;
  --maybe-ink: #6b4a0a;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .06);
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181a;
    --card: #1a2326;
    --ink: #e8eeee;
    --muted: #9aaaae;
    --line: #2a373b;
    --line-strong: #3d4d52;
    --accent: #2dd4bf;
    --accent-ink: #06322d;
    --accent-soft: #123b36;
    --confirm-soft: #123f39;
    --confirm-ink: #bdf3e9;
    --maybe: #e0a526;
    --maybe-soft: #392e10;
    --maybe-ink: #f6dd9b;
    --danger: #ff8a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.error { color: var(--danger); font-size: 14px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
button.primary, button.ghost, button.danger {
  border-radius: 10px; padding: 9px 14px; border: 1px solid transparent; font-weight: 600;
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; border-color: var(--line-strong); }
button.ghost:hover { background: var(--accent-soft); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.small { padding: 5px 10px; font-size: 13px; }
button.link { background: none; border: 0; color: var(--accent); padding: 4px; text-decoration: underline; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 14px;
}

/* ---------- header / tabs / toolbar ---------- */
.top { padding: 16px 0 6px; }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 22px; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.sticky {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--line); padding-bottom: 8px;
}
.tabs { display: flex; gap: 6px; padding-top: 6px; overflow-x: auto; }
.tabs button {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  flex: 1 1 0; min-width: 0; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.count { font-weight: 700; opacity: .8; }
.count:empty { display: none; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.toolbar .ghost { padding: 6px 12px; }
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700;
}
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.filter-panel {
  margin-top: 8px; padding: 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); display: grid; gap: 14px; max-height: 45vh; overflow-y: auto;
}
.filter-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.mode {
  border: 1px solid var(--line-strong); background: transparent; border-radius: 999px;
  padding: 2px 10px; font-size: 12px;
}

/* ---------- chips / toggles ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle, .chip-radio span {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--card); font-size: 14px; user-select: none;
}
.chip-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip-radio { cursor: pointer; }
.chip-radio input { position: absolute; opacity: 0; pointer-events: none; }
.chip-radio input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip-radio input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-radio.potential input:checked + span { background: var(--maybe-soft); border: 1px dashed var(--maybe); color: var(--maybe-ink); }

.pill {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px;
  font-size: 12.5px; background: var(--accent-soft); color: var(--ink); border: 1px solid transparent;
}
.pill.person { background: transparent; border-color: var(--line-strong); }

/* ---------- main ---------- */
main { padding-top: 14px; padding-bottom: 110px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.key { display: inline-block; width: 26px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 6px; }
.key.confirmed { background: var(--confirm-soft); border: 1px solid var(--accent); border-left-width: 4px; }
.key.potential { background: var(--maybe-soft); border: 1px dashed var(--maybe); }

.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

.divider {
  display: flex; align-items: center; gap: 6px; margin: 6px 0 5px; color: var(--muted);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px dashed var(--line-strong); }

/* ---------- month grid ---------- */
.grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.dow { background: var(--card); padding: 6px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.day { background: var(--card); min-height: 128px; padding: 4px; display: flex; flex-direction: column; gap: 3px; }
.day.out {
  background: repeating-linear-gradient(135deg, var(--bg), var(--bg) 6px, var(--line) 6px, var(--line) 7px);
  opacity: .6;
}
.day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.day-head { display: flex; align-items: center; justify-content: space-between; }
.num { font-weight: 700; font-size: 13px; padding: 0 4px; }
.add {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line-strong);
  background: transparent; line-height: 1; opacity: .55; padding: 0;
}
.add:hover, .add:focus-visible { opacity: 1; background: var(--accent-soft); }
.day-events { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.chip-ev {
  display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 4px; width: 100%; text-align: left; min-width: 0;
  padding: 3px 6px; border-radius: 6px; font-size: 12px; line-height: 1.25; border: 1px solid;
}
.chip-ev .ev-ppl { flex-basis: 100%; }
.chip-ev.confirmed { background: var(--confirm-soft); color: var(--confirm-ink); border-color: var(--accent); border-left-width: 4px; }
.chip-ev.potential { background: var(--maybe-soft); color: var(--maybe-ink); border: 1px dashed var(--maybe); }
.ev-time { font-weight: 700; white-space: nowrap; }
.ev-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-ppl { font-size: 11px; white-space: nowrap; }

/* ---------- agenda (list view) + cards ---------- */
.agenda { display: grid; gap: 12px; }
.a-day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; }
.a-day.today { box-shadow: 0 0 0 2px var(--accent); }
.a-day header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.a-day h3 { font-size: 16px; }
.a-day .add { width: 30px; height: 30px; opacity: 1; }
.a-day .stack { display: grid; gap: 8px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; display: grid; gap: 6px; min-width: 0;
}
.card.confirmed { background: var(--confirm-soft); border-color: var(--accent); border-left-width: 5px; color: var(--confirm-ink); }
.card.potential { background: var(--maybe-soft); border: 1px dashed var(--maybe); color: var(--maybe-ink); }
.card-head { display: flex; gap: 8px; align-items: baseline; }
.card-title { font-weight: 700; flex: 1; overflow-wrap: anywhere; }
.card .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13.5px; }
.card .meta a { color: inherit; }
.card .notes { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.card .row-pills { display: flex; flex-wrap: wrap; gap: 5px; }
.card .row-pills .pill { color: var(--ink); }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.card-actions button { padding: 5px 10px; font-size: 13px; }
.status-badge { font-size: 12px; font-weight: 700; }

.cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.section-title:first-child { margin-top: 0; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: 32px; line-height: 1; box-shadow: 0 6px 18px rgba(0, 0, 0, .3); z-index: 15;
}

/* ---------- dialog / forms ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; background: var(--card); color: var(--ink);
  width: min(580px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
#editor-form { padding: 18px; display: grid; gap: 14px; }
#editor-form h2 { font-size: 20px; }

.field { display: grid; gap: 5px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > label, .field > legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; }
input[type=text], input:not([type]), input[type=password], input[type=date], input[type=time], textarea {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--bg); min-width: 0;
}
textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; color: var(--ink); cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.cal-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; gap: 12px; }
.cal-box > div { display: grid; gap: 12px; margin-top: 8px; }
.status { margin-top: 2px; }

.tagbox {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--bg);
}
.tagbox input { flex: 1; min-width: 120px; border: 0; background: transparent; padding: 4px 6px; outline: none; }
.tagbox:focus-within { outline: 2px solid var(--accent); }
.tagbox .pill button { border: 0; background: none; padding: 0 0 0 2px; font-size: 15px; line-height: 1; }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px;
  display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }

/* ---------- responsive ---------- */
.a-day .chip-ev { font-size: 14px; padding: 7px 9px; }

@media (max-width: 759px) {
  #view-toggle { display: none; }
  .top h1 { font-size: 20px; white-space: nowrap; }
  #sync { display: none; }
  .tabs button { min-width: 0; padding: 9px 4px; font-size: 13.5px; gap: 4px; }
  .row { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: 1fr; }
}
