:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-outbound: #2a78d6;
  --series-inbound: #008300;
  --series-prompt: #eb6834;
  --series-completion: #1baf7a;
  --status-critical: #d03b3b;
  --status-good: #0ca30c;
  --status-warning: #fab219;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-outbound: #3987e5;
    --series-inbound: #008300;
    --series-prompt: #d95926;
    --series-completion: #199e70;
    --status-critical: #e66767;
    --status-good: #0ca30c;
    --status-warning: #fab219;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
body { min-height: 100vh; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }

/* ---------- login ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
}
.field input:focus { outline: 2px solid var(--series-outbound); outline-offset: 1px; }
.btn {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--series-outbound);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; filter: none; }
.btn.secondary { background: transparent; color: var(--text-primary); border: 1px solid var(--border); font-weight: 500; }
.error-msg { color: var(--status-critical); font-size: 13px; margin-top: 12px; min-height: 16px; }

/* ---------- dashboard ---------- */
header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
header.top h1 { font-size: 16px; margin: 0; }
header.top .who { color: var(--text-secondary); font-size: 13px; }

.nav-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.nav-tab {
  padding: 10px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.nav-tab.active { color: var(--series-outbound); border-bottom-color: var(--series-outbound); }

.channel-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.portal-filter {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 13px;
  margin-bottom: 12px;
  max-width: 320px;
}

.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 8px; }
#send-text-module { width: 100%; min-height: 120px; padding: 10px 12px; border-radius: 8px 8px 8px 8px; border: 1px solid var(--border); background: var(--page); color: var(--text-primary); font-size: 14px; font-family: inherit; resize: vertical; }

.fmt-toolbar { display: flex; gap: 4px; margin-bottom: 6px; }
.fmt-btn {
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
  line-height: 1.4;
}
.fmt-btn:hover { background: var(--page); }
.fmt-btn:active { filter: brightness(0.95); }

.results-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.results-table th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--gridline); }
.results-table td { padding: 6px 8px; border-bottom: 1px solid var(--gridline); }
.result-ok { color: var(--status-good); font-weight: 600; }
.result-err { color: var(--status-critical); font-weight: 600; }

.summary-row { display: flex; gap: 24px; margin-bottom: 20px; flex-wrap: wrap; }
.summary-tile { background: var(--page); border: 1px solid var(--gridline); border-radius: 8px; padding: 12px 18px; min-width: 120px; }
.summary-tile .value { font-size: 22px; font-weight: 700; }
.summary-tile .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 2px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab {
  padding: 8px 16px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.tab.active {
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-bottom-color: var(--surface-1);
  margin-bottom: -1px;
  font-weight: 600;
}

.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: 0 8px 8px 8px; padding: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--gridline); }
td { padding: 10px; border-bottom: 1px solid var(--gridline); vertical-align: top; }
tr.row-click { cursor: pointer; }
tr.row-click:hover td { background: var(--page); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active { background: color-mix(in srgb, var(--status-good) 18%, transparent); color: var(--status-good); }
.badge.trial { background: color-mix(in srgb, var(--status-warning) 22%, transparent); color: #8a5a00; }
.badge.blocked, .badge.canceled { background: color-mix(in srgb, var(--status-critical) 16%, transparent); color: var(--status-critical); }
.badge.pending_cancellation { background: color-mix(in srgb, var(--status-warning) 22%, transparent); color: #8a5a00; }
.badge.unknown { background: var(--page); color: var(--text-muted); }

.empty-msg, .loading-msg { color: var(--text-muted); font-size: 13px; padding: 24px 0; text-align: center; }

/* ---------- detail drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; justify-content: flex-end; z-index: 20;
}
.drawer {
  width: min(560px, 100%);
  height: 100%;
  background: var(--surface-1);
  overflow-y: auto;
  padding: 20px;
  border-left: 1px solid var(--border);
}
.drawer h2 { font-size: 16px; margin: 0 0 2px; }
.drawer .domain { color: var(--text-secondary); font-size: 13px; margin-bottom: 16px; }
.drawer .close-btn { float: right; cursor: pointer; color: var(--text-muted); font-size: 13px; background: none; border: none; }

.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 20px 0 8px; }
.section-title:first-of-type { margin-top: 0; }

/* legend */
.legend { display: flex; gap: 14px; margin-bottom: 8px; font-size: 12px; color: var(--text-secondary); }
.legend .dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 5px; }

/* bar chart */
.chart {
  display: flex; align-items: flex-end; gap: 4px; height: 100px; border-bottom: 1px solid var(--baseline); padding-bottom: 2px;
  /* Linhas horizontais discretas a cada 40px — só textura de referência, não compete com os dados. */
  background-image: repeating-linear-gradient(to top, var(--gridline) 0, var(--gridline) 1px, transparent 1px, transparent 40px);
  background-position: bottom left;
  background-repeat: repeat-x;
  background-size: 100% 100px;
}
.chart .day-group { flex: 1; display: flex; align-items: flex-end; gap: 1px; height: 100%; justify-content: center; }
.chart .bar { width: 6px; border-radius: 2px 2px 0 0; min-height: 1px; }
.chart-labels { display: flex; gap: 4px; margin-top: 4px; }
.chart-labels span { flex: 1; text-align: center; font-size: 9px; color: var(--text-muted); }

/* messages / conversations list */
.msg-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--gridline); border-radius: 8px; }
.msg-row { padding: 10px; border-bottom: 1px solid var(--gridline); font-size: 13px; }
.msg-row:last-child { border-bottom: none; }
.msg-row .meta { color: var(--text-muted); font-size: 11px; margin-bottom: 3px; display: flex; gap: 8px; }
.msg-row .kind-inbound { color: var(--series-inbound); font-weight: 600; }
.msg-row .kind-outbound { color: var(--series-outbound); font-weight: 600; }
.msg-search { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--page); color: var(--text-primary); font-size: 13px; margin-bottom: 8px; }
.load-more { margin-top: 8px; }

.send-box textarea {
  width: 100%; min-height: 80px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-primary);
  font-size: 13px; font-family: inherit; resize: vertical;
}
.send-status { font-size: 12px; margin-top: 6px; min-height: 14px; }
.send-status.ok { color: var(--status-good); }
.send-status.err { color: var(--status-critical); }

.conv-item { border: 1px solid var(--gridline); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.conv-item .head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.conv-item .head .name { font-weight: 600; }
.conv-item .head .time { color: var(--text-muted); font-size: 11px; }
.conv-item .history { display: none; margin-top: 8px; }
.conv-item.open .history { display: block; }
.conv-item .bubble { font-size: 12px; padding: 6px 8px; border-radius: 6px; margin-bottom: 4px; max-width: 90%; }
.conv-item .bubble.user { background: var(--page); }
.conv-item .bubble.assistant { background: color-mix(in srgb, var(--series-outbound) 12%, transparent); margin-left: auto; }

.backend-error { color: var(--status-critical); font-size: 12px; margin-bottom: 10px; }
