:root {
  --bg: #0b141a;
  --surface: #111b21;
  --surface-2: #18252d;
  --border: #23333d;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-hover: #06cf9c;
  --accent-soft: rgba(0, 168, 132, 0.14);
  --danger: #f15c6d;
  --danger-soft: rgba(241, 92, 109, 0.14);
  --warn: #f5b942;
  --warn-soft: rgba(245, 185, 66, 0.14);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.accent { color: var(--accent-hover); }
.mt-8 { margin-top: 8px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}
.brand-badge {
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card h1 { margin: 0 0 8px; font-size: 21px; }
.login-form { text-align: left; margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.login-form label { font-size: 12px; color: var(--muted); font-weight: 600; }
.login-download { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
}

/* App Shell */
.app-shell {
  max-width: 780px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 80px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(17, 27, 33, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.app-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topbar-title { font-weight: 700; font-size: 15px; }
.topbar-sub { font-size: 11px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

.content { padding: 14px; display: flex; flex-direction: column; gap: 12px; }

.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
}
.hero-card {
  background: linear-gradient(145deg, #13252a 0%, #111b21 75%);
  border-color: rgba(0, 168, 132, 0.35);
}
.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.hero-heading { margin: 8px 0 4px; font-size: 18px; }
.hero-meta {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.card-head h3 { margin: 0; font-size: 15px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-hover);
}
.pill.off { background: var(--danger-soft); color: var(--danger); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-ok { background: var(--accent-soft); color: var(--accent-hover); border-color: rgba(0, 168, 132, 0.3); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(245, 185, 66, 0.3); }
.badge-wa { background: rgba(37, 211, 102, 0.14); color: #25d366; border: none; }
.badge-wab { background: rgba(56, 189, 248, 0.14); color: #38bdf8; border: none; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
}
.stat-label { font-size: 11px; color: var(--muted); font-weight: 600; }
.stat-val { font-size: 24px; font-weight: 800; margin: 4px 0 2px; }
.stat-val.small-num { font-size: 19px; }
.stat-sub { font-size: 11px; color: var(--muted); }

/* Permissions & toggles */
.perm-list { display: flex; flex-direction: column; gap: 10px; }
.perm-item, .toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.perm-item:last-child, .toggle-row:last-child { border-bottom: none; }
.perm-title { font-weight: 600; font-size: 13px; }
.perm-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  display: inline-block;
}
.status-dot.ok { background: var(--accent-hover); box-shadow: 0 0 8px rgba(6, 207, 156, 0.6); }

.callout {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--warn-soft);
  border: 1px solid rgba(245, 185, 66, 0.3);
  color: #fde68a;
  font-size: 12px;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid rgba(0, 168, 132, 0.4);
}

/* Switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch-lg { width: 54px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #2c3e49;
  border-radius: 999px;
  transition: 0.2s;
}
.slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch-lg .slider:before { height: 24px; width: 24px; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); }
.switch-lg input:checked + .slider:before { transform: translateX(24px); }

/* Inputs & Buttons */
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #052019; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(241, 92, 109, 0.25); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: none; color: var(--accent-hover); font-weight: 600; font-size: 12px; cursor: pointer; }
.btn-group { display: flex; gap: 6px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Filters & Lists */
.filter-bar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.list-stack { display: flex; flex-direction: column; gap: 8px; }
.item-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
}
.item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.item-title { font-weight: 700; font-size: 13.5px; word-break: break-word; }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item-body {
  margin-top: 7px;
  font-size: 13px;
  color: #dbe4e8;
  white-space: pre-wrap;
  word-break: break-word;
}
.item-foot {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }

/* Settings Form */
.setting-group { margin-bottom: 10px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview-box {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 168, 132, 0.08);
  border: 1px dashed rgba(0, 168, 132, 0.35);
  font-size: 12px;
}

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

.debug-details { margin-top: 8px; }
.debug-details summary { cursor: pointer; user-select: none; }
.debug-code {
  display: block;
  margin-top: 6px;
  padding: 8px;
  border-radius: 8px;
  background: #0b141a;
  border: 1px solid var(--border);
  color: #93c5fd;
  font-size: 11px;
  word-break: break-all;
  white-space: pre-wrap;
}

.field-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.sim-result {
  margin-top: 10px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(0, 168, 132, 0.1);
  border: 1px solid rgba(0, 168, 132, 0.35);
  font-size: 13px;
}
.sim-result.sim-error {
  background: var(--danger-soft);
  border-color: rgba(241, 92, 109, 0.35);
}

.chat-pair {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-in, .chat-out {
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-in { background: #101a20; border: 1px solid var(--border); }
.chat-out { background: rgba(0, 168, 132, 0.12); border: 1px solid rgba(0, 168, 132, 0.28); }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 780px;
  background: rgba(17, 27, 33, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}
.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 10px;
}
.nav-btn.active { color: var(--accent-hover); background: var(--accent-soft); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: #1f2f38;
  color: #fff;
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
