:root {
  --bg: #f6f7fb; --card: #ffffff; --text: #0f172a; --muted: #5b6475; --line: #e3e6ee;
  --primary: #1d4ed8; --primary-ink: #ffffff; --free: #15803d; --free-bg: #e8f7ee; --warn: #b45309; --warn-bg: #fff4e5;
  --danger: #b91c1c; --danger-bg: #fdecec; --done: #475569; --done-bg: #eef1f6; --shadow: 0 8px 30px rgba(15, 23, 42, .12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #141c2e; --text: #e8ecf5; --muted: #9aa5bd; --line: #26314a;
    --primary: #6d8cff; --primary-ink: #0b1220; --free: #4ade80; --free-bg: #12301f; --warn: #fbbf24; --warn-bg: #3a2a08;
    --danger: #f87171; --danger-bg: #3b1515; --done: #a9b4c9; --done-bg: #1c2538; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --card: #141c2e; --text: #e8ecf5; --muted: #9aa5bd; --line: #26314a;
  --primary: #6d8cff; --primary-ink: #0b1220; --free: #4ade80; --free-bg: #12301f; --warn: #fbbf24; --warn-bg: #3a2a08;
  --danger: #f87171; --danger-bg: #3b1515; --done: #a9b4c9; --done-bg: #1c2538; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 860px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h3 { font-size: 1.25rem; margin: 0 0 .2rem; }
.muted { color: var(--muted); } .small { font-size: .9rem; } .error { color: var(--danger); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.login-card { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: .95rem; }
label.inline { display: flex; align-items: center; gap: 8px; }
input, select, textarea, button { font: inherit; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); }
textarea { min-height: 84px; resize: vertical; }
.btn { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.link { border: none; background: none; color: var(--primary); padding: 4px 6px; }
.btn[disabled] { opacity: .5; cursor: progress; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 6px; gap: 12px; }
.brand { font-weight: 700; font-size: 1.15rem; }
.who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; font-size: .95rem; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 12px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.tab { flex: 1; padding: 12px 6px; border: none; background: none; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; font-weight: 600; position: relative; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.badge { position: absolute; top: 6px; right: 10px; background: var(--danger); color: #fff; border-radius: 999px; font-size: .72rem; padding: 1px 6px; }
.toolbar { display: flex; gap: 8px; }
.toolbar input { flex: 1; }
.list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.list li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; cursor: pointer; }
.list li:hover { border-color: var(--primary); }
.rowl { display: flex; gap: 12px; align-items: center; min-width: 0; }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: 0 0 44px; background: var(--line); }
.avatar.ini { display: inline-flex; align-items: center; justify-content: center; font-size: .9rem; font-weight: 700; color: var(--muted); }
.list .name { font-weight: 600; }
.list .sub { color: var(--muted); font-size: .92rem; }
.list li > div:last-child { flex: 0 0 auto; max-width: 52%; text-align: right; }
.pill { display: inline-block; font-size: .86rem; line-height: 1.25; padding: 5px 11px; border-radius: 14px; border: 1px solid transparent; font-weight: 600; text-align: right; max-width: 100%; }
.pill.free { color: var(--free); background: var(--free-bg); }
.pill.done { color: var(--done); background: var(--done-bg); }
.pill.team { color: #fff; }
.pill.owned { background: var(--card); border-width: 2px; }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill small { display: block; font-weight: 400; opacity: .9; font-size: .8rem; }
.qbadge { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.events li { padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: .95rem; }
.events .meta { color: var(--muted); font-size: .85rem; }
.ev-type { font-weight: 600; margin-right: 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-top: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; border-left: 6px solid var(--line); }
.stat .n { font-size: 1.5rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .88rem; }
.capbar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; margin-top: 8px; }
.capbar > div { height: 100%; background: var(--primary); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row input { flex: 1; min-width: 140px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.grid2 button { grid-column: span 2; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } .grid2 button { grid-column: span 1; } }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.sheet[hidden] { display: none; }
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet-panel { position: relative; width: 100%; max-width: 680px; max-height: 92vh; overflow: auto; background: var(--card); border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-panel { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.sheet-id { display: flex; gap: 16px; align-items: center; min-width: 0; }
.sheet-photo { width: 112px; height: 136px; border-radius: 14px; object-fit: cover; object-position: top; flex: 0 0 112px; background: var(--line); box-shadow: 0 4px 14px rgba(15, 23, 42, .18); }
.sheet-photo.ini { display: inline-flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; color: var(--muted); }
.sheet-photo.small { width: 88px; height: 88px; flex-basis: 88px; border-radius: 50%; object-position: center; }
@media (min-width: 700px) { .sheet-photo.small { width: 96px; height: 96px; flex-basis: 96px; } }
@media (min-width: 700px) { .sheet-photo { width: 140px; height: 170px; flex-basis: 140px; } }
.status-card { border-radius: 12px; padding: 12px 14px; margin: 12px 0; border: 1px solid var(--line); }
.status-card.free { background: var(--free-bg); border-color: transparent; }
.status-card.warn { background: var(--warn-bg); border-color: transparent; }
.status-card.done { background: var(--done-bg); border-color: transparent; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .95rem; margin: 8px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.timeline li { padding-left: 14px; border-left: 2px solid var(--line); font-size: .93rem; }
.timeline .meta { color: var(--muted); font-size: .84rem; }
.inlineform { display: grid; gap: 8px; margin: 10px 0; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }
.candidates li { cursor: default; flex-direction: column; align-items: stretch; }
.help .callout { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--primary); border-radius: 12px; padding: 14px 16px; margin: 12px 0 16px; font-size: 1.05rem; }
.help details { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px; margin: 10px 0; }
.help summary { cursor: pointer; font-weight: 700; padding: 10px 0; list-style: none; display: flex; align-items: center; gap: 8px; }
.help summary::-webkit-details-marker { display: none; }
.help summary::before { content: "▸"; color: var(--muted); font-size: .9rem; transition: transform .15s; }
.help details[open] summary::before { transform: rotate(90deg); }
.help ol, .help ul { padding-left: 1.3rem; margin: 4px 0 12px; }
.help li { margin: 6px 0; }
.help b { font-weight: 600; color: var(--primary); }
.empty { color: var(--muted); padding: 12px; text-align: center; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.swbtn { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; margin: 8px 0 14px; }
.pal { background: none; border: 2px solid transparent; border-radius: 12px; padding: 8px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text); }
.pal .dot { width: 40px; height: 40px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.pal .lbl { font-size: .8rem; color: var(--muted); }
.pal:hover { border-color: var(--line); }
.pal.sel { border-color: var(--text); }
.pal.sel .lbl { color: var(--text); font-weight: 600; }
.picker .preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.picker input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 14px; border-radius: 7px; border: 1px solid var(--line); padding: 0; background: var(--line); }
.picker input[type="range"].hue { background: linear-gradient(90deg, hsl(0,80%,45%), hsl(60,80%,45%), hsl(120,80%,40%), hsl(180,80%,40%), hsl(240,80%,50%), hsl(300,80%,45%), hsl(360,80%,45%)); }
.picker input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: var(--card); border: 2px solid var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .3); cursor: pointer; }
.picker input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--card); border: 2px solid var(--text); cursor: pointer; }
