:root {
  color-scheme: light;
  --brand: #087f6a;
  --brand-strong: #056451;
  --brand-soft: #e7f7f3;
  --ink: #10223d;
  --muted: #627087;
  --surface: #ffffff;
  --canvas: #f3f6fa;
  --line: #dbe3ec;
  --danger: #b42318;
  --warning: #b54708;
  --success: #067647;
  --shadow: 0 12px 38px rgba(16, 34, 61, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.error { color: var(--danger); }
.success { color: var(--success); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(8,127,106,.18), transparent 32rem),
    linear-gradient(145deg, #eefaf7, #f5f7fb 58%, #edf2f8);
}
.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid rgba(219,227,236,.9);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  color: white; background: linear-gradient(145deg, var(--brand), #0da58b);
  font-weight: 900; font-size: 1.3rem;
}
.brand h1 { margin: 0; font-size: 1.55rem; letter-spacing: -.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.form { display: grid; gap: 16px; margin-top: 28px; }
.field { display: grid; gap: 7px; }
.field label { font-weight: 700; font-size: .9rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); background: white; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(8,127,106,.12);
}
.btn {
  border: 0; border-radius: 12px; padding: 11px 15px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-strong); }
.btn-secondary { background: #eaf0f6; color: var(--ink); }
.btn-danger { background: #fee4e2; color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0,1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 22px 16px;
  background: #0e223d; color: white; display: flex; flex-direction: column;
}
.sidebar .brand { padding: 0 8px 22px; }
.sidebar .brand p { color: #b9c6d6; }
.nav { display: grid; gap: 5px; overflow: auto; padding-right: 2px; }
.nav button {
  border: 0; color: #dbe5f0; background: transparent; text-align: left;
  padding: 11px 12px; border-radius: 11px; display: flex; gap: 10px; align-items: center;
}
.nav button:hover, .nav button.active { background: rgba(255,255,255,.11); color: white; }
.sidebar-footer { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.mode-pill { display: inline-flex; padding: 5px 9px; border-radius: 99px; background: rgba(20,184,166,.18); color: #99f6e4; font-size: .76rem; font-weight: 800; }

.main { min-width: 0; }
.topbar {
  position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between;
  min-height: 72px; padding: 12px 28px; background: rgba(243,246,250,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(219,227,236,.85);
}
.topbar h2 { margin: 0; font-size: 1.25rem; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 900; }
.content { padding: 26px 28px 110px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0 0 5px; font-size: clamp(1.45rem, 2vw, 2rem); letter-spacing: -.025em; }
.page-head p { margin: 0; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(4, minmax(0,1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 17px; padding: 18px; box-shadow: 0 5px 18px rgba(16,34,61,.045); }
.metric-label { color: var(--muted); font-size: .88rem; }
.metric-value { font-size: 1.8rem; font-weight: 900; margin-top: 8px; letter-spacing: -.03em; }
.metric-sub { color: var(--muted); font-size: .8rem; margin-top: 5px; }
.panel-grid { grid-template-columns: 1.5fr 1fr; margin-top: 16px; }
.card h3 { margin: 0 0 14px; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; }
.list { display: grid; gap: 10px; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #edf1f5; }
.list-row:last-child { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; border-radius: 99px; padding: 5px 9px; font-size: .76rem; font-weight: 800; }
.badge-success { background: #dcfae6; color: #067647; }
.badge-muted { background: #eef2f6; color: #475467; }
.badge-warning { background: #fef0c7; color: #93370d; }

.mode-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
.mode-card { border: 2px solid var(--line); border-radius: 16px; padding: 18px; background: white; transition: .15s; }
.mode-card:hover { transform: translateY(-2px); border-color: #8cd9ca; }
.mode-card.selected { border-color: var(--brand); background: var(--brand-soft); }
.mode-card h3 { margin: 8px 0; }
.mode-icon { font-size: 1.8rem; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 15px; background: white; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th, td { text-align: left; padding: 13px 15px; border-bottom: 1px solid #edf1f5; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }

.module-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
.module-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 13px; padding: 13px; background: white; }
.switch { position: relative; width: 43px; height: 24px; background: #cfd8e3; border-radius: 99px; border: 0; flex: 0 0 auto; }
.switch.on { background: var(--brand); }
.switch::after { content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: white; left: 3px; top: 3px; transition: .15s; box-shadow: 0 1px 4px rgba(0,0,0,.22); }
.switch.on::after { transform: translateX(19px); }

.bottom-nav { display: none; }
.mobile-only { display: none; }
.toast { position: fixed; right: 20px; bottom: 22px; z-index: 100; max-width: min(420px, calc(100vw - 40px)); padding: 13px 16px; border-radius: 12px; color: white; background: #0e223d; box-shadow: var(--shadow); }

@media (max-width: 1050px) {
  .cards { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .panel-grid, .mode-grid { grid-template-columns: 1fr; }
  .module-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .mobile-only { display: inline-flex; }
  .topbar { min-height: 62px; padding: 9px 14px; }
  .topbar .btn-secondary span { display: none; }
  .content { padding: 18px 14px 92px; }
  .cards { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .card { padding: 15px; border-radius: 14px; }
  .metric-value { font-size: 1.5rem; }
  .module-grid { grid-template-columns: 1fr; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5,1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: white; border-top: 1px solid var(--line); box-shadow: 0 -8px 25px rgba(16,34,61,.08);
  }
  .bottom-nav button { border: 0; background: transparent; color: var(--muted); display: grid; gap: 2px; place-items: center; font-size: .67rem; padding: 5px 1px; }
  .bottom-nav button.active { color: var(--brand); font-weight: 800; }
  .bottom-nav .nav-icon { font-size: 1.15rem; }
  .page-head { display: block; }
  .page-head .btn { width: 100%; margin-top: 14px; }
  .login-card { padding: 24px 20px; }
}
@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .metric-label { font-size: .78rem; }
}


.btn-small { padding: 8px 11px; font-size: .82rem; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; padding: 20px;
  background: rgba(8, 24, 43, .58);
}
.modal-card {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(8, 24, 43, .28);
  border: 1px solid var(--line);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 18px;
  padding: 22px 24px 0;
}
.modal-head h2 { margin: 0 0 5px; }
.modal-head p { margin: 0; color: var(--muted); }
.modal-close {
  border: 0; background: #edf2f7; color: var(--ink);
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 1.5rem; line-height: 1;
}
.modal-form { margin: 0; padding: 22px 24px 24px; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding-top: 4px;
}
@media (max-width: 560px) {
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal-card { width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; }
  .modal-head { padding: 20px 18px 0; }
  .modal-form { padding: 18px; }
  .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
}


.badge-danger { background: #fee4e2; color: #b42318; }
.wa-connect-card {
  min-height: 460px; display: grid; grid-template-columns: 1fr 340px;
  gap: 28px; align-items: center;
}
.wa-connect-copy { text-align: center; max-width: 560px; margin: 0 auto; }
.wa-connect-copy h2 { margin: 8px 0; }
.wa-connect-copy p { color: var(--muted); line-height: 1.55; }
.wa-logo { font-size: 3.2rem; }
.wa-actions { display: flex; gap: 10px; justify-content: center; margin: 22px 0 12px; }
.qr-frame {
  width: 320px; height: 320px; border-radius: 20px; border: 1px solid var(--line);
  background: #f8fafc; display: grid; place-items: center; overflow: hidden;
}
.qr-placeholder { color: var(--muted); padding: 24px; text-align: center; }
.qr-image { width: 100%; height: 100%; object-fit: contain; padding: 12px; background: white; }
.wa-head-actions { display: flex; gap: 10px; align-items: center; }
.conversation-shell {
  min-height: calc(100vh - 235px);
  display: grid; grid-template-columns: minmax(270px, 360px) 1fr;
  border: 1px solid var(--line); border-radius: 17px; overflow: hidden;
  background: white;
}
.conversation-list { border-right: 1px solid var(--line); overflow: auto; }
.conversation-list-title { padding: 16px; font-weight: 900; border-bottom: 1px solid var(--line); }
.conversation-item {
  width: 100%; border: 0; border-bottom: 1px solid #edf1f5; background: white;
  display: grid; grid-template-columns: 44px 1fr auto; gap: 11px;
  padding: 13px; text-align: left;
}
.conversation-item:hover, .conversation-item.active { background: var(--brand-soft); }
.conversation-avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; background: #e7eef6; color: var(--ink);
}
.conversation-summary { min-width: 0; }
.conversation-name { font-weight: 850; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-preview { color: var(--muted); font-size: .82rem; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-meta { color: var(--muted); font-size: .72rem; display: grid; justify-items: end; align-content: start; gap: 6px; }
.unread { background: var(--brand); color: white; border-radius: 99px; padding: 2px 7px; }
.message-panel { min-width: 0; display: grid; grid-template-rows: auto 1fr auto; background: #eef3f7; }
.message-head { padding: 13px 17px; background: white; border-bottom: 1px solid var(--line); }
.message-list { overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.message-row { display: flex; }
.message-row.outbound { justify-content: flex-end; }
.message-bubble {
  max-width: min(76%, 720px); background: white; border-radius: 13px;
  padding: 10px 12px; box-shadow: 0 2px 6px rgba(16,34,61,.08); white-space: pre-wrap;
}
.message-row.outbound .message-bubble { background: #d9fdd3; }
.message-time { margin-top: 4px; font-size: .68rem; color: var(--muted); text-align: right; }
.message-compose {
  padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 10px;
  background: white; border-top: 1px solid var(--line);
}
.message-compose textarea {
  resize: none; min-height: 44px; max-height: 130px; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: 12px; font: inherit;
}
.empty.compact { padding: 18px 12px; border: 0; }

@media (max-width: 850px) {
  .wa-connect-card { grid-template-columns: 1fr; }
  .qr-frame { width: min(320px, 100%); height: auto; aspect-ratio: 1; margin: 0 auto; }
  .conversation-shell { grid-template-columns: 1fr; min-height: calc(100vh - 220px); }
  .conversation-list { max-height: 42vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .message-panel { min-height: 54vh; }
}
@media (max-width: 560px) {
  .wa-actions, .wa-head-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .message-bubble { max-width: 88%; }
}
