:root {
  --ink: #10243c;
  --muted: #64748b;
  --line: #dbe3ed;
  --soft: #f4f7fb;
  --paper: #ffffff;
  --wa: #13795b;
  --wa-soft: #eaf6f1;
  --sms: #275f9b;
  --sms-soft: #edf4fb;
  --ok: #147a55;
  --warn: #9a5b05;
  --warn-soft: #fff6df;
  --bad: #ad2f45;
  --bad-soft: #fdecef;
  --radius: 16px;
  --shadow: 0 8px 26px rgba(16, 36, 60, .07);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--soft); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: #245d91; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.login-card { width: min(100%, 390px); padding: 28px; background: var(--paper); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
h1 { margin: 0 0 8px; font-size: 24px; line-height: 1.15; letter-spacing: -.4px; }
h2 { margin: 0 0 14px; font-size: 17px; }
h3 { margin: 0 0 10px; font-size: 15px; }
.sub { margin: 0 0 25px; color: var(--muted); }

.field { display: grid; gap: 7px; margin: 0 0 15px; }
.field label, .check strong { font-size: 13px; font-weight: 750; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid #c9d5e2; background: #fff; border-radius: 11px; padding: 11px 12px; color: var(--ink); outline: 0;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: #4978aa; box-shadow: 0 0 0 3px rgba(73, 120, 170, .13); }
.field textarea { min-height: 122px; resize: vertical; }
.help, .footer-note { margin: 0; color: var(--muted); font-size: 12px; }
.check { display: grid; grid-template-columns: 20px 1fr; gap: 9px; align-items: start; margin: 12px 0; color: #33445a; font-size: 13px; }
.check input { width: 17px; height: 17px; margin-top: 2px; }

.button { border: 0; border-radius: 10px; padding: 11px 14px; font-weight: 750; background: var(--ink); color: #fff; }
.button:hover:not(:disabled) { filter: brightness(1.1); }
.button.secondary { background: #e8eef5; color: var(--ink); }
.button.whatsapp { background: var(--wa); }
.button.sms { background: var(--sms); }
.button.danger { background: var(--bad-soft); color: var(--bad); }
.button:disabled { opacity: .48; cursor: not-allowed; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.error, .notice, .warning { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 12px 0; }
.error { background: var(--bad-soft); color: #861f33; }
.notice { background: #e7f5ef; color: #115d40; }
.warning { background: var(--warn-soft); color: #784505; border: 1px solid #f0d79c; }
.channel-callout { padding: 13px 14px; border-radius: 12px; margin: 0 0 16px; font-size: 13px; }
.channel-callout.wa { background: var(--wa-soft); border-left: 4px solid var(--wa); }
.channel-callout.sms { background: var(--sms-soft); border-left: 4px solid var(--sms); }
.channel-callout.policy { background: var(--bad-soft); border-left: 4px solid var(--bad); }

.app { max-width: 1160px; margin: auto; padding: 0 16px 30px; }
.top { position: sticky; top: 0; z-index: 20; padding: 16px 0 10px; border-bottom: 1px solid rgba(219, 227, 237, .85); background: rgba(244, 247, 251, .95); backdrop-filter: blur(10px); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { margin: 0; font-size: 20px; }
.counter { color: var(--muted); font-size: 13px; font-weight: 800; white-space: nowrap; }
.counter b { color: var(--ink); font-size: 18px; }
.tabs { display: flex; gap: 7px; overflow-x: auto; padding: 13px 0 0; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: 8px 10px; font-weight: 750; }
.tab.active { background: var(--ink); color: #fff; }
.tab[data-view="whatsapp"].active { background: var(--wa); }
.tab[data-view="sms"].active { background: var(--sms); }
.view { padding-top: 18px; }

.channel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.channel-summary { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.channel-summary.wa { border-top: 4px solid var(--wa); }
.channel-summary.sms { border-top: 4px solid var(--sms); }
.channel-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.channel-title h2 { margin: 0; }
.channel-tag { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.channel-tag.wa { background: var(--wa-soft); color: var(--wa); }
.channel-tag.sms { background: var(--sms-soft); color: var(--sms); }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.metric { min-width: 0; padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfe; }
.metric span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.metric strong { display: block; margin-top: 2px; font-size: 22px; }
.metric.bad strong { color: var(--bad); }

.card { margin: 16px 0; padding: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-head h2 { margin: 0; }
.table-wrap { overflow: auto; margin: 0 -4px; }
.table { width: 100%; min-width: 720px; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 11px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: 3px 7px; border-radius: 99px; background: #eef2f7; color: #445265; font-size: 11px; font-weight: 800; }
.badge.queued, .badge.sending, .badge.in_review, .badge.identity_pending { background: var(--warn-soft); color: var(--warn); }
.badge.completed, .badge.delivered, .badge.read { background: #e5f5ed; color: var(--ok); }
.badge.failed, .badge.rejected { background: var(--bad-soft); color: var(--bad); }
.mini-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-actions .button { padding: 7px 9px; font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.line { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.conversations { display: grid; grid-template-columns: minmax(240px, .7fr) minmax(0, 1.3fr); gap: 14px; }
.conversation-list { max-height: 620px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.contact { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 12px; text-align: left; }
.contact:hover, .contact.active { background: #eef4fa; }
.contact strong, .contact span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.chat { min-height: 400px; border: 1px solid var(--line); border-radius: 12px; background: #f8fafc; display: flex; flex-direction: column; }
.chat-head { padding: 13px 14px; background: #fff; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.chat-messages { min-height: 300px; max-height: 440px; padding: 14px; display: grid; gap: 9px; overflow: auto; }
.bubble { max-width: 86%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 12px; background: #fff; font-size: 13px; }
.bubble.out { margin-left: auto; background: #dcecfb; border-color: #c5deef; }
.bubble small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.reply { padding: 12px; border-top: 1px solid var(--line); background: #fff; display: flex; gap: 8px; }
.reply input { min-width: 0; flex: 1; border: 1px solid #cbd6e2; border-radius: 10px; padding: 10px; }
.empty { padding: 20px; color: var(--muted); font-size: 13px; text-align: center; }

.setting-status { color: var(--ok); font-size: 12px; font-weight: 750; }
.setting-status.off { color: var(--warn); }
code { padding: 4px 6px; border-radius: 6px; background: #f1f4f7; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.copy-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.request-detail { max-width: 310px; white-space: normal; }
.site-footer { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; padding: 14px 0 2px; color: var(--muted); font-size: 12px; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(10, 24, 40, .56); }
.modal-card { width: min(100%, 400px); padding: 22px; border-radius: 18px; background: #fff; box-shadow: 0 24px 70px rgba(0, 0, 0, .24); }
.modal-card.wide { width: min(100%, 1040px); max-height: calc(100dvh - 40px); overflow: auto; }
.modal-card h2 { margin-bottom: 5px; }

.legal-shell { width: min(100% - 28px, 820px); margin: 30px auto; }
.legal-header, .legal-card { margin-bottom: 14px; padding: clamp(18px, 4vw, 32px); border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.legal-header p { margin-bottom: 0; color: var(--muted); }
.legal-card h2 { margin-top: 0; }
.legal-card h3 { margin-top: 22px; }
.legal-card li { margin: 7px 0; }
.legal-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.legal-meta span { padding: 5px 8px; border-radius: 999px; background: #edf2f7; color: #4d5d72; font-size: 12px; }
.case-code { display: block; margin: 12px 0; padding: 12px; border-radius: 10px; background: #eef7f2; color: #0f6645; font: 700 18px ui-monospace, monospace; text-align: center; letter-spacing: .05em; }

@media (max-width: 760px) {
  .app { padding: 0 12px 24px; }
  .top { padding-top: max(13px, env(safe-area-inset-top)); }
  .top-row { align-items: flex-start; }
  .top h1 { max-width: 205px; font-size: 18px; }
  .channel-grid, .two-col, .three-col, .conversations { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 14px; }
  .conversation-list { max-height: 220px; }
  .chat { min-height: 360px; }
  .chat-messages { min-height: 245px; }
  .reply { flex-wrap: wrap; }
  .reply .button { width: 100%; }
  .tabs { margin-right: -12px; padding-right: 12px; }
  .field textarea { min-height: 105px; }
  .button-row > .button { flex: 1 1 auto; }
}
