:root {
  --bg: #f4f4f1; --card: #ffffff; --text: #1d1d1b; --muted: #6b6a66; --faint: #9a9993;
  --line: rgba(0,0,0,.10); --line2: rgba(0,0,0,.18); --soft: #ecebe6;
  --green: #0F6E56; --green-bg: #E1F5EE; --green-tx: #085041; --green-mid: #1D9E75;
  --amber-bg: #FAEEDA; --amber-tx: #633806; --amber-bd: #FAC775; --amber-mid: #854F0B;
  --red-bg: #FCEBEB; --red-tx: #791F1F; --red-bd: #F7C1C1;
  --a-bg: #EEEDFE; --a-tx: #3C3489; --b-bg: #FBEAF0; --b-tx: #72243E; --c-bg: #E1F5EE; --c-tx: #085041;
  --d-bg: #FAECE7; --d-tx: #712B13; --e-bg: #E6F1FB; --e-tx: #0C447C;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211; --card: #1e1e1d; --text: #f1f0ec; --muted: #a9a8a2; --faint: #75746f;
    --line: rgba(255,255,255,.10); --line2: rgba(255,255,255,.2); --soft: #2a2a28;
    --green: #2FB58C; --green-bg: #0b3a2e; --green-tx: #9FE1CB; --green-mid: #2FB58C;
    --amber-bg: #3d2a08; --amber-tx: #FAC775; --amber-bd: #854F0B; --amber-mid: #EF9F27;
    --red-bg: #3d1414; --red-tx: #F7C1C1; --red-bd: #791F1F;
    --a-bg: #2c2766; --a-tx: #CECBF6; --b-bg: #4b1528; --b-tx: #F4C0D1; --c-bg: #0b3a2e; --c-tx: #9FE1CB;
    --d-bg: #4A1B0C; --d-tx: #F5C4B3; --e-bg: #042C53; --e-tx: #B5D4F4;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--green); text-decoration: none; }

#app { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-t) + 12px) 14px calc(84px + var(--safe-b)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 2px 12px; }
.top h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -.3px; }
.iconbtn { background: none; border: 0; padding: 6px; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.link { background: none; border: 0; color: var(--green); font-weight: 600; padding: 6px 2px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); font-size: 13px; }
.faint { color: var(--faint); font-size: 13px; }
.label { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 4px 8px; text-transform: none; }
.label:first-child { margin-top: 4px; }
.clip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.b { font-weight: 600; }
.hidden { display: none !important; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat .n { font-size: 20px; font-weight: 700; }
.stat.amber { background: var(--amber-bg); border-color: var(--amber-bd); color: var(--amber-tx); }
.stat.red { background: var(--red-bg); border-color: var(--red-bd); color: var(--red-tx); }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); white-space: nowrap; cursor: pointer; }
.pill.ok, .pill.on { background: var(--green-bg); color: var(--green-tx); border-color: transparent; }
.pill.wt { background: var(--amber-bg); color: var(--amber-tx); border-color: transparent; }
.pill.er { background: var(--red-bg); color: var(--red-tx); border-color: transparent; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: 0 0 9px !important; }
.dot.on { background: var(--green-mid); } .dot.warn { background: #EF9F27; } .dot.err { background: #E24B4A; }

.tag { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; font-size: 15px; }
.t0 { background: var(--a-bg); color: var(--a-tx); } .t1 { background: var(--b-bg); color: var(--b-tx); } .t2 { background: var(--c-bg); color: var(--c-tx); }
.t3 { background: var(--d-bg); color: var(--d-tx); } .t4 { background: var(--e-bg); color: var(--e-tx); } .t5 { background: var(--soft); color: var(--muted); }

.msg { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.msg .body { flex: 1; min-width: 0; }

.btn { border: 1px solid var(--line2); background: var(--card); border-radius: 12px; padding: 12px 14px; font-weight: 600; cursor: pointer; text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: #c0392b; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; white-space: nowrap; }
.btn:disabled { opacity: .5; }
.btns { display: grid; grid-template-columns: 1fr 1.5fr; gap: 8px; }

input[type=text], input[type=number], input[type=search], input[type=date], input[type=time], input[type=datetime-local], input[type=password], input[type=tel], select, textarea {
  width: 100%; border: 1px solid var(--line2); background: var(--card); border-radius: 10px; padding: 10px 12px; font-size: 16px; outline: none; min-height: 42px;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); }
textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > * { flex: 1; }
.inline > .shrink { flex: 0 0 auto; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--soft); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 8px 4px; border-radius: 8px; font-size: 14px; cursor: pointer; color: var(--muted); }
.seg button.sel { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.section h2 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 8px; }
.section h2 .num { width: 22px; height: 22px; border-radius: 50%; background: var(--green); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.sub { background: var(--soft); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 10px; }

.toolbar { display: flex; gap: 4px; flex-wrap: wrap; }
.toolbar button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; min-width: 36px; height: 34px; cursor: pointer; }

.attach { display: flex; gap: 8px; flex-wrap: wrap; }
.att { width: 64px; height: 64px; border-radius: 10px; background: var(--soft); position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 11px; text-align: center; color: var(--muted); }
.att img, .att video { width: 100%; height: 100%; object-fit: cover; }
.att .x { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; cursor: pointer; }
.att.add { border: 1.5px dashed var(--line2); background: none; cursor: pointer; font-size: 22px; }

.bubble { background: #d9fdd3; color: #111b21; border-radius: 10px 10px 2px 10px; padding: 8px 10px; white-space: pre-wrap; word-wrap: break-word; max-width: 90%; align-self: flex-end; font-size: 14.5px; }
@media (prefers-color-scheme: dark) { .bubble { background: #005c4b; color: #e9edef; } }
.bubble code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.chatbg { background: #efeae2; border-radius: 10px; padding: 10px; display: flex; flex-direction: column; }
@media (prefers-color-scheme: dark) { .chatbg { background: #0b141a; } }

.grp { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; }
.grp .nm { flex: 1; min-width: 0; }
.grp.paused { background: var(--amber-bg); border-color: var(--amber-bd); color: var(--amber-tx); }
.grp.locked { opacity: .6; }
.ck { width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--line2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: #fff; font-size: 14px; }
.ck.on { background: var(--green); border-color: var(--green); }
.pz { width: 34px; height: 34px; border-radius: 50%; border: 0; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; background: var(--amber-bg); color: var(--amber-tx); font-size: 14px; }
.grp.paused .pz { background: var(--card); color: var(--green-tx); }

.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.days button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 0; font-size: 13px; cursor: pointer; }
.days button.on { background: var(--green-bg); color: var(--green-tx); border-color: transparent; font-weight: 600; }

.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line2); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--green-mid); }
.switch input:checked + span::before { transform: translateX(20px); }

.nav { position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 8px 0 calc(8px + var(--safe-b)); z-index: 10; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--faint); min-width: 80px; }
.nav a .i { font-size: 22px; line-height: 1; }
.nav a.on { color: var(--green); }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; max-height: 85dvh; overflow: auto; }
.sheet h3 { margin: 0 0 4px; font-size: 17px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; max-width: 90%; text-align: center; }
.toast.err { background: #A32D2D; }

.lock { min-height: 80dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; }
.pins { display: flex; gap: 14px; }
.pins span { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--line2); }
.pins span.f { background: var(--text); border-color: var(--text); }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; }
.keypad button { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--card); font-size: 26px; cursor: pointer; }
.keypad button.blank { background: none; }
.logo { width: 64px; height: 64px; border-radius: 16px; background: var(--green); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 30px; }

.qr { background: #fff; padding: 10px; border-radius: 12px; align-self: center; }
.qr img { width: 240px; height: 240px; display: block; }
.warn { background: var(--amber-bg); color: var(--amber-tx); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.err-box { background: var(--red-bg); color: var(--red-tx); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.ok-box { background: var(--green-bg); color: var(--green-tx); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.deliv { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.spacer { height: 8px; }
