*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --green: #008571;
  --green-dim: #014d49;
  --amber: #e6a23c;
  --red: #e85d5d;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, sans-serif;
  --sidebar-w: 240px;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Shell ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green-dim), var(--green));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
}

.sidebar-brand strong {
  display: block;
  font-size: 0.95rem;
}

.sidebar-brand small {
  color: var(--muted);
  font-size: 0.72rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.nav-item.active {
  background: rgba(0, 133, 113, 0.18);
  color: #5eead4;
  font-weight: 600;
}

.nav-icon {
  font-size: 0.9rem;
  width: 1.25rem;
  text-align: center;
}

.sidebar-foot {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.sidebar-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.sidebar-status.connected .dot { background: #4ade80; }
.sidebar-status.connected { color: #5eead4; }
.sidebar-status.qr .dot { background: var(--amber); }
.sidebar-status.qr { color: #f5d08a; }
.sidebar-status.disconnected .dot { background: var(--red); }

.content-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: linear-gradient(135deg, var(--green-dim), var(--green));
  padding: 1.1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  flex-shrink: 0;
}

.menu-bar {
  display: block;
  width: 20px;
  height: 2px;
  margin: 0 auto;
  background: #fff;
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

body.drawer-open .menu-toggle .menu-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.drawer-open .menu-toggle .menu-bar:nth-child(2) {
  opacity: 0;
}

body.drawer-open .menu-toggle .menu-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.topbar-titles {
  flex: 1;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.topbar p {
  margin: 0.1rem 0 0;
  font-size: 0.82rem;
  opacity: 0.9;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.25);
}

.badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.badge.connected .dot { background: #4ade80; }
.badge.qr .dot { background: var(--amber); }
.badge.disconnected .dot { background: var(--red); }

/* ── Views ── */
.views {
  flex: 1;
  padding: 1.5rem;
  max-width: 960px;
}

.view {
  display: none;
  animation: fadeIn 0.2s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.view-intro {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  color: var(--muted);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.card .sub {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.15rem;
}

.stat-hint {
  font-size: 0.72rem;
  color: var(--muted);
}

.flow-list {
  margin: 0 0 1.25rem;
  padding-left: 1.25rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.flow-list li {
  margin-bottom: 0.45rem;
}

.flow-list li::marker {
  color: var(--green);
}

/* ── Conexão ── */
.conn-methods {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.method-card {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}

.method-card .btn-block {
  margin-top: auto;
}

.qr-preview {
  flex: 1;
  min-height: 200px;
  background: #fff;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  padding: 1rem;
}

.qr-preview img {
  max-width: 220px;
  height: auto;
}

.qr-placeholder {
  color: #888;
  font-size: 0.85rem;
  margin: 0;
  text-align: center;
  padding: 0 0.5rem;
}

.qr-hint {
  margin-top: -0.5rem !important;
  color: #5eead4 !important;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 1.25rem;
  background: #fff;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.qr-wrap img {
  max-width: 240px;
  height: auto;
}

.conn-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.conn-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
}

.conn-avatar.connected {
  background: rgba(0, 133, 113, 0.25);
  color: #5eead4;
  border: 2px solid var(--green);
}

.connected-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.connected-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.connected-number {
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.pairing-box {
  text-align: center;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--surface2);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.pairing-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.pairing-code {
  display: inline-block;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--green-dim);
  background: #fff;
  padding: 0.85rem 1.5rem;
  border-radius: 10px;
}

/* ── Formulários ── */
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

input[type='text'],
input[type='tel'],
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.field {
  margin-bottom: 0.85rem;
}

.btn {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--green);
  color: #fff;
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--red);
  color: #fff;
}

/* ── Cenários ── */
.scenario-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.scenario-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  background: var(--surface2);
}

.scenario-item header {
  background: none;
  padding: 0;
  margin-bottom: 0.5rem;
}

.scenario-item h3 {
  margin: 0;
  font-size: 0.92rem;
}

.scenario-item .id {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: monospace;
}

.scenario-item p.desc {
  margin: 0.25rem 0 0.6rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.sticky-actions {
  display: flex;
  gap: 0.6rem;
  padding: 1rem 0;
  position: sticky;
  bottom: 0;
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* ── Simulador ── */
.sim-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.sim-scenario-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.anti-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.risk-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.risk-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.risk-item .level {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.risk-item .level.high { background: rgba(232, 93, 93, 0.25); color: #f0a0a0; }
.risk-item .level.medium { background: rgba(230, 162, 60, 0.2); color: #f5d08a; }
.risk-item .level.low { background: rgba(0, 133, 113, 0.2); color: #5eead4; }

.blocked-list {
  font-size: 0.8rem;
  color: var(--muted);
}

.blocked-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

/* ── Log ── */
.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-toolbar h2 {
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.log-table th,
.log-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.log-table th {
  color: var(--muted);
  font-weight: 600;
}

.empty-cell {
  color: var(--muted);
  text-align: center !important;
  padding: 1.5rem !important;
}

.tag {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: monospace;
}

.tag.ok { background: rgba(0, 133, 113, 0.25); color: #5eead4; }
.tag.pending { background: rgba(100, 149, 237, 0.2); color: #93c5fd; }
.tag.warn { background: rgba(230, 162, 60, 0.2); color: var(--amber); }
.tag.err { background: rgba(232, 93, 93, 0.2); color: var(--red); }

.alert {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

.alert.warn {
  background: rgba(230, 162, 60, 0.15);
  border: 1px solid rgba(230, 162, 60, 0.35);
  color: #f5d08a;
}

.saved-toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--green);
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 100;
}

.saved-toast.show { opacity: 1; }

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
  backdrop-filter: blur(2px);
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .topbar {
    flex-wrap: nowrap;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .topbar p {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .badge {
    font-size: 0.72rem;
    padding: 0.3rem 0.6rem;
    flex-shrink: 0;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 85vw);
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }

  body.drawer-open .sidebar {
    transform: translateX(0);
  }

  body.drawer-open .mobile-overlay {
    display: block;
  }

  .sidebar-nav {
    flex-direction: column;
    overflow-x: visible;
    padding: 0.75rem 0.5rem;
    gap: 0.2rem;
  }

  .nav-item {
    white-space: normal;
    font-size: 0.88rem;
    padding: 0.7rem 0.85rem;
  }

  .sidebar-foot {
    display: block;
  }

  .content-wrap {
    width: 100%;
  }

  .views {
    padding: 1rem;
    max-width: none;
  }
}
