:root {
  --bg: #f4f6f8; --surface: #fff; --surface-2: #f8fafb; --border: #e2e7ec; --text: #17212b; --muted: #627080;
  --primary: #0f766e; --primary-h: #0b5f59; --primary-soft: #e3f3f1; --danger: #c2410c; --danger-soft: #fdeee6;
  --warn: #a16207; --warn-soft: #fdf6dc; --ok: #15803d; --ok-soft: #e5f5ea; --info: #1d4ed8; --info-soft: #e8efff;
  --bubble: #d9fdd3; --chat: #efeae2; --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418; --surface: #161d23; --surface-2: #1b242b; --border: #26323b; --text: #e6edf2; --muted: #93a2b0;
    --primary: #2bb3a5; --primary-h: #3cc6b8; --primary-soft: #133a37; --danger: #f08455; --danger-soft: #3a2118;
    --warn: #e2b34a; --warn-soft: #382e14; --ok: #4ccb7c; --ok-soft: #15301f; --info: #7aa2ff; --info-soft: #1a2546;
    --bubble: #005c4b; --chat: #0b141a; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand img { width: 28px; height: 28px; }
.nav a { display: block; padding: 8px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.side .foot { margin-top: auto; padding: 10px 12px; font-size: 12.5px; color: var(--muted); }
.main { padding: 26px 32px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head .sub { color: var(--muted); margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stack > * + * { margin-top: 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

label.f { display: block; font-weight: 600; margin-bottom: 5px; }
.field + .field { margin-top: 14px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
textarea { resize: vertical; min-height: 120px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.checks { display: grid; gap: 6px; max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.checks label { display: flex; gap: 8px; align-items: center; }

.alert { padding: 11px 14px; border-radius: 8px; border: 1px solid transparent; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; display: flex; min-width: 120px; }
.progress span { display: block; height: 100%; }
.progress .s { background: var(--ok); } .progress .f { background: var(--danger); } .progress .k { background: var(--muted); opacity: .5; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.phone { background: var(--chat); border-radius: 14px; padding: 18px 14px; min-height: 220px; position: sticky; top: 20px; }
.bubble { background: var(--bubble); border-radius: 10px 10px 10px 2px; padding: 8px 10px 18px; max-width: 92%; white-space: pre-wrap; word-wrap: break-word; position: relative; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.bubble img { display: block; max-width: 100%; border-radius: 6px; margin-bottom: 6px; }
.bubble .file { background: rgba(0,0,0,.06); padding: 8px; border-radius: 6px; margin-bottom: 6px; font-size: 13px; }
.bubble time { position: absolute; right: 8px; bottom: 3px; font-size: 11px; opacity: .6; }

.conn { display: flex; gap: 16px; align-items: flex-start; }
.qr { background: #fff; padding: 10px; border-radius: 10px; border: 1px solid var(--border); }
.qr img { width: 240px; height: 240px; display: block; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 8px 12px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 600; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--muted); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10,15,20,.45); }
dialog .dh { padding: 16px 18px 0; font-weight: 700; font-size: 16px; }
dialog .db { padding: 14px 18px; }
dialog .df { padding: 12px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .brand { padding: 0 0 18px; justify-content: center; font-size: 20px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }

.menu-btn { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2, .split { grid-template-columns: 1fr; }
  .phone { position: static; }
  .conn { flex-direction: column; }
}

.picklist { max-height: 340px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.pick:last-child { border-bottom: 0; }
.pick:hover { background: var(--surface-2); }
.pick-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-main strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.weekdays { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.weekdays label { cursor: pointer; }
.weekdays input { position: absolute; opacity: 0; pointer-events: none; }
.weekdays span { display: inline-block; min-width: 46px; text-align: center; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-weight: 600; }
.weekdays input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.weekdays input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
