:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #15181d;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2f6df6;
  --accent-soft: #e8f0ff;
  --done: #15a06a;
  --danger: #d8453c;
  --high: #e4761b;
  --radius: 14px;
  --tabbar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #21252d;
    --text: #e8eaee;
    --muted: #949aa6;
    --border: #2a2f38;
    --accent: #4b86ff;
    --accent-soft: #1b2740;
    --done: #2bbd84;
    --danger: #f06a60;
    --high: #f0943a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }

/* ---------------------------------------------------------------- login */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 24px; width: 100%; max-width: 340px;
  text-align: center;
}
.gate-mark {
  width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 16px;
  background: var(--accent); color: #fff; font-size: 28px;
  display: grid; place-items: center;
}
.gate-card h1 { font-size: 21px; margin: 0 0 4px; }
.gate-card p { margin: 0 0 18px; }
.gate-card input {
  width: 100%; padding: 12px 14px; font-size: 16px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--bg); color: var(--text);
}

/* --------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 0;
}
.topbar-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.topbar h1 { font-size: 26px; margin: 0; letter-spacing: -0.4px; }
.topbar p { margin: 2px 0 0; }
.progress { height: 3px; background: var(--surface-2); border-radius: 3px; margin: 12px 0 0; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--done); transition: width .25s ease; }

.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 10px; font-size: 17px; cursor: pointer;
  display: grid; place-items: center; flex: none;
}

/* ---------------------------------------------------------------- views */
/* Bottom gap clears the floating + button and the tab bar. */
.view { padding: 14px 16px 96px; }
.daynav { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 12px; }
.section-h { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 22px 0 8px; }
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filters select {
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px;
}
.check { display: flex; gap: 7px; align-items: center; font-size: 14px; color: var(--muted); }

/* ---------------------------------------------------------------- cards */
.list { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 13px;
}
.card.is-done { opacity: .55; }
.card.is-high { border-left: 3px solid var(--high); }
.card.is-overdue { border-left: 3px solid var(--danger); }
.tick {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--border); background: transparent; cursor: pointer;
  display: grid; place-items: center; color: transparent; font-size: 14px; font-weight: 700;
  transition: background .15s, border-color .15s;
}
.tick.on { background: var(--done); border-color: var(--done); color: #fff; }
.card-main { flex: 1; min-width: 0; }
.card-title { font-size: 15px; font-weight: 550; word-break: break-word; }
.card.is-done .card-title { text-decoration: line-through; }
.card-notes { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.chip {
  font-size: 11.5px; padding: 2.5px 7px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.time { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.chip.streak { background: color-mix(in srgb, var(--done) 16%, transparent); color: var(--done); }
.card-edit {
  flex: none; background: none; border: 0; color: var(--muted);
  font-size: 18px; cursor: pointer; padding: 0 2px; line-height: 1;
}

.empty { text-align: center; padding: 48px 20px; }
.empty p { margin: 4px 0; }

/* ----------------------------------------------------------------- logs */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; text-align: center;
}
.stat b { display: block; font-size: 22px; letter-spacing: -0.5px; }
.stat span { font-size: 11px; color: var(--muted); white-space: nowrap; }

.heatmap { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.hm {
  aspect-ratio: 1; border-radius: 5px; background: var(--surface-2);
  display: grid; place-items: center; font-size: 10px; color: var(--muted);
}
.hm[data-level="1"] { background: color-mix(in srgb, var(--done) 28%, var(--surface-2)); color: #fff; }
.hm[data-level="2"] { background: color-mix(in srgb, var(--done) 55%, var(--surface-2)); color: #fff; }
.hm[data-level="3"] { background: color-mix(in srgb, var(--done) 80%, var(--surface-2)); color: #fff; }
.hm[data-level="4"] { background: var(--done); color: #fff; }

.loglist { display: flex; flex-direction: column; gap: 1px; }
.logrow {
  display: flex; gap: 10px; align-items: baseline;
  background: var(--surface); border: 1px solid var(--border);
  padding: 9px 12px; font-size: 13.5px;
}
.logrow:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.logrow:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.logrow:only-child { border-radius: var(--radius); }
.logrow .when { color: var(--muted); font-size: 12px; white-space: nowrap; flex: none; min-width: 86px; }
.logrow .what { flex: 1; min-width: 0; }
.logrow .act { font-weight: 600; }
.act-completed { color: var(--done); }
.act-created { color: var(--accent); }
.act-deleted, .act-reminder_failed { color: var(--danger); }
.act-skipped, .act-archived { color: var(--high); }

.kv { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; }
.kv span:last-child { color: var(--muted); text-align: right; word-break: break-all; }

/* ------------------------------------------------------- fab and tabbar */
.fab {
  position: fixed; right: 18px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 54px; height: 54px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); cursor: pointer; z-index: 30;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  background: none; border: 0; color: var(--muted); font-size: 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tab span { font-size: 18px; line-height: 1; }
.tab.active { color: var(--accent); }

/* --------------------------------------------------------------- sheets */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; max-height: 92vh; display: flex; flex-direction: column;
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border); flex: none;
}
.sheet-body {
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.sheet-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 20px 0 8px; }
.sheet-body h3:first-child { margin-top: 0; }
.sheet-body label, .sheet-body .label {
  display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 12px;
}
.sheet-body input, .sheet-body select, .sheet-body textarea {
  display: block; width: 100%; margin-top: 5px; padding: 11px 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 11px;
}
.sheet-body textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.daypicker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin: 5px 0 12px; }
.daypicker button {
  padding: 9px 0; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 12px; cursor: pointer;
}
.daypicker button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* -------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 10px 14px; border-radius: 11px; font: inherit; font-weight: 550; cursor: pointer;
}
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 76px);
  background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: 20px; font-size: 13.5px; z-index: 80; max-width: 90vw; text-align: center;
}

/* =======================================================================
   Accounts, groups, chat and the calendar
   ======================================================================= */

/* Five tabs now, not three. */
.tabbar { grid-template-columns: repeat(5, 1fr); }
.tab { position: relative; }

.topbar-text { flex: 1; min-width: 0; }
.topbar h1 { word-break: break-word; }

.gate-card form input { margin-bottom: 10px; }
.gate-card form input:last-of-type { margin-bottom: 14px; }
.center { text-align: center; }
.note {
  margin: 12px 0 0; padding: 10px 12px; font-size: 13px; text-align: left;
  background: var(--accent-soft); color: var(--accent); border-radius: 10px;
}
.linkbtn {
  background: none; border: 0; padding: 0; font: inherit; font-size: inherit;
  color: var(--accent); cursor: pointer; text-decoration: underline;
}
.linkbtn.danger { color: var(--danger); }

/* ------------------------------------------------------------- badges */
.badge {
  display: inline-block; min-width: 18px; padding: 1px 5px; margin-left: 6px;
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
  vertical-align: middle;
}
.tab .badge { position: absolute; top: 4px; right: 50%; margin-right: -22px; }

/* --------------------------------------------------- segmented control */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--surface-2); border-radius: 12px;
}
.seg {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 8px 4px; border-radius: 9px; cursor: pointer;
}
.seg.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* --------------------------------------------------------- extra chips */
.chip.group { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.chip.who { background: var(--surface-2); font-weight: 600; }
.chip.ok { background: color-mix(in srgb, var(--done) 16%, transparent); color: var(--done); }

/* ------------------------------------------------------------ meetings */
.card.is-meeting { border-left: 3px solid var(--accent); align-items: center; }
.when-col {
  flex: none; min-width: 66px; font-size: 12.5px; font-weight: 650;
  color: var(--accent); line-height: 1.3;
}

/* ------------------------------------------------------------ calendar */
.cal-dow {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  margin-bottom: 5px; text-align: center;
}
.cal-dow span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
  position: relative; aspect-ratio: 1 / 1; min-height: 42px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 3px; padding: 5px 2px 2px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font: inherit; cursor: pointer;
}
.cal-cell.faded { opacity: .38; }
.cal-cell.is-today { border-color: var(--accent); }
.cal-cell.selected { background: var(--accent-soft); border-color: var(--accent); }
.cal-cell .num { font-size: 13px; font-weight: 600; line-height: 1; }
.cal-cell.is-today .num { color: var(--accent); }
.cal-cell .marks { display: flex; gap: 2px; align-items: center; min-height: 6px; }
.cal-cell .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.cal-cell .dot.shared { background: var(--accent); }
.cal-cell .more { font-size: 9px; color: var(--muted); font-style: normal; line-height: 1; }
.cal-cell .tasknum {
  position: absolute; right: 3px; bottom: 2px;
  font-size: 9.5px; font-weight: 700; color: var(--done);
}

/* ----------------------------------------------------- group task tally */
.tally { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.tally-row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.tally-name { flex: none; width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tally-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.tally-bar i { display: block; height: 100%; background: var(--done); transition: width .25s ease; }
.tally-num { flex: none; color: var(--muted); font-size: 12px; min-width: 34px; text-align: right; }

/* ---------------------------------------------------------------- chat */
.chatlog {
  display: flex; flex-direction: column; gap: 8px;
  /* Leave room for the fixed composer and the tab bar below it. */
  min-height: 40vh; max-height: calc(100vh - 300px);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 0 8px;
}
.chat-row { display: flex; }
.chat-row.mine { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 8px 11px 6px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
}
.chat-row.mine .bubble { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-who { font-size: 11.5px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.chat-body { font-size: 14.5px; word-break: break-word; white-space: pre-wrap; }
.chat-time { font-size: 10.5px; opacity: .6; text-align: right; margin-top: 2px; }
.chat-system {
  text-align: center; font-size: 12px; color: var(--muted);
  padding: 2px 10px;
}
.composer { display: flex; gap: 8px; align-items: center; padding-top: 8px; }
.composer input {
  flex: 1; min-width: 0; padding: 11px 13px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 22px;
}

/* -------------------------------------------------------------- groups */
.card.tappable { cursor: pointer; align-items: center; }
.card.tappable:active { background: var(--surface-2); }
.chev { flex: none; color: var(--muted); font-size: 22px; line-height: 1; }

.codebox { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.codebox code {
  flex: none; padding: 9px 13px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 17px; font-weight: 700; letter-spacing: 2px;
}
.inline-form { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.inline-form input {
  flex: 1; min-width: 0; padding: 10px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 11px;
}

.logrow .who { font-weight: 650; }
.logrow .when { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.act-event_created, .act-event_updated { color: var(--accent); }
.act-event_deleted { color: var(--danger); }
.act-joined_group, .act-group_created { color: var(--done); }

/* A member row carries more than the old log row did; let it breathe. */
#member-list .what, #admin-users .what { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
