:root {
  color-scheme: light;
  --bg: #f4f0e6; --surface: #fffdf8; --surface-2: #ece7da; --ink: #1c1b18; --muted: #6a665c; --line: #ddd7c8;
  --brand: #14513a; --brand-ink: #ffffff; --accent: #c8372d; --ok: #1f7a4d; --warn: #a76a00; --no: #b3261e;
  --shadow: 0 1px 2px rgb(40 30 10 / .08), 0 6px 18px rgb(40 30 10 / .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121513; --surface: #1b1f1c; --surface-2: #272c28; --ink: #f0ede4; --muted: #a5a79e; --line: #343a35;
    --brand: #2d9b6c; --brand-ink: #08130d; --accent: #ef6a5f; --ok: #54c48d; --warn: #e0a83a; --no: #f2776d;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121513; --surface: #1b1f1c; --surface-2: #272c28; --ink: #f0ede4; --muted: #a5a79e; --line: #343a35;
  --brand: #2d9b6c; --brand-ink: #08130d; --accent: #ef6a5f; --ok: #54c48d; --warn: #e0a83a; --no: #f2776d;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 ui-rounded, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.3rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
a { color: var(--brand); }
p { margin: 0 0 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
img, video { max-width: 100%; display: block; }
.boot { padding: 48px; text-align: center; color: var(--muted); }

/* layout */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
.side { position: sticky; top: 0; height: 100dvh; overflow-y: auto; padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.1rem; padding: 4px 8px 14px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.nav-link { position: relative; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: inherit; text-decoration: none; font-weight: 550; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.on { background: var(--brand); color: var(--brand-ink); }
.nav-link svg { width: 21px; height: 21px; flex: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); min-height: 56px; }
.top h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page { width: 100%; max-width: 780px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.page.wide { max-width: 1040px; }
.tabs-bottom { display: none; }
.badge { min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.nav-link .badge { margin-left: auto; }

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 13px; border-radius: 10px; cursor: pointer; font-weight: 600; text-decoration: none; color: inherit; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn.danger { color: var(--no); }
.btn.sm { padding: 4px 9px; min-height: 32px; font-size: .88rem; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg, .file-chip svg, .event-row svg, .list-item > svg, .avatar svg { width: 18px; height: 18px; flex: none; }
.btn { white-space: nowrap; }
.btn.yes.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.no.on { background: var(--no); border-color: var(--no); color: #fff; }
.btn.maybe.on { background: var(--warn); border-color: var(--warn); color: #fff; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 10px; cursor: pointer; display: inline-grid; place-items: center; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .badge { position: absolute; top: 0; right: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; min-width: 0; }
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), select, textarea { width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 400; min-width: 0; }
input[type=color] { width: 56px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
textarea { resize: vertical; min-height: 44px; }
label.check { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; background: var(--surface-2); font-size: .82rem; font-weight: 600; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip.dot::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--brand)); flex: none; }
.chip.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.chip.no { background: color-mix(in srgb, var(--no) 16%, transparent); color: var(--no); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; object-fit: cover; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.avatar.sm { width: 28px; height: 28px; font-size: .7rem; }
.avatar.lg { width: 84px; height: 84px; font-size: 1.6rem; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; color: inherit; text-decoration: none; min-width: 0; }
a.list-item:hover { background: var(--surface-2); }
.list-item + .list-item { border-top: 1px solid var(--line); border-radius: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.segmented { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.segmented a, .segmented button { padding: 7px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: inherit; font-weight: 600; font-size: .9rem; white-space: nowrap; cursor: pointer; }
.segmented .on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachments img, .attachments video { max-height: 300px; border-radius: 10px; }
.attachments audio { max-width: 100%; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--surface-2); border-radius: 8px; text-decoration: none; color: inherit; font-size: .88rem; max-width: 100%; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.reaction { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 1px 8px; font-size: .9rem; cursor: pointer; }
.reaction.mine { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 16%, transparent); }
.comment { display: flex; gap: 8px; }
.comment .bubble { background: var(--surface-2); border-radius: 12px; padding: 6px 10px; min-width: 0; }

/* chat */
.chat { display: flex; flex-direction: column; height: calc(100dvh - 57px); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 8px; max-width: 88%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 7px 11px; min-width: 0; }
.msg.mine .bubble { background: color-mix(in srgb, var(--brand) 16%, var(--surface)); }
.msg .meta { font-size: .75rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg .tools { display: flex; gap: 2px; flex-wrap: wrap; }
.msg .meta button { background: none; border: 0; color: inherit; font: inherit; padding: 0; cursor: pointer; text-decoration: underline dotted; }
.msg .tools button { color: var(--muted); font-size: .78rem; padding: 2px 5px; text-decoration: none; }
.msg .tools button:hover { color: var(--ink); }
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; position: relative; }
.composer .row { align-items: flex-end; }
.mention-pop { position: absolute; bottom: 100%; left: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 200px; overflow-y: auto; z-index: 5; min-width: 200px; }
.mention-pop button { display: block; width: 100%; text-align: left; padding: 8px 12px; background: none; border: 0; cursor: pointer; }
.mention-pop button:hover { background: var(--surface-2); }
.unread { background: var(--accent); color: #fff; border-radius: 10px; font-size: .75rem; font-weight: 700; padding: 1px 7px; }

/* calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-head { text-align: center; font-size: .78rem; color: var(--muted); font-weight: 700; padding: 4px 0; }
.cal-day { min-height: 76px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; overflow: hidden; text-align: left; }
.cal-day.other { opacity: .45; }
.cal-day.today .num { background: var(--brand); color: var(--brand-ink); border-radius: 50%; }
.cal-day.sel { outline: 2px solid var(--brand); outline-offset: -1px; }
.cal-day .num { width: 22px; height: 22px; display: grid; place-items: center; font-size: .78rem; font-weight: 700; }
.cal-ev { font-size: .7rem; padding: 0 4px; border-radius: 4px; background: color-mix(in srgb, var(--c, var(--brand)) 24%, transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev.x { text-decoration: line-through; opacity: .6; }
.event-row { display: flex; gap: 10px; padding: 10px; border-left: 4px solid var(--c, var(--brand)); background: var(--surface); border-radius: 10px; color: inherit; text-decoration: none; min-width: 0; border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.event-row:hover { background: var(--surface-2); }
.event-row time { flex: none; width: 54px; text-align: center; font-weight: 700; font-size: .85rem; }
.event-row.canceled strong { text-decoration: line-through; }

/* results */
.bar-row { display: grid; gap: 2px; }
.bar { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .8rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat b { font-size: 1.55rem; display: block; }
.member-card { max-width: 360px; margin: 0 auto; background: linear-gradient(145deg, #14513a, #0d3526); color: #fff; border-radius: 20px; padding: 22px; display: flex; flex-direction: column; gap: 14px; align-items: center; text-align: center; }
.member-card .qr { background: #fff; padding: 12px; border-radius: 12px; }
.member-card .qr svg { display: block; width: 190px; height: 190px; }

/* overlays */
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 16px; padding: 18px; width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; width: calc(100% - 32px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 9px 15px; border-radius: 10px; font-size: .92rem; max-width: 100%; }
.toast.err { background: var(--no); color: #fff; }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--brand); }
.auth .card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 12px; }
.auth img { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto; }
.err { color: var(--no); font-size: .92rem; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { font-size: .85rem; }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .side { display: none; }
  .tabs-bottom { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabs-bottom a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 2px; font-size: .68rem; font-weight: 600; color: var(--muted); text-decoration: none; }
  .tabs-bottom a.on { color: var(--brand); }
  .tabs-bottom svg { width: 23px; height: 23px; }
  .tabs-bottom .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
  .chat { height: calc(100dvh - 57px - 60px - env(safe-area-inset-bottom)); }
  .cal-day { min-height: 54px; }
  .cal-ev { height: 6px; padding: 0; font-size: 0; }
  .page { padding: 12px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}
@media print { .side, .tabs-bottom, .top, .noprint { display: none !important; } .shell { display: block; } .card { box-shadow: none; } }
