:root {
  --bg: #f4f6ef;
  --panel: #ffffff;
  --line: #d9ddca;
  --ink: #1f2a1f;
  --muted: #5f695d;
  --accent: #18683f;
  --danger: #b43830;
  --radius: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Manrope", sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }

.topbar {
  height: 64px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: #f0f3e5;
}
.status-bar {
  min-width: 260px;
  max-width: 48vw;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid #c8d5bb;
  background: #f6fbef;
  color: #2c5934;
}
.status-bar.error {
  border-color: #e4b1ac;
  background: #fff0ef;
  color: #9a2d25;
}
.brand { font-size: 26px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.brand-copy { display: flex; align-items: baseline; gap: 6px; }
.brand span { font-size: 14px; color: var(--muted); font-weight: 600; }
.top-actions { display: flex; gap: 8px; }

button { border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; background: var(--accent); color: #fff; font-weight: 700; }
button.ghost { background: #f7f9f0; color: #294430; border: 1px solid #ccd3ba; }
button.danger { background: var(--danger); }

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 64px); }
.layout.auth-only { grid-template-columns: 1fr; }
.layout.auth-only .sidebar { display: none !important; }
.layout.auth-only .content {
  min-height: calc(100vh - 64px);
  display: grid;
  align-items: start;
  justify-items: center;
  padding: 36px 16px;
}
.layout.auth-only .panel[data-section="auth"] {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 20px;
}
.sidebar { border-right: 1px solid var(--line); padding: 16px; background: #eef2e1; }
.sidebar nav { max-height: calc(100vh - 130px); overflow: auto; padding-right: 4px; }
.tenant-pill { border: 1px dashed #c8d0b6; border-radius: 10px; padding: 10px; font-size: 13px; background: #fff; margin-bottom: 14px; }
.tenant-brand { display: flex; align-items: center; gap: 10px; }
.tenant-brand strong { display: block; font-size: 14px; }
.tenant-brand span { color: var(--muted); font-size: 12px; }
nav { display: grid; gap: 8px; }
.nav-btn { text-align: left; background: #fff; color: #1f2a1f; border: 1px solid #d2d8c2; }
.nav-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.nav-main-btn, .nav-group-toggle { text-align: left; background: #fff; color: #444f63; border: 1px solid #e3e7d9; display: flex; align-items: center; gap: 10px; }
.nav-main-btn.active, .nav-group-toggle.active { background: #ece9e7; color: #5f6986; border-color: #e2ddda; }
.ico { width: 20px; height: 20px; display: inline-grid; place-items: center; color: #4f9479; font-size: 15px; }
.nav-submenu { display: grid; gap: 8px; padding: 8px 4px 4px; border-top: 1px solid #eef0e8; }
.nav-subtitle { margin: 8px 2px 2px; color: #a0a5b7; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.nav-sub-btn { font-size: 15px; display: flex; align-items: center; gap: 10px; background: transparent; border: 0; padding: 8px 6px; color: #3c4148; }
.nav-sub-btn:hover { background: #f5f6f2; border-radius: 10px; }
.nav-sub-btn.active { background: #e8f3eb; color: #1f5136; border-radius: 10px; }
.add-account-btn { background: #3f866c; color: #e9fff4; }

.content { padding: 18px; width: 100%; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 16px; }
.panel[data-section="auth"] { display: flex; justify-content: center; width: 100%; }

.auth-wrap { max-width: 460px; margin: 0; width: 100%; }
.auth-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fcfdf8;
  padding: 16px;
  width: 100%;
  box-shadow: 0 10px 24px rgba(23, 41, 24, 0.06);
}
.auth-card h2 { margin: 0 0 4px; }
.muted { color: var(--muted); margin: 0 0 14px; }
.divider { height: 1px; background: #e7eadf; margin: 14px 0; }
.text-link {
  margin-top: 10px;
  background: transparent;
  border: 0;
  color: #3e5f46;
  font-size: 12px;
  font-weight: 700;
  padding: 0;
  text-decoration: underline;
  text-align: left;
}

.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.compact { gap: 8px; }
.settings-grid { align-items: start; }
.card { border: 1px solid var(--line); border-radius: 12px; background: #fcfdf8; padding: 14px; }
label { display: block; margin: 8px 0; font-size: 13px; color: var(--muted); }
input, select, textarea { width: 100%; margin-top: 6px; border: 1px solid #cfd6be; border-radius: 10px; padding: 10px; font: inherit; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-status:empty { display: none; }
.inbox-filters { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; gap: 8px; align-items: end; }
.send-card { max-width: 980px; margin: 0 auto; }
.send-card-ref { padding: 22px; border-color: #e4e8dc; }
.send-title { margin: 0; font-size: 44px; letter-spacing: -0.02em; line-height: 1.05; }
.send-subtitle { margin-bottom: 16px; }
.send-account-card { border: 1px solid #e6eadf; border-radius: 12px; background: #fff; padding: 8px 12px; }
.send-inner { margin-top: 14px; background: #fff; border-color: #e6eadf; }
.send-mode button { min-width: 118px; border-radius: 8px; }
.send-mode button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.send-actions { justify-content: space-between; }
.inline-status { font-size: 12px; margin: 0; }
.send-media-select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.send-media-select-row input { margin-top: 0; background: #fafcf7; }
.send-media-select-row button { white-space: nowrap; }
.send-media-source { margin-top: 6px; }
.contacts-grid { align-items: start; }
.bulk-grid { align-items: start; }
.bulk-campaign-card { max-width: 1180px; margin: 0 auto; }
.bulk-title { margin: 0 0 14px; font-size: 42px; line-height: 1.05; }
.bulk-inner { background: #fff; border-color: #e6eadf; }
.bulk-actions { justify-content: space-between; margin-top: 8px; }
.auto-card { max-width: 1180px; margin: 0 auto; }
.auto-title { margin: 0; font-size: 42px; line-height: 1.05; }
.auto-subtitle { margin-bottom: 16px; }
.auto-account-card { border: 1px solid #e6eadf; border-radius: 12px; background: #fff; padding: 8px 12px; }
.auto-inner { margin-top: 14px; background: #fff; border-color: #e6eadf; }
.auto-actions { justify-content: flex-end; margin-top: 8px; }
.compact-list { max-height: 360px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.report-table-wrap { margin-top: 10px; max-height: 440px; }
.fm-row-empty td { color: var(--muted); }
.tool-shell { max-width: 920px; margin: 0 auto; }
.tool-card { padding: 0; overflow: hidden; }
.tool-card h3 {
  margin: 0;
  padding: 18px 22px;
  border-bottom: 1px solid #e6ebdc;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.tool-card label { margin: 14px 22px; }
.tool-card input,
.tool-card textarea { background: #f5f7f2; }
.tool-actions {
  justify-content: space-between;
  border-top: 1px solid #e6ebdc;
  padding: 16px 22px 10px;
}
.tool-actions .ghost { background: #20242b; color: #fff; border-color: #20242b; }
.tool-card .inline-status { margin: 0 22px 16px; }
.tool-account-list {
  margin: 6px 22px 12px;
  border: 1px solid #e2e7d8;
  border-radius: 10px;
  background: #fff;
  max-height: 320px;
  overflow: auto;
}
.tool-account-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #edf0e5;
}
.tool-account-row:last-child { border-bottom: 0; }
.tool-account-meta { display: flex; align-items: center; gap: 10px; }
.tool-account-label { font-weight: 700; font-size: 14px; line-height: 1.2; color: #1f2a1f; }
.tool-account-sub { font-size: 12px; color: #5f695d; line-height: 1.2; margin-top: 2px; }
.tool-account-check { width: 22px; height: 22px; margin: 0; }
.tool-empty {
  padding: 18px 14px;
  font-size: 13px;
  color: var(--muted);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; border-bottom: 1px solid #e9eddc; padding: 8px; }
.list { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.item { padding: 10px; border-bottom: 1px solid #edf0e4; font-size: 13px; }
.item:last-child { border-bottom: 0; }
.qr-wrap { min-height: 150px; border: 1px dashed #c5ccb3; border-radius: 12px; display: grid; place-items: center; margin-top: 10px; background: #fff; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; white-space: pre-wrap; }
.small { font-size: 12px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.dashboard-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
.kpi { border: 1px solid #d4dbc3; border-radius: 10px; background: #fff; padding: 10px; }
.kpi span { display: block; font-size: 12px; color: var(--muted); }
.kpi strong { font-size: 20px; line-height: 1.1; }
.kv { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e9eddc; padding: 10px 0; font-size: 13px; }
.kv span { color: var(--muted); }
.kv strong { font-size: 14px; color: var(--ink); }
.checkbox { display: flex; align-items: center; gap: 10px; }
.checkbox input { width: auto; margin: 0; }
#saveSecurityBtn { margin-top: 10px; }
.modal { position: fixed; inset: 0; background: rgba(18, 28, 18, 0.45); display: grid; place-items: center; z-index: 40; }
.modal-card { width: min(520px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 14px; }
.modal-card.wide { width: min(900px, calc(100vw - 24px)); }
.wa-empty { min-height: 350px; display: grid; align-content: center; justify-items: center; text-align: center; gap: 8px; }
.wa-logo { width: 70px; height: 70px; border-radius: 35px; border: 4px solid #47b468; color: #47b468; display: grid; place-items: center; font-size: 28px; font-weight: 800; }
.add-wa-btn { background: #4ab46b; }
.wa-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.wa-toolbar input { width: 240px; margin: 0; }
.wa-account-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.wa-avatar {
  width: 38px;
  height: 38px;
  border-radius: 19px;
  object-fit: cover;
  border: 1px solid #d9decf;
  background: #fff;
}
.wa-avatar-fallback {
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: #1e5b3a;
  background: #e9f4ec;
}
.wa-account-name { font-weight: 700; font-size: 13px; color: #233328; line-height: 1.2; }
.wa-account-number { font-size: 12px; color: #5f695d; line-height: 1.2; margin-top: 2px; }
.status-pill { border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }
.status-connected { background: #e4f5e8; color: #1f6b3b; }
.status-qr_pending { background: #fff6df; color: #7a5b00; }
.status-new, .status-reconnecting, .status-disconnected { background: #eef1f5; color: #4d5969; }
.status-banned { background: #fde7e7; color: #9d2a2a; }
.instance-id-box { background: #f7faf1; border: 1px solid #dce5ca; border-radius: 10px; padding: 12px; margin-bottom: 8px; font-size: 24px; font-weight: 700; color: #45a75f; }
.qr-grid { align-items: start; }
.steps { margin: 4px 0 12px 22px; padding: 0; line-height: 1.8; }
.inbox-chat { display: grid; grid-template-columns: 320px 1fr; gap: 12px; min-height: 520px; }
.thread-list { border: 1px solid #dce3cb; border-radius: 10px; background: #fff; padding: 10px; display: grid; gap: 8px; }
.thread-row { padding: 10px; border-bottom: 1px solid #edf0e4; cursor: pointer; }
.thread-row:hover { background: #f4f8eb; }
.thread-row.active { background: #e8f6eb; border-left: 4px solid #1f9d55; }
.thread-title { font-weight: 700; font-size: 13px; }
.thread-meta { font-size: 12px; color: var(--muted); }
.chat-view { border: 1px solid #dce3cb; border-radius: 10px; background: #f7f9f1; display: grid; grid-template-rows: auto 1fr auto auto; overflow: hidden; }
.chat-header { padding: 10px 12px; border-bottom: 1px solid #e6ebd9; background: #eff4e2; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chat-messages { padding: 12px; overflow: auto; display: grid; gap: 10px; align-content: start; }
.bubble { max-width: 72%; padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; white-space: pre-wrap; }
.bubble.in { justify-self: start; background: #fff; border: 1px solid #dfe6cf; }
.bubble.out { justify-self: end; background: #ddf7e3; border: 1px solid #bde8c8; }
.bubble-meta { display: block; margin-top: 6px; font-size: 11px; color: #6a7868; }
.reply-btn { margin-top: 8px; font-size: 11px; padding: 4px 8px; border-radius: 8px; }
.chat-compose { border-top: 1px solid #e6ebd9; background: #fff; padding: 10px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.reply-context { margin: 8px 10px; padding: 8px; border: 1px dashed #b8cda8; border-radius: 8px; background: #f4fae9; font-size: 12px; }
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .layout.auth-only .content { padding: 20px 12px; align-items: start; }
  .layout.auth-only .panel[data-section="auth"] { padding: 12px; }
  .auth-wrap { max-width: 100%; margin: 0; }
  .grid.two { grid-template-columns: 1fr; }
  .grid.three { grid-template-columns: 1fr; }
  .grid.four { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .dashboard-kpis { grid-template-columns: 1fr 1fr; }
  .wa-toolbar { flex-wrap: wrap; }
  .wa-toolbar input { width: 100%; }
  .inbox-chat { grid-template-columns: 1fr; }
  .bubble { max-width: 92%; }
  .inbox-filters { grid-template-columns: 1fr; align-items: stretch; }
  .send-card { max-width: 100%; }
  .compact-list { max-height: 260px; }
  .report-table-wrap { max-height: 320px; }
}
