:root {
  --bg: #0b1120;
  --bg-elev: #111a2e;
  --bg-card: #162038;
  --bg-input: #0e1629;
  --border: #253352;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
  --accent-bg: rgba(16, 185, 129, 0.14);
  --danger: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --border: #dbe3ee;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #059669;
  --accent-bg: rgba(5, 150, 105, 0.1);
  --danger: #dc2626;
  --warn: #d97706;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* Overlay / Modals */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.login-card, .modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.modal-card { max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.brand-badge {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.login-card h1 { margin: 0 0 6px; font-size: 24px; }
.login-card form { margin-top: 20px; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.brand-mini {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  color: #fff;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav-tabs { display: flex; gap: 6px; }
.nav-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.nav-tab:hover { color: var(--text); background: rgba(148, 163, 184, 0.1); }
.nav-tab.active { color: #fff; background: var(--primary); }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
  font-weight: 600;
}
.status-pill .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
}
.status-pill.connected { background: var(--accent-bg); color: var(--accent); }
.status-pill.connected .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-pill.error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.status-pill.error .dot { background: var(--danger); }

/* Inputs & Buttons */
input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.form-row { margin-bottom: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.input-action { display: flex; gap: 8px; }
.input-action input { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: rgba(148, 163, 184, 0.12); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.35); }
.btn-danger-ghost:hover { background: rgba(239, 68, 68, 0.12); }
.btn-block { width: 100%; margin-top: 12px; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-xs { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.active { border-color: var(--primary); background: rgba(59, 130, 246, 0.16); }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-weight: 600; padding: 0 4px; }

/* Main Layout */
.main-content {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 18px 86px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-card.accent { border-color: rgba(16, 185, 129, 0.4); background: linear-gradient(145deg, var(--bg-card), rgba(16, 185, 129, 0.08)); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 800; margin-top: 4px; }

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.search-box { flex: 1; min-width: 220px; }
.toolbar select { width: auto; min-width: 160px; }

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.toggle-chip input { width: auto; margin: 0; }
.checkbox-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }

.phone-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.phone-chip {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.phone-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Message Cards */
.message-list { display: flex; flex-direction: column; gap: 12px; }
.msg-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: transform 0.15s, border-color 0.15s;
}
.msg-card.has-otp { border-left: 4px solid var(--accent); }
.msg-card.new-flash { animation: flashNew 1.4s ease; }
@keyframes flashNew {
  0% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.55); }
  100% { box-shadow: none; }
}

.msg-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.msg-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text);
}
.badge-source { background: rgba(59, 130, 246, 0.18); color: #60a5fa; }
[data-theme="light"] .badge-source { color: #1d4ed8; }
.badge-phone { background: rgba(16, 185, 129, 0.16); color: var(--accent); }
.badge-slot { background: rgba(245, 158, 11, 0.16); color: var(--warn); }
.msg-meta-right { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }

.otp-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent-bg);
  border: 1px solid rgba(16, 185, 129, 0.32);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.otp-code-value {
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--accent);
  cursor: pointer;
}
.msg-body {
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.otp-inline {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 5px;
}

/* Section Headers & Cards */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-header h2 { margin: 0 0 4px; font-size: 19px; }
.section-header p { margin: 0; font-size: 13px; }

.device-grid, .pusher-grid, .pairing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}
.pairing-grid { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.panel-card, .device-card, .pusher-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.panel-card h2 { margin: 0 0 6px; font-size: 17px; }

.device-head, .pusher-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}
.device-title { font-weight: 700; font-size: 16px; }
.online-tag {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
}
.online-tag.on { background: var(--accent-bg); color: var(--accent); }
.online-tag.off { background: rgba(148, 163, 184, 0.16); color: var(--muted); }

.device-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.sim-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.sim-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 13px;
}
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.sim-editor-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.sim-editor-box h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

.code-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 14px;
}
.code-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}
.code-block textarea {
  font-family: Consolas, monospace;
  font-size: 12px;
  margin-bottom: 6px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-icon { font-size: 38px; margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 6px; }

/* Mobile Bottom Nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 60;
}
.mobile-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 18px;
  padding: 4px 0;
  cursor: pointer;
}
.mobile-tab span { font-size: 11px; font-weight: 600; }
.mobile-tab.active { color: var(--primary); }

/* Toast */
.toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 2000;
}

@media (max-width: 820px) {
  .nav-tabs { display: none; }
  .mobile-nav { display: flex; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; }
  .brand-sub { display: none; }
  .otp-code-value { font-size: 24px; }
}
