:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #ececea;
  --text: #16171a;
  --muted: #6d6f75;
  --line: #e2e2df;
  --accent: #16171a;
  --accent-text: #ffffff;
  --danger: #d93b3b;
  --warn-bg: #fff4dc;
  --warn-text: #8a5a00;
  --radius: 14px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1012;
    --surface: #1a1b1f;
    --surface-2: #26272c;
    --text: #f1f1f2;
    --muted: #9a9ba2;
    --line: #2c2d33;
    --accent: #f1f1f2;
    --accent-text: #111214;
    --warn-bg: #3a2c0e;
    --warn-text: #ffcf70;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
#app { min-height: 100vh; }
.page {
  max-width: 760px; margin: 0 auto;
  padding: calc(var(--safe-t) + 18px) 16px calc(var(--tabbar) + var(--safe-b) + 28px);
}
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top .muted { font-size: 13px; margin-bottom: 2px; }
section { margin-top: 22px; }
section > h2 { margin: 0 0 8px 2px; display: flex; justify-content: space-between; align-items: center; }
section > h2 a, section > h2 button { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); font-size: 13px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: 11px; gap: 3px; position: relative;
}
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.on { color: var(--text); }
.tabbar .badge { position: absolute; top: 8px; left: calc(50% + 6px); }
.fab {
  position: fixed; right: max(16px, calc(50% - 364px)); bottom: calc(var(--tabbar) + var(--safe-b) + 16px); z-index: 21;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.22);
}
.fab svg { width: 26px; height: 26px; }

/* ---------- Cards / lists ---------- */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; background: var(--surface); min-height: 56px;
}
.card .bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--c, var(--muted)); flex: none; }
.card .time { width: 46px; flex: none; font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600; }
.card .time .end { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.card .main { flex: 1; min-width: 0; }
.card .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.done .title { text-decoration: line-through; color: var(--muted); }
.card.dim { opacity: .55; }
.empty { padding: 18px 14px; color: var(--muted); text-align: center; background: var(--surface); border-radius: var(--radius); }

.who { display: flex; gap: 3px; flex: none; }
.ini {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 5px;
  border-radius: 13px; background: var(--surface-2); font-size: 11px; font-weight: 700; letter-spacing: .02em;
}
.ini.me { background: var(--accent); color: var(--accent-text); }
.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.pill.imp { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.pill.ws { background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); }
.badge { min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; display: inline-grid; place-items: center; }

.day-head { padding: 14px 4px 6px; font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; }
.day-head.today { color: var(--danger); }
.absent-line { font-size: 12.5px; color: var(--muted); padding: 2px 4px 6px; }

.attn { display: flex; gap: 10px; align-items: center; padding: 12px 14px; background: var(--warn-bg); color: var(--warn-text); width: 100%; text-align: left; }
.attn + .attn { border-top: 1px solid color-mix(in srgb, var(--warn-text) 18%, transparent) !important; }
.attn b { font-weight: 600; }

/* ---------- To-dos ---------- */
.todo { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; background: var(--surface); }
.todo .txt { flex: 1; min-width: 0; }
.todo .txt small { display: block; color: var(--muted); font-size: 12.5px; }
.todo.done .txt > span { text-decoration: line-through; color: var(--muted); }
.check {
  appearance: none; -webkit-appearance: none; width: 22px; height: 22px; flex: none; margin: 1px 0 0;
  border: 2px solid var(--muted); border-radius: 50%; display: grid; place-items: center; cursor: pointer;
}
.check:checked { background: var(--accent); border-color: var(--accent); }
.check:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-text); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }

/* ---------- Segments / chips ---------- */
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 6px 10px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13.5px; font-weight: 500;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip.off { opacity: .45; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head h1 { flex: 1; font-size: 24px; }
.iconbtn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface); }
.iconbtn svg { width: 20px; height: 20px; }
.textbtn { padding: 7px 12px; border-radius: 10px; background: var(--surface); font-weight: 600; font-size: 13.5px; }
.month { background: var(--surface); border-radius: var(--radius); padding: 8px 6px 10px; margin-top: 12px; }
.month .wd, .month .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.month .wd div { text-align: center; font-size: 11.5px; color: var(--muted); font-weight: 600; padding: 4px 0 6px; }
.mday { aspect-ratio: 1 / 1.02; display: flex; flex-direction: column; align-items: center; padding-top: 5px; gap: 4px; border-radius: 10px; }
.mday .n { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; font-size: 15px; font-variant-numeric: tabular-nums; }
.mday.other .n { color: var(--muted); opacity: .5; }
.mday.today .n { color: var(--danger); font-weight: 700; }
.mday.sel .n { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.mday .dots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 34px; }
.mday .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.mday .abs { width: 18px; height: 2px; border-radius: 2px; background: var(--muted); opacity: .6; }

/* ---------- Overlay sheets ---------- */
#overlay:empty { display: none; }
.sheet {
  position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slideup .22s ease-out;
}
#overlay.noanim .sheet { animation: none; }
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 10px) 12px 10px; background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.sheet-bar .grow { flex: 1; text-align: center; font-weight: 600; }
.sheet-body { max-width: 680px; margin: 0 auto; padding: 4px 16px calc(var(--safe-b) + 40px); }
.d-head { background: var(--surface); border-radius: var(--radius); padding: 16px; border-top: 5px solid var(--c); }
.d-head h1 { font-size: 23px; margin: 8px 0 6px; }
.d-when { font-size: 15px; }
.d-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.d-people { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.person { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 99px; background: var(--surface-2); font-size: 13.5px; }
.block { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-top: 12px; }
.block h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.block h3 small { font-weight: 500; }
.block .text { white-space: pre-wrap; word-wrap: break-word; }
.block.cta { display: flex; gap: 12px; align-items: center; background: var(--warn-bg); color: var(--warn-text); }
.block.cta p { margin: 0; flex: 1; }
.inline-edit { width: 100%; border: 0; background: transparent; resize: none; min-height: 24px; padding: 0; outline: none; white-space: pre-wrap; }
.inline-edit::placeholder { color: var(--muted); }
.cl { list-style: none; margin: 0; padding: 0; }
.cl li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.cl li:first-child { border-top: 0; }
.cl li .t { flex: 1; min-width: 0; }
.cl li.done .t { text-decoration: line-through; color: var(--muted); }
.cl li select { min-height: 0; width: auto; border: 0; background: var(--surface-2); border-radius: 8px; padding: 3px 6px; font-size: 12px; font-weight: 700; max-width: 70px; }
.cl .x { color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; }
.cl-add { display: flex; gap: 8px; margin-top: 8px; }
.cl-add input { flex: 1; }
.files a { display: flex; align-items: center; gap: 10px; padding: 8px 0; text-decoration: none; border-top: 1px solid var(--line); }
.files a:first-child { border-top: 0; }
.files .ficon { width: 34px; height: 40px; border-radius: 6px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; display: grid; place-items: center; flex: none; }
.files .x { margin-left: auto; color: var(--muted); font-size: 20px; padding: 0 6px; }
.pdf-frame { width: 100%; height: 60vh; border: 0; border-radius: 10px; margin-top: 8px; background: var(--surface-2); }
.status-row { display: flex; gap: 6px; flex-wrap: wrap; }
.danger-zone { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, input[type=text], input[type=email], input[type=date], input[type=time], input[type=url], input[type=number], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface);
  outline: none; -webkit-appearance: none; appearance: none; min-height: 44px;
}
input[type=date], input[type=time] { min-width: 0; }
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--muted); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--surface); border-radius: 12px; }
.toggle div small { display: block; color: var(--muted); font-size: 12.5px; }
.switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--surface-2); position: relative; flex: none; cursor: pointer; transition: background .15s; border: 1px solid var(--line); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch:checked { background: #34c759; border-color: #34c759; }
.switch:checked::after { transform: translateX(18px); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 12px; font-weight: 600; background: var(--accent); color: var(--accent-text); min-height: 46px;
}
.btn.sec { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.small { padding: 7px 12px; min-height: 0; font-size: 13.5px; border-radius: 10px; }
.btn.block-btn { width: 100%; }
.btn:disabled { opacity: .5; }
.warnbox { padding: 10px 12px; border-radius: 11px; background: var(--warn-bg); color: var(--warn-text); font-size: 13.5px; }
.more-link { font-size: 13.5px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; align-self: flex-start; }

/* ---------- Settings ---------- */
.set-group { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 50px; width: 100%; text-align: left; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row .lbl { flex: 1; min-width: 0; }
.set-row .lbl small { display: block; color: var(--muted); font-size: 12.5px; }
.set-row input[type=time] { width: auto; min-height: 34px; padding: 5px 8px; }
.codebox { font: 12px/1.4 ui-monospace, Menlo, monospace; word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 10px; }
.matrix { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.matrix th, .matrix td { padding: 8px 4px; text-align: center; border-top: 1px solid var(--line); }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.matrix input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.team-card { padding: 12px 14px; display: grid; grid-template-columns: 1fr 86px; gap: 8px; align-items: center; }
.team-card + .team-card { border-top: 1px solid var(--line); }
.team-card .full { grid-column: 1 / -1; }
.team-card input { min-height: 38px; padding: 8px 10px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .box { width: 100%; max-width: 380px; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 18px; }
.login h1 { margin-bottom: 6px; }
.login p { color: var(--muted); margin: 0 0 22px; }
.code-input { font-size: 26px !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- Misc ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-b) + 84px); transform: translateX(-50%) translateY(20px);
  background: var(--accent); color: var(--accent-text); padding: 10px 16px; border-radius: 12px; font-weight: 500; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
#toast.on { opacity: 1; transform: translateX(-50%); }
.syncdot { width: 9px; height: 9px; border-radius: 50%; background: #34c759; display: inline-block; }
.syncdot.pending { background: #ff9f0a; }
.syncdot.offline { background: var(--muted); }
.statusline { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); padding: 6px 10px; background: var(--surface); border-radius: 99px; }
.install-hint { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: var(--surface); border-radius: var(--radius); margin-top: 14px; }
.install-hint p { margin: 0; flex: 1; font-size: 13.5px; }
@media (min-width: 900px) {
  .page { padding-top: 36px; }
}

.abs-link { color: inherit; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; font-size: inherit; }
.absent-line { padding: 4px 4px 8px; }
