:root {
  --bg: #f6f3ef; --card: #ffffff; --text: #2b2420; --muted: #8a7f77; --line: #ebe4dc;
  --accent: #8b5e3c; --accent-2: #f1e6dc; --ok: #2f8f5b; --ok-bg: #e3f3ea; --warn: #b7791f; --warn-bg: #fbf0dc;
  --bad: #c0392b; --bad-bg: #fbe5e2; --info-bg: #e6eef8; --info: #2c5d93;
  --radius: 14px; --tabs-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1a18; --card: #282320; --text: #f1ebe5; --muted: #a89c92; --line: #3a332e;
    --accent: #d39a6a; --accent-2: #3b2f27; --ok-bg: #1f3529; --warn-bg: #3b3020; --bad-bg: #3d2420; --info-bg: #1f2b3a;
    --ok: #59c08a; --warn: #e3a74a; --bad: #ef7a6b; --info: #8db8ec; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { padding-bottom: calc(var(--tabs-h) + var(--safe-b)); min-height: 100vh; }
body.no-tabs { padding-bottom: var(--safe-b); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

#top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: var(--bg); border-bottom: 1px solid var(--line); min-height: 52px; }
#top h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: var(--accent-2); color: var(--accent); width: 36px; height: 36px; border-radius: 10px;
  font-size: 24px; line-height: 1; cursor: pointer; }

main { padding: 12px 12px 24px; max-width: 760px; margin: 0 auto; }
.center { text-align: center; padding: 40px 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

#tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--tabs-h) + var(--safe-b)); }
#tabs button { flex: 1; border: 0; background: none; font-size: 11px; color: var(--muted); display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; position: relative; }
#tabs button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
#tabs button.active { color: var(--accent); font-weight: 600; }
#tabs button.active span { filter: none; opacity: 1; }
#tabs .dot { position: absolute; top: 6px; right: calc(50% - 20px); background: var(--bad); color: #fff; font-size: 10px;
  border-radius: 9px; min-width: 18px; padding: 1px 5px; font-weight: 700; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  border: 1px solid var(--line); }
.card h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .grow { flex: 1; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; }
.stat b { display: block; font-size: 24px; }
.stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); } .stat.ok b { color: var(--ok); }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.row .right { text-align: right; white-space: nowrap; font-size: 13px; }
.row.static { cursor: default; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--accent-2); color: var(--accent); }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.info { background: var(--info-bg); color: var(--info); }
.chip.gray { background: var(--line); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--accent); color: #fff; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn.block { width: 100%; }
.btn.sec { background: var(--accent-2); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns.end { justify-content: flex-end; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=search], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 11px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.seg { display: flex; background: var(--accent-2); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 12px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; font-size: 13px; color: var(--accent);
  white-space: nowrap; cursor: pointer; }
.seg button.active { background: var(--card); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; }

.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); } .banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--info-bg); color: var(--info); }

.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { max-width: 85%; padding: 8px 11px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; }
.msg.in { background: var(--card); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.sys { background: var(--info-bg); color: var(--info); align-self: center; font-size: 12px; text-align: center; }
.msg .meta { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }
.composer { position: sticky; bottom: calc(var(--tabs-h) + var(--safe-b)); background: var(--bg); padding: 8px 0 4px;
  display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 160px; flex: 1; }

.prog { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.prog i { display: block; height: 100%; background: var(--ok); }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-b) + 14px);
  background: #2b2420; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 30; max-width: 92vw;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
#toast.err { background: var(--bad); }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 16px 14px calc(16px + var(--safe-b)); }
.sheet h3 { margin: 0 0 12px; font-size: 17px; }
.linkbox { word-break: break-all; background: var(--card); border: 1px dashed var(--line); border-radius: 10px; padding: 10px;
  font-size: 13px; margin: 6px 0; user-select: all; }
.kv { display: grid; grid-template-columns: 42% 58%; gap: 6px 10px; font-size: 14px; }
.kv div:nth-child(odd) { color: var(--muted); }
.hero { text-align: center; padding: 24px 8px 12px; }
.hero .logo { width: 72px; height: 72px; border-radius: 18px; }
.hero h2 { margin: 10px 0 4px; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 14px; }
.month-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.month-nav b { flex: 1; text-align: center; font-size: 16px; text-transform: capitalize; }
details.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.item > summary { list-style: none; padding: 12px 14px; cursor: pointer; }
details.item > summary::-webkit-details-marker { display: none; }
details.item .body { padding: 0 14px 10px; }
.toggle3 { display: flex; gap: 4px; }
.toggle3 button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 5px 8px; font-size: 12px; cursor: pointer; }
.toggle3 button.on.done { background: var(--ok); color: #fff; border-color: var(--ok); }
.toggle3 button.on.na { background: var(--muted); color: #fff; border-color: var(--muted); }
