:root {
  --bg: #f4f6f9; --panel: #fff; --text: #1b2330; --muted: #677489; --line: #e3e7ee; --soft: #f0f3f8;
  --primary: #2453d6; --primary-soft: #e8eefc; --ok: #13804b; --ok-soft: #e3f5ec; --warn: #a15c00; --warn-soft: #fff3df;
  --bad: #c0302b; --bad-soft: #fdeceb; --rcs: #6b3fd4; --rcs-soft: #f0eafd; --radius: 10px; --side: 232px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
}
* { 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: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 8px; overflow: auto; white-space: pre; }
code.inline { background: var(--soft); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: #111827; color: #cbd5e1; position: fixed; inset: 0 auto 0 0; overflow-y: auto; z-index: 30; transition: transform .2s; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 17px; }
.side .brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #7c3aed); display: grid; place-items: center; font-size: 15px; }
.side nav { padding: 6px 10px 20px; }
.side .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 14px 10px 4px; }
.side a { display: flex; align-items: center; gap: 10px; color: #cbd5e1; padding: 8px 10px; border-radius: 7px; text-decoration: none; }
.side a:hover { background: #1f2937; color: #fff; }
.side a.active { background: #2453d6; color: #fff; }
.side a .ico { width: 18px; text-align: center; }
.side a .tag { margin-left: auto; font-size: 10px; background: var(--rcs); color: #fff; padding: 1px 6px; border-radius: 99px; }
.main { flex: 1; margin-left: var(--side); min-width: 0; }
.top { position: sticky; top: 0; z-index: 20; background: rgba(244, 246, 249, .9); backdrop-filter: blur(6px); display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--line); }
.top .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 24px 28px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
@media (max-width: 900px) {
  .side { transform: translateX(-100%); }
  .side.open { transform: none; box-shadow: 0 0 40px #0005; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .top { padding: 12px 16px; }
}

/* Cards & grid */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); } }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); }
.compose { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.compose .sticky { position: sticky; top: 76px; }
@media (max-width: 1100px) { .compose { grid-template-columns: minmax(0, 1fr); } .compose .sticky { position: static; } }

/* Forms */
.f { display: block; margin-bottom: 12px; }
.f > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.f > small, .help { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
  width: 100%; border: 1px solid #cfd6e1; border-radius: 8px; padding: 8px 10px; font: inherit; background: #fff; color: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 120px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }
.row.align-top { align-items: flex-start; } /* fields with help text under some of them: keep inputs aligned */
.check { display: inline-flex; align-items: center; gap: 7px; margin: 0 14px 6px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; }
.checklist { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.checklist .check { display: flex; margin: 4px 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 0 0 12px; }
legend { font-weight: 600; font-size: 13px; padding: 0 6px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid #cfd6e1; background: #fff; color: var(--text); border-radius: 8px; padding: 7px 13px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1c44b5; }
.btn.rcs { background: var(--rcs); border-color: var(--rcs); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.tabs { display: inline-flex; background: var(--soft); border-radius: 9px; padding: 3px; gap: 2px; margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; padding: 6px 16px; border-radius: 7px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.tabs button.on.rcs { color: var(--rcs); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8faff; }
td .clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; }

/* Badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--soft); 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.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.rcs { background: var(--rcs-soft); color: var(--rcs); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #9aa5b5; margin-right: 6px; }
.dot.on { background: #16a34a; box-shadow: 0 0 0 3px #16a34a22; }
.progress { height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; display: flex; }
.progress > i { display: block; height: 100%; }

/* Modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px #0004; }
.modal.wide { width: min(980px, 100%); }
.modal header { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 18px; overflow: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px #0003; max-width: 380px; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--primary-soft); color: #1e3a8a; margin-bottom: 12px; font-size: 13px; }
.alert.warn { background: var(--warn-soft); color: #7a4500; }
.alert.rcs { background: var(--rcs-soft); color: #4c1d95; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #dbe6ff, transparent 40%), radial-gradient(circle at 80% 90%, #ece2ff, transparent 40%), var(--bg); }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; margin-bottom: 18px; }
.auth .brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #7c3aed); display: grid; place-items: center; color: #fff; }

/* Bars chart */
.bars { display: flex; align-items: end; gap: 10px; height: 160px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: end; }
.bars .stack { width: 100%; max-width: 38px; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 2px 2px; overflow: hidden; min-height: 2px; background: var(--soft); }
.bars .stack i { display: block; }
.bars .lbl { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Phone + RCS bubbles */
.phone { width: 320px; max-width: 100%; margin: 0 auto; background: #0b0f17; border-radius: 34px; padding: 10px; box-shadow: 0 10px 30px #0003; }
.phone .screen { background: #fff; border-radius: 26px; overflow: hidden; display: flex; flex-direction: column; height: 600px; }
.phone .bar { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; border-bottom: 1px solid #eef0f4; }
.phone .bar .av { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #3b82f6, #7c3aed); color: #fff; display: grid; place-items: center; font-weight: 700; }
.phone .bar .nm { font-weight: 600; line-height: 1.2; }
.phone .bar .vf { font-size: 11px; color: var(--rcs); }
.phone .thread { flex: 1; overflow-y: auto; padding: 12px 10px; background: #fff; display: flex; flex-direction: column; gap: 8px; }
.phone .composer { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #eef0f4; }
.phone .composer input { border-radius: 99px; padding: 8px 12px; }
.phone .composer button { border-radius: 99px; }
.msg { max-width: 86%; display: flex; flex-direction: column; gap: 6px; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 9px 12px; border-radius: 18px; background: #eef1f6; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; }
.msg.out .bubble { background: #d3e3fd; }
.msg .meta { font-size: 10.5px; color: var(--muted); padding: 0 6px; }
.rcard { border: 1px solid #e3e7ee; border-radius: 16px; overflow: hidden; background: #fff; width: 240px; flex: 0 0 auto; }
.rcard.horizontal { display: flex; width: 270px; }
.rcard.horizontal .media { width: 40%; flex: 0 0 40%; }
.rcard.horizontal.right { flex-direction: row-reverse; }
.rcard .media { background: #dfe5ee center/cover no-repeat; }
.rcard .media.SHORT { height: 90px; } .rcard .media.MEDIUM { height: 140px; } .rcard .media.TALL { height: 210px; }
.rcard.horizontal .media { height: auto !important; min-height: 110px; }
.rcard .txt { padding: 10px 12px 6px; }
.rcard .txt b { display: block; font-size: 14px; margin-bottom: 2px; }
.rcard .txt p { margin: 0; font-size: 12.5px; color: #4b5565; white-space: pre-wrap; }
.rcard .acts { display: flex; flex-direction: column; border-top: 1px solid #eef0f4; }
.rcard .acts button { border: 0; background: none; padding: 8px; font: inherit; font-size: 13px; color: #1a56db; font-weight: 600; cursor: pointer; }
.rcard .acts button + button { border-top: 1px solid #eef0f4; }
.carousel { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; padding-bottom: 4px; }
.carousel .rcard { width: 200px; }
.carousel.SMALL .rcard { width: 150px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { border: 1px solid #c9d3e3; background: #fff; color: #1a56db; border-radius: 99px; padding: 5px 11px; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.chip:hover { background: #f1f5ff; }
.media-only { width: 220px; border-radius: 16px; overflow: hidden; }
.media-only img { width: 100%; display: block; }
.rcs-editor .sugg { border: 1px dashed #cfd6e1; border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #fbfcfe; }
.rcs-editor .cardbox { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.counter { font-size: 12px; color: var(--muted); text-align: right; margin-top: -8px; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.copy { display: flex; gap: 6px; }
.copy input { font-family: ui-monospace, monospace; font-size: 12px; }
.sim-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.sim-list .sim { display: flex; align-items: center; gap: 10px; background: var(--soft); border-radius: 8px; padding: 8px 10px; }
.drv { border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; }
.drv.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Setup guide */
.guide-step { display: flex; gap: 14px; align-items: flex-start; }
.guide-step h2 { margin-top: 4px; }
.guide-step ol, .card ul { margin: 0; padding-left: 20px; }
.guide-step li, .card ul li { margin-bottom: 8px; }
.guide-n { flex: 0 0 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; }

/* ===================================================================== */
/* Responsive / mobile                                                    */
/* ===================================================================== */
.side-backdrop { display: none; }
.tabs { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { white-space: nowrap; flex: 0 0 auto; }
.compose.in-modal { grid-template-columns: minmax(0, 1fr) 330px; }
img { max-width: 100%; }

@media (max-width: 900px) {
  .side-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 25; }
  .compose.in-modal { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 700px) {
  .content { padding: 14px 12px 60px; }
  .top { padding: 10px 12px; gap: 8px; }
  .top .user-name { display: none; }
  .card { padding: 14px; }
  .page-head { margin-bottom: 14px; gap: 8px; }
  .page-head h1 { font-size: 18px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid { gap: 12px; }
  .grid > [style*="span 2"] { grid-column: auto !important; }
  .stat .value { font-size: 22px; }
  .stat .sub { font-size: 11.5px; }
  /* 16px inputs stop iOS from zooming in on focus */
  input[type=text], input[type=email], input[type=password], input[type=number], input[type=url],
  input[type=datetime-local], input[type=time], input[type=search], select, textarea { font-size: 16px; }
  .overlay { padding: 8px; align-items: end; }
  .modal { max-height: calc(100vh - 16px); border-radius: 14px; }
  .modal .body { padding: 14px; }
  .modal footer { padding: 10px 14px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 8px; font-size: 12px; }
  .row > * { flex: 1 1 100%; min-width: 0; }
  .row > .shrink { flex: 0 0 auto; }
  .row > select { flex-basis: calc(50% - 5px); }
  .toasts { left: 12px; right: 12px; }
  .toast { max-width: none; }
  .pager { justify-content: space-between; flex-wrap: wrap; }
  .pager > span { width: 100%; }
  .phone { width: 100%; max-width: 320px; }
  .guide-step { gap: 10px; }
  .guide-n { flex-basis: 28px; height: 28px; font-size: 13px; }

  /* Tables → stacked cards. Labels come from the header (data-label, set in core.js). */
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 6px 0; box-shadow: var(--shadow); }
  .table-wrap td { border: 0; padding: 4px 12px; display: flex; gap: 10px; align-items: baseline; min-width: 0; }
  .table-wrap td > * { min-width: 0; }
  .table-wrap td[data-label]::before { content: attr(data-label); flex: 0 0 84px; color: var(--muted); font-size: 12px; font-weight: 600; }
  .table-wrap td .clip { white-space: normal; max-width: none; overflow-wrap: anywhere; }
  .table-wrap td:empty { display: none; }
  .table-wrap td[style*="text-align:right"] { justify-content: flex-end; padding-top: 8px; }
  .table-wrap tr.click:hover td { background: transparent; }
  .table-wrap .empty { display: block; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
}
