/* ── Reset & Tokens ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0f14;
  --surface:   #141720;
  --surface2:  #1c2030;
  --border:    #252a3a;
  --accent:    #25d366;   /* WhatsApp green */
  --accent2:   #128c7e;
  --text:      #e8eaf0;
  --text-dim:  #7a8099;
  --text-muted:#4a5068;
  --danger:    #ff4d6d;
  --warn:      #ffb347;
  --radius:    10px;
  --mono:      'JetBrains Mono', monospace;
  --sans:      'Inter', system-ui, sans-serif;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.brand-icon {
  font-size: 22px;
  background: var(--accent);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.nav { flex: 1; padding: 0 12px; display: flex; flex-direction: column; gap: 4px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: rgba(37,211,102,.12); color: var(--accent); }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.version-badge {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 3px 8px;
  border-radius: 20px;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.status-dot.offline { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* ── Main ─────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: 220px;
  min-height: 100vh;
  padding: 36px 40px;
  max-width: calc(100vw - 220px);
}

/* ── Pages ───────────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 16px;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.4px;
}

.subtitle { color: var(--text-dim); font-size: 13.5px; margin-top: 2px; }

.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 28px 0 14px;
}

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

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

.stat-card.accent { border-color: rgba(37,211,102,.3); background: rgba(37,211,102,.06); }

.stat-num {
  font-size: 36px;
  font-weight: 700;
  font-family: var(--mono);
  line-height: 1;
  color: var(--accent);
}

.stat-card:not(.accent) .stat-num { color: var(--text); }

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ── Device Cards ─────────────────────────────────────────────────────────── */
.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  transition: border-color .2s;
}

.device-card:hover { border-color: var(--accent2); }

.device-card.connected { border-left: 3px solid var(--accent); }
.device-card.disconnected { border-left: 3px solid var(--text-muted); }
.device-card.qr { border-left: 3px solid var(--warn); }

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.device-id {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
}

.device-status {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  font-weight: 600;
}

.status-open   { background: rgba(37,211,102,.15); color: var(--accent); }
.status-qr     { background: rgba(255,179,71,.15); color: var(--warn); }
.status-disconnected,
.status-logged_out,
.status-connecting { background: var(--surface2); color: var(--text-dim); }

.device-info { font-size: 13px; color: var(--text-dim); line-height: 1.7; }
.device-info strong { color: var(--text); }

.device-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty-text { font-size: 16px; font-weight: 500; }
.empty-sub  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}

.btn:hover { opacity: .85; }
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent);
  color: #000;
}

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

.btn-danger {
  background: rgba(255,77,109,.12);
  color: var(--danger);
  border: 1px solid rgba(255,77,109,.2);
}

.btn-sm { padding: 6px 13px; font-size: 12.5px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
}

.hint { color: var(--text-muted); font-weight: 400; }

.form-control {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}

.form-control:focus { border-color: var(--accent); }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control option { background: var(--surface2); }

.form-hint { font-size: 11.5px; color: var(--text-muted); }

.result-box {
  padding: 12px 16px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.result-box.ok     { background: rgba(37,211,102,.1); border: 1px solid rgba(37,211,102,.2); color: var(--accent); }
.result-box.err    { background: rgba(255,77,109,.1); border: 1px solid rgba(255,77,109,.2); color: var(--danger); }
.hidden { display: none !important; }

/* ── API Docs ─────────────────────────────────────────────────────────────── */
.badge-base {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 6px;
  color: var(--text-dim);
  align-self: center;
}

.api-list { display: flex; flex-direction: column; gap: 14px; }

.api-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.api-item-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
}

.api-item-header:hover { background: var(--surface2); }

.method {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  min-width: 52px;
  text-align: center;
}

.method-get    { background: rgba(64,158,255,.15); color: #4fb3ff; }
.method-post   { background: rgba(37,211,102,.15); color: var(--accent); }
.method-delete { background: rgba(255,77,109,.15); color: var(--danger); }

.api-path {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}

.api-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-left: auto;
}

.api-item-body {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: none;
}

.api-item-body.open { display: block; }

.api-item-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  overflow-x: auto;
  margin-top: 10px;
  line-height: 1.6;
}

.api-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 420px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-close {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 14px;
}

/* ── QR Area ─────────────────────────────────────────────────────────────── */
.qr-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0 6px;
}

.qr-status {
  font-size: 13px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.qr-image-wrap {
  width: 220px; height: 220px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

.qr-image-wrap img {
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: 12px;
  padding: 8px;
  background: #fff;
}

.qr-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.qr-hint { font-size: 11.5px; color: var(--text-muted); text-align: center; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Login Screen ─────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 60% 20%, rgba(37,211,102,.06) 0%, transparent 60%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 380px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: -4px;
}

.input-wrap {
  position: relative;
}

.input-wrap .form-control { padding-right: 42px; }

.toggle-pass {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  opacity: .5;
  transition: opacity .15s;
}

.toggle-pass:hover { opacity: 1; }

.login-error {
  background: rgba(255,77,109,.1);
  border: 1px solid rgba(255,77,109,.2);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
}

.btn-block { width: 100%; justify-content: center; }

/* ── Sidebar footer update ────────────────────────────────────────────────── */
.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  min-width: 0;
}

.user-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}

.btn-logout:hover { color: var(--danger); border-color: rgba(255,77,109,.3); }

/* ── Lookup Page ─────────────────────────────────────────────────────────── */
.lookup-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 20px;
}

.lookup-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.lookup-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.lookup-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.lookup-row .form-control { flex: 1; min-width: 180px; }

/* ── Profile Card ─────────────────────────────────────────────────────────── */
.profile-card {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.profile-avatar-placeholder {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.profile-details { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.profile-phone { font-family: var(--mono); font-size: 16px; font-weight: 600; }
.profile-name  { font-size: 13px; color: var(--text-dim); }
.profile-status-text { font-size: 13px; color: var(--text-dim); font-style: italic; }

.profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
  width: fit-content;
}

.badge-exists { background: rgba(37,211,102,.15); color: var(--accent); }
.badge-not-exists { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }

/* ── API Key info box ─────────────────────────────────────────────────────── */
.apikey-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: rgba(37,211,102,.06);
  border: 1px solid rgba(37,211,102,.2);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 24px;
  font-size: 13px;
}

.apikey-label { font-weight: 700; color: var(--accent); flex-shrink: 0; }
.apikey-text  { color: var(--text-dim); }
.apikey-text code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text);
}

/* ── Device Card with Avatar ─────────────────────────────────────────────── */
.device-card-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.device-avatar-wrap {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
}

.device-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  display: block;
}

.device-avatar-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.device-card-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-id {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.device-phone {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.device-name {
  font-size: 12px;
  color: var(--text-dim);
}

.device-time {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── Status Result Card ───────────────────────────────────────────────────── */
.status-result-card {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-top: 12px;
}

.sr-avatar-wrap { flex-shrink: 0; }

.sr-avatar-img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  display: block;
}

.sr-avatar-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}

.sr-details { display: flex; flex-direction: column; gap: 5px; flex: 1; }

.sr-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.sr-phone {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
}

.sr-row { display: flex; gap: 8px; align-items: center; }

.sr-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.sr-meta strong { color: var(--text-dim); }
