:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --wa: #25d366;
  --wa-dark: #128c7e;
  --sidebar: #0b1220;
  --danger: #dc2626;
  --orange: #f59e0b;
  --purple: #7c3aed;
  --success: #16a34a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.86em; background: #f1f5f9; padding: 2px 6px; border-radius: 5px; }

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

.gate { 
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(145deg, #ecfdf5, #eff6ff 55%, #f8fafc);
}
.gate-card {
  width: min(420px, 100%); background: #fff; border-radius: 20px;
  padding: 32px 28px; box-shadow: 0 25px 60px rgba(15,23,42,.12); animation: rise .4s ease both;
}
.gate-card h1 { margin: 14px 0 8px; font-size: 1.5rem; }
.lede { color: var(--muted); margin: 0 0 18px; line-height: 1.55; }

.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row strong { display: block; line-height: 1.15; }
.brand-row small { color: var(--muted); font-size: .78rem; }
.logo {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--wa), var(--wa-dark));
  color: #fff; font-weight: 800; box-shadow: 0 8px 20px rgba(37,211,102,.35);
}

label { display: block; font-weight: 700; font-size: .86rem; margin-bottom: 6px; color: #334155; }
input, select, textarea {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 11px;
  padding: 11px 12px; background: #fff; outline: none; margin-bottom: 12px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}
.hint { margin: -4px 0 12px; color: var(--muted); font-size: .82rem; }
.hint.center { text-align: center; margin-top: 12px; }
.form-error { color: var(--danger); margin-top: 10px; }
.form-result { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.form-result.ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.form-result.err { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.muted { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 11px; padding: 10px 14px;
  font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.03); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; border-color: #cbd5e1; color: #334155; }
.btn-ghost { background: transparent; border-color: #e2e8f0; color: #475569; }
.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-sm { padding: 6px 10px; font-size: .8rem; }
.btn-lg { padding: 14px 18px; font-size: .95rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; animation: rise .35s ease both; }
.sidebar {
  background: var(--sidebar); color: #fff; padding: 18px 12px;
  display: flex; flex-direction: column; gap: 16px;
}
.sidebar-brand { padding: 6px 10px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand small { color: #94a3b8; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  width: 100%; text-align: left; border: 0; background: transparent;
  color: #94a3b8; border-radius: 11px; padding: 12px 12px; cursor: pointer; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}
.nav-item .ni {
  width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center;
  background: rgba(255,255,255,.08); font-size: .72rem; font-weight: 800;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(37,211,102,.18), rgba(37,99,235,.16));
  color: #fff; box-shadow: inset 3px 0 0 var(--wa);
}
.nav-item.active .ni { background: var(--wa); color: #052e16; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; padding: 8px; }
.sidebar .btn-ghost { color: #cbd5e1; border-color: rgba(255,255,255,.12); }

.health-pill {
  display: flex; align-items: center; gap: 8px; font-size: .82rem; color: #cbd5e1;
  padding: 8px 10px; border-radius: 999px; background: rgba(255,255,255,.06);
}
.health-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.health-pill.ok .dot { background: var(--wa); box-shadow: 0 0 0 4px rgba(37,211,102,.2); }
.health-pill.bad .dot { background: var(--danger); }

.shell { min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 18px 24px; background: #fff; border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 1.35rem; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.main { padding: 20px 24px 40px; }

.view { display: none; animation: rise .28s ease both; }
.view.active { display: block; }

.guide { display: grid; gap: 12px; margin-bottom: 16px; }
.guide-step {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.gs-num {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  background: #eff6ff; color: var(--primary); font-weight: 800; font-size: 1.2rem;
}
.gs-body h3 { margin: 0 0 4px; font-size: 1.05rem; }
.gs-body p { margin: 0 0 10px; color: var(--muted); font-size: .9rem; }
.gs-status {
  padding: 6px 12px; border-radius: 999px; font-size: .78rem; font-weight: 800;
  background: #f1f5f9; color: #64748b; white-space: nowrap;
}
.gs-status.ok { background: #ecfdf5; color: #047857; }
.gs-status.soft { background: #eff6ff; color: #1d4ed8; }

.info-banner {
  background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a;
  border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: .92rem;
}

.stat-row { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; border-top: 3px solid transparent;
}
.stat span { display: block; color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.stat strong { display: block; margin-top: 4px; font-size: 1.35rem; }
.s-green { border-top-color: var(--wa); }
.s-blue { border-top-color: var(--primary); }
.s-orange { border-top-color: var(--orange); }
.s-purple { border-top-color: var(--purple); }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 14px;
}
.card-title { margin: 0 0 12px; font-size: 1.05rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head .card-title { margin: 0; }
.card-head-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.pill { background: #eff6ff; color: var(--primary); border-radius: 999px; padding: 4px 10px; font-size: .78rem; font-weight: 800; }

.grid-2 { display: grid; grid-template-columns: 340px 1fr; gap: 14px; align-items: start; }
.compose-grid { grid-template-columns: 1.15fr .85fr; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 8px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.connected { background: #ecfdf5; color: #047857; }
.badge.qr, .badge.connecting, .badge.starting { background: #fffbeb; color: #b45309; }
.badge.disconnected, .badge.stopped, .badge.logged_out { background: #f1f5f9; color: #64748b; }

.check { display: flex !important; align-items: center; gap: 8px; font-weight: 600 !important; margin-bottom: 12px; cursor: pointer; }
.check input { width: auto !important; margin: 0 !important; }

.meter { display: grid; gap: 6px; margin-top: 10px; }
.meter-label { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.meter-bar { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.meter-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #16a34a, #25d366); }
.meter-fill.warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.meter-fill.danger { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.chip { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800; background: #ecfdf5; color: #047857; }
.chip.warn { background: #fffbeb; color: #b45309; }
.chip.off { background: #f1f5f9; color: #64748b; }

.client-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px; margin-bottom: 14px;
}
.client-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; border: 2px solid transparent; cursor: pointer;
}
.client-card:hover { border-color: #bfdbfe; }
.client-card.active { border-color: var(--primary); }
.client-card h4 { margin: 0 0 6px; }
.client-card p { margin: 0; color: var(--muted); font-size: .86rem; word-break: break-all; }
.client-card .row { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 8px; }

.detail-card { border: 1px solid #dbeafe; }
.big-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.simple-fields { display: grid; gap: 12px; margin-bottom: 14px; }
.simple-fields label { margin-bottom: 6px; }
.mono-block {
  display: block; background: #0f172a; color: #a7f3d0; border-radius: 10px;
  padding: 12px; word-break: break-all; font-size: .85rem;
}
.more-box {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px;
}
.more-box summary { cursor: pointer; font-weight: 700; color: #334155; }
.danger-row { border-top: 1px solid var(--line); padding-top: 14px; }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab {
  border: 1px solid var(--line); background: #fff; border-radius: 9px;
  padding: 6px 12px; cursor: pointer; font-weight: 700; font-size: .82rem; color: var(--muted);
}
.tab.active { background: #eff6ff; border-color: #bfdbfe; color: var(--primary); }
.snippet {
  margin: 0 0 10px; background: #0f172a; color: #e2e8f0; border-radius: 12px;
  padding: 14px; overflow: auto; max-height: 260px;
}
.snippet code { background: transparent; color: inherit; padding: 0; white-space: pre-wrap; word-break: break-word; font-size: .8rem; }

.modal { border: 0; padding: 0; background: transparent; max-width: 440px; width: calc(100% - 32px); }
.modal::backdrop { background: rgba(15,23,42,.55); }
.modal-card { background: #fff; border-radius: 18px; padding: 18px; box-shadow: 0 24px 60px rgba(15,23,42,.25); }
.modal-card header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.modal-card h3 { margin: 0; }
.qr-box {
  min-height: 280px; display: grid; place-items: center; background: #f8fafc;
  border: 1px dashed #cbd5e1; border-radius: 12px; padding: 16px; color: var(--muted);
}
.qr-box img { width: min(250px, 100%); background: #fff; padding: 10px; border-radius: 10px; }

.toast {
  position: fixed; z-index: 60; bottom: 20px; right: 20px;
  background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 12px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast.err { background: #991b1b; }

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 10px 10px 8px;
    gap: 8px;
  }
  .sidebar-brand { 
    padding: 4px 6px 8px;
  }
  .sidebar-brand small { display: none; }
  .logo { width: 36px; height: 36px; border-radius: 10px; }
  .nav {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 4px;
  }
  .nav-item {
    flex: 0 0 auto;
    padding: 10px 12px;
    font-size: .85rem;
  }
  .sidebar-foot { display: none; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 14px;
    gap: 10px;
  }
  .topbar h2 { font-size: 1.2rem; }
  .main { padding: 14px 14px 28px; }
  .stat-row, .grid-2, .compose-grid { grid-template-columns: 1fr; }
  .guide-step {
    grid-template-columns: 40px 1fr;
    gap: 10px;
    padding: 14px;
  }
  .gs-num { width: 40px; height: 40px; border-radius: 12px; font-size: 1rem; }
  .gs-status { grid-column: 2; justify-self: start; }
  .gs-body .btn { width: 100%; }
  .card-head-row { flex-direction: column; align-items: stretch; }
  .card-head-row .btn { width: 100%; }
  .big-actions { flex-direction: column; }
  .big-actions .btn { width: 100%; }
  .client-grid { grid-template-columns: 1fr; }
  .table { font-size: .82rem; }
  .table th, .table td { padding: 10px 6px; }
  .btn-row .btn { flex: 1 1 auto; }
  .modal { width: calc(100% - 20px); max-width: none; }
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

@media (max-width: 480px) {
  .nav-item .ni { display: none; }
  .stat strong { font-size: 1.15rem; }
}
