:root {
  --color-bg: oklch(1 0 0);
  --color-surface: oklch(0.975 0.006 256);
  --color-surface-strong: oklch(0.945 0.01 256);
  --color-ink: oklch(0.205 0.025 256);
  --color-muted: oklch(0.46 0.025 256);
  --color-border: oklch(0.875 0.012 256);
  --color-primary: oklch(0.52 0.16 256);
  --color-primary-hover: oklch(0.45 0.17 256);
  --color-accent: oklch(0.57 0.12 174);
  --color-success: oklch(0.49 0.13 152);
  --color-warning: oklch(0.66 0.15 76);
  --color-danger: oklch(0.53 0.19 27);
  --color-info-bg: oklch(0.95 0.035 256);
  --radius: 6px;
  --nav-width: 232px;
  --topbar-height: 56px;
  --z-topbar: 50;
  --z-nav-overlay: 90;
  --z-nav: 100;
  --z-drawer: 200;
  --z-modal: 300;
  --z-toast: 400;
  --z-tooltip: 500;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { font-size: 14px; }

body {
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-ink);
  line-height: 1.5;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  min-width: 320px;
}

/* ── Login ─────────────────────────────── */

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  padding: 1rem;
}

.login-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-icon { margin-bottom: 1rem; opacity: 0.7; }
.login-card h1 { font-size: 24px; font-weight: 700; }
.login-subtitle { color: var(--color-muted); font-size: 13px; margin-top: 0.25rem; margin-bottom: 1.5rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; text-align: left; }
.login-error { color: var(--color-danger); font-size: 13px; }

/* ── App Layout ────────────────────────── */

.app-view { display: flex; min-height: 100vh; }

.nav-rail {
  width: var(--nav-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: var(--z-nav);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  height: var(--topbar-height);
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.nav-list { flex: 1; padding: 0.5rem 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  color: var(--color-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 150ms ease-out, color 150ms ease-out;
  white-space: nowrap;
}

.nav-item:hover { background: var(--color-surface-strong); color: var(--color-ink); }
.nav-item.active { background: var(--color-info-bg); color: var(--color-primary); font-weight: 600; }

.nav-logout {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border: none;
  border-top: 1px solid var(--color-border);
  background: none;
  color: var(--color-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: color 150ms ease-out;
}
.nav-logout:hover { color: var(--color-danger); }

.nav-overlay {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.3);
  z-index: var(--z-nav-overlay);
}

.main-area {
  flex: 1;
  margin-left: var(--nav-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.top-bar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--color-bg);
  z-index: var(--z-topbar);
}

.top-bar h2 { font-size: 18px; font-weight: 600; }
.top-bar-actions { margin-left: auto; display: flex; gap: 0.5rem; }

.menu-toggle { display: none; border: none; background: none; cursor: pointer; padding: 0.25rem; }

.content { padding: 1.25rem; flex: 1; overflow-x: auto; }

/* ── Buttons ───────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  height: 34px;
  padding: 0 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 150ms ease-out, border-color 150ms ease-out;
  white-space: nowrap;
}
.btn:hover { background: var(--color-surface); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

.btn-ghost { border-color: transparent; }
.btn-ghost:hover { background: var(--color-surface); border-color: var(--color-border); }

.btn-danger { color: var(--color-danger); border-color: var(--color-border); }
.btn-danger:hover { background: oklch(0.53 0.19 27 / 0.08); border-color: var(--color-danger); }

.btn-sm { height: 28px; padding: 0 0.625rem; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Fields ────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field-label { font-size: 12px; color: var(--color-muted); font-weight: 500; }

.input, .select {
  height: 36px;
  padding: 0 0.625rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-ink);
  font: inherit;
  font-size: 14px;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
  width: 100%;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px oklch(0.52 0.16 256 / 0.12);
}
textarea.input { height: auto; min-height: 72px; padding: 0.5rem 0.625rem; resize: vertical; }

/* ── Summary Band ──────────────────────── */

.summary-band {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.summary-item {
  padding: 0.875rem 1rem;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.summary-item:last-child { border-right: none; }

.summary-label { font-size: 12px; color: var(--color-muted); }
.summary-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }

/* ── Tables ────────────────────────────── */

.table-wrap {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: auto;
  margin-bottom: 1.25rem;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--color-muted);
  white-space: nowrap;
  z-index: 1;
}

tbody td {
  padding: 0 0.75rem;
  height: 44px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-surface); }

.td-actions { text-align: right; white-space: nowrap; }
.td-actions .btn { margin-left: 0.25rem; }

/* ── Status Badges ─────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 12px;
  font-weight: 500;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.active { background: var(--color-success); }
.status-dot.disabled { background: var(--color-danger); }
.status-dot.available { background: var(--color-muted); }
.status-dot.assigned { background: var(--color-accent); }
.status-dot.queued, .status-dot.originating, .status-dot.ringing { background: var(--color-warning); }
.status-dot.answered { background: var(--color-success); }
.status-dot.ended { background: var(--color-muted); }
.status-dot.failed { background: var(--color-danger); }

/* ── Sections ──────────────────────────── */

.section { margin-bottom: 1.5rem; }
.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.section-header h3 { font-size: 18px; font-weight: 600; }
.section-header .btn,
.section-header .btn-primary { margin-left: auto; }

/* ── Drawer ────────────────────────────── */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.25);
  z-index: var(--z-drawer);
  display: flex;
  justify-content: flex-end;
  animation: fade-in 150ms ease-out;
}

.drawer {
  width: 420px;
  max-width: 100%;
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
}

.drawer-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.drawer-header h3 { font-size: 18px; font-weight: 600; }
.drawer-close { margin-left: auto; }

.drawer-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; flex: 1; }
.drawer-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--color-border); display: flex; gap: 0.5rem; justify-content: flex-end; flex-shrink: 0; }

/* ── Modal ─────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.25);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fade-in 150ms ease-out;
}

.modal {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  max-width: 400px;
  width: 100%;
  padding: 1.5rem;
}

.modal h3 { font-size: 18px; font-weight: 600; margin-bottom: 0.5rem; }
.modal p { color: var(--color-muted); font-size: 13px; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ── Toast ─────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--color-ink);
  color: white;
  padding: 0.625rem 1rem;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slide-in 200ms ease-out;
  max-width: 360px;
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }

/* ── Misc ──────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-muted);
  font-size: 13px;
}

.mono { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; font-size: 12px; }
.muted { color: var(--color-muted); }
.text-sm { font-size: 12px; }
.text-right { text-align: right; }
.font-mono { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; }
.tabular { font-variant-numeric: tabular-nums; }

.health-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}
.health-card h4 { font-size: 14px; font-weight: 600; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.health-row { display: flex; justify-content: space-between; padding: 0.25rem 0; font-size: 13px; border-bottom: 1px solid var(--color-border); }
.health-row:last-child { border-bottom: none; }
.health-key { color: var(--color-muted); }
.health-val { font-variant-numeric: tabular-nums; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }

/* ── Tooltips & ajuda ─────────────────── */

.tip-wrap {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
  margin-left: 0.25rem;
}

.tip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: none;
  color: var(--color-muted);
  cursor: help;
  border-radius: 50%;
  transition: color 150ms ease-out, background 150ms ease-out;
}
.tip-btn:hover,
.tip-btn:focus-visible {
  color: var(--color-primary);
  background: var(--color-info-bg);
  outline: none;
}

.tip-pop {
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: min(280px, 70vw);
  padding: 0.625rem 0.75rem;
  background: var(--color-ink);
  color: white;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  z-index: var(--z-tooltip);
  box-shadow: 0 4px 8px oklch(0 0 0 / 0.18);
  pointer-events: none;
}
.tip-pop strong {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.tip-pop p { margin: 0; opacity: 0.92; }

.tip-wrap:hover .tip-pop,
.tip-wrap:focus-within .tip-pop { display: block; }

.info-box {
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-info-bg);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-ink);
}
.info-box.muted-box {
  background: var(--color-surface);
  color: var(--color-muted);
}
.info-box.roadmap-box {
  border-color: oklch(0.57 0.12 174 / 0.35);
  background: oklch(0.96 0.03 174);
}
.info-box-icon { flex-shrink: 0; opacity: 0.75; margin-top: 1px; }
.info-box p { margin: 0; }
.info-box p + p { margin-top: 0.5rem; }

.label-with-tip {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
}

/* ── Glossário ─────────────────────────── */

.glossary-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
}
.glossary-search {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}

.glossary-category {
  margin-bottom: 1.5rem;
}
.glossary-category h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 0.625rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid var(--color-border);
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.625rem;
}

.glossary-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 0.875rem;
  background: var(--color-bg);
  transition: border-color 150ms ease-out;
}
.glossary-card:hover { border-color: var(--color-primary); }
.glossary-card h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 0.375rem;
}
.glossary-card p {
  font-size: 12px;
  color: var(--color-muted);
  line-height: 1.45;
  margin: 0;
}
.glossary-card .glossary-short {
  font-size: 11px;
  color: var(--color-accent);
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.glossary-roadmap {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--color-surface);
}
.glossary-roadmap h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.glossary-roadmap ul {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 13px;
  color: var(--color-muted);
  line-height: 1.6;
}
.glossary-roadmap li + li { margin-top: 0.375rem; }
.glossary-roadmap strong { color: var(--color-ink); }

/* ── Alertas, fluxos, gravações, SMS ─── */

.alert-badge {
  display: inline-flex;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.alert-badge.critical { background: oklch(0.53 0.19 27 / 0.12); color: var(--color-danger); }
.alert-badge.warning { background: oklch(0.66 0.15 76 / 0.15); color: oklch(0.45 0.12 76); }
.alert-badge.info { background: var(--color-info-bg); color: var(--color-primary); }
.alert-count-critical { color: var(--color-danger); }
.info-box.alert-banner {
  border-color: oklch(0.66 0.15 76 / 0.4);
  background: oklch(0.97 0.03 76);
}

.msg-preview { max-width: 200px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--color-muted); }

.recording-player { height: 28px; max-width: 220px; }

.flow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.flow-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  background: var(--color-bg);
}
.flow-card h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.flow-inbound h4 { color: oklch(0.52 0.16 256); }
.flow-outbound h4 { color: oklch(0.57 0.12 174); }
.flow-sms h4 { color: oklch(0.55 0.14 300); }
.flow-webrtc h4 { color: oklch(0.5 0.12 50); }
.flow-steps {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 13px;
  color: var(--color-muted);
  line-height: 1.6;
}
.flow-steps li + li { margin-top: 0.375rem; }

.copy-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0.125rem;
  color: var(--color-muted);
  display: inline-flex;
  vertical-align: middle;
  transition: color 150ms ease-out;
}
.copy-btn:hover { color: var(--color-primary); }

/* ── Animations ────────────────────────── */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Responsive ────────────────────────── */

@media (max-width: 768px) {
  .nav-rail { transform: translateX(-100%); transition: transform 200ms ease-out; }
  .nav-rail.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .menu-toggle { align-items: center; display: inline-flex; justify-content: center; min-height: 44px; min-width: 44px; }
  .top-bar h2 { font-size: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .summary-band { grid-template-columns: repeat(2, 1fr); }
  .summary-item:nth-child(2n) { border-right: none; }
  .drawer { padding-bottom: env(safe-area-inset-bottom); width: 100%; }
  .content { padding: 0.75rem max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left)); }
  .top-bar { min-height: var(--topbar-height); padding-left: max(0.5rem, env(safe-area-inset-left)); padding-right: max(0.75rem, env(safe-area-inset-right)); }
  .btn { min-height: 44px; }
  .btn-sm { font-size: 13px; min-height: 40px; }
  .input, .select { min-height: 44px; }
  .nav-item { min-height: 44px; }
  .tip-btn { height: 32px; width: 32px; }
  .toast-container { bottom: max(0.75rem, env(safe-area-inset-bottom)); left: 0.75rem; right: 0.75rem; }
  .toast { max-width: none; width: 100%; }
}
