:root {
  --bg: #F0F2F5;
  --surface: #FFFFFF;
  --soft: #F7F8FA;
  --line: #E9EDEF;
  --line-strong: #C5CCD1;
  --ink: #111B21;
  --muted: #54656F;
  --accent: #008069;
  --accent-dark: #005C4B;
  --bubble: #D9FDD3;
  --chat: #EFEAE2;
  --side: #111B21;
  --side-active: #2A3942;
  --side-text: #D1D7DB;
  --side-muted: #8696A0;
  --bright: #25D366;
  --warn: #9A4A06;
  --warn-bg: #FBEBD8;
  --warn-ink: #7A3A05;
  --info-bg: #E3ECF7;
  --info-ink: #1F3F6E;
  --bad-bg: #F6E1DE;
  --bad-ink: #8A1F14;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 14px; line-height: 1.4; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
.hide { display: none !important; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; flex-shrink: 0; background: var(--side); padding: 22px 14px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px; }
.logo { width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0; object-fit: cover; }
.logo-text { background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.brand-name { font-size: 16px; font-weight: 600; color: #fff; }
.brand-sub { font-family: var(--mono); font-size: 11px; color: var(--side-muted); margin-top: 2px; }
.brand-dark .brand-name { color: var(--ink); }
.brand-dark .brand-sub { color: var(--muted); }
.side-links { display: flex; flex-direction: column; gap: 2px; }
.side-links a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--side-text); text-decoration: none; font-weight: 500; }
.side-links a:hover { background: #1b262c; color: #fff; }
.side-links a.active { background: var(--side-active); color: #fff; font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px; border-radius: 10px; background: #202C33; display: flex; flex-direction: column; gap: 6px; }
.conn { display: flex; align-items: center; gap: 8px; color: #fff; font-size: 13px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-on { background: var(--bright); }
.dot-warn { background: #F0A44B; }
.dot-off { background: var(--side-muted); }
.side-user { font-size: 12px; color: var(--side-muted); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--side-text); text-decoration: underline; cursor: pointer; font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { min-height: 68px; padding: 12px 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.top .sub { font-size: 12px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.content { padding: 24px 28px 40px; display: flex; flex-direction: column; gap: 20px; }
.tabs { display: none; }

.banner { padding: 10px 28px; font-weight: 600; font-size: 13px; }
.banner-warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner-info { background: var(--info-bg); color: var(--info-ink); }
.banner-ok { background: var(--bubble); color: var(--accent-dark); }
.banner-bad { background: var(--bad-bg); color: var(--bad-ink); }

/* ---------- layout helpers ---------- */
.row { display: flex; gap: 20px; align-items: flex-start; }
.row > .grow { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; gap: 20px; }
.w300 { width: 300px; flex-shrink: 0; }
.w360 { width: 360px; flex-shrink: 0; }
.w400 { width: 400px; flex-shrink: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.cluster { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.card-head { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.card-body { padding: 0 20px 18px; }
.card > .card-body:first-child { padding-top: 18px; }
.card-flush { border-top: 1px solid var(--line); }
.card > .card-flush:first-child { border-top: 0; }
.list-row { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.list-row:first-child { border-top: 0; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.stat-label { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; }
.stat-value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.tone-ok { color: var(--accent); }
.tone-warn { color: var(--warn); }
.tone-bad { color: var(--bad-ink); }

/* ---------- tables ---------- */
.tbl .tr { display: grid; grid-template-columns: var(--tracks); column-gap: 14px; align-items: center; padding: 11px 20px; border-top: 1px solid var(--line); }
.tbl .tr > div { min-width: 0; overflow-wrap: anywhere; }
.tbl .tr:first-child { border-top: 0; }
.tbl .th { background: var(--soft); font-size: 12px; font-weight: 600; color: var(--muted); padding-top: 10px; padding-bottom: 10px; }
.tbl .tr.flag { background: var(--warn-bg); }
.tbl .tr.dim { color: var(--muted); }
.empty { padding: 28px 20px; color: var(--muted); text-align: center; }

/* ---------- pills, bars, notes ---------- */
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-ok { background: var(--bubble); color: var(--accent-dark); }
.pill-warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill-info { background: var(--info-bg); color: var(--info-ink); }
.pill-bad { background: var(--bad-bg); color: var(--bad-ink); }
.pill-muted { background: var(--soft); color: var(--ink); border: 1px solid var(--line); }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar-fill { height: 8px; background: var(--accent); }
.note { padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.note-muted { background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.note-warn { background: var(--warn-bg); color: var(--warn-ink); }
.note-info { background: var(--info-bg); color: var(--info-ink); }
.note-ok { background: var(--bubble); color: var(--accent-dark); }
.note-bad { background: var(--bad-bg); color: var(--bad-ink); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label, .label { font-size: 12px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=search], input[type=password], input[type=tel], input[type=number], input[type=time], input[type=date], input[type=email], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface);
}
textarea { line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 32px; }
.checklist { border: 1px solid var(--line); border-radius: 8px; max-height: 340px; overflow-y: auto; }
.checklist label { display: flex; align-items: center; gap: 10px; padding: 0 12px; min-height: 40px; border-top: 1px solid var(--line); cursor: pointer; }
.checklist label:first-child { border-top: 0; }
.checklist label:has(input:checked) { background: var(--bubble); font-weight: 600; }
.checklist .tag { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--soft); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { border-color: var(--warn); color: var(--warn); }
.btn-danger:hover { background: var(--warn-bg); color: var(--warn-ink); }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; }
.btn-sm { min-height: 32px; padding: 0 12px; border-radius: 7px; font-size: 13px; }
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg a, .seg button { min-height: 38px; padding: 0 14px; display: flex; align-items: center; justify-content: center; border: 0; background: var(--surface); color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 500; cursor: pointer; }
.seg .on { background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- chat preview ---------- */
.chat { padding: 14px; border-radius: 10px; background: var(--chat); display: flex; justify-content: flex-end; }
.bubble { max-width: 420px; padding: 8px 12px; border-radius: 10px 10px 2px 10px; background: var(--bubble); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-in { background: var(--bg); border-radius: 2px 10px 10px 10px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- login ---------- */
body.bare { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.bare-box { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.bare-box .brand { padding: 0; }

/* ---------- phone ---------- */
@media (max-width: 900px) {
  body { font-size: 15px; }
  .side { display: none; }
  .shell { display: block; padding-bottom: 72px; }
  .top { background: var(--accent); color: #fff; border-bottom: 0; padding: 10px 16px; min-height: 56px; position: sticky; top: 0; z-index: 5; }
  .top h1 { font-size: 18px; }
  .top .sub { color: var(--bubble); font-size: 11px; }
  .top .btn { min-height: 44px; padding: 0 12px; font-size: 13px; }
  .top .btn-danger { background: #fff; }
  .top .btn-primary { background: #fff; border-color: #fff; color: var(--accent-dark); }
  .content { padding: 16px 16px 24px; gap: 12px; }
  .banner { padding: 10px 16px; }
  .row { flex-direction: column; gap: 12px; }
  .col { gap: 12px; }
  .w300, .w360, .w400 { width: 100%; }
  .grid2, .grid3, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .grid3.wide, .grid2.wide { grid-template-columns: 1fr; }
  .card-head { padding: 12px 14px; }
  .card-body { padding: 0 14px 14px; }
  .list-row { padding: 12px 14px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; }
  .checklist label { min-height: 44px; }
  .seg a, .seg button { min-height: 44px; }
  .tbl .tr.th { display: none; }
  .tbl .tr { display: block; padding: 12px 14px; }
  .tbl .tr > div { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
  .tbl .tr > div::before { content: attr(data-label); font-size: 12px; font-weight: 600; color: var(--muted); flex-shrink: 0; }
  .tbl .tr > div:first-child { font-weight: 600; }
  .tbl .tr > div:first-child::before { content: none; }
  .tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; height: 64px; background: var(--surface); border-top: 1px solid var(--line); z-index: 10; padding-bottom: env(safe-area-inset-bottom); }
  .tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; }
  .tabs a.active { color: var(--accent); font-weight: 600; }
}

/* ---------- phone fields: fixed +1, then the 10 digits ---------- */
.phone { display: flex; align-items: stretch; }
.phone-cc { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--line-strong); border-right: 0; border-radius: 8px 0 0 8px; background: var(--soft); color: var(--muted); font-weight: 600; }
.phone input { flex: 1; min-width: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
