/* ────────────────────────────────────────────────────────
   WA SaaS — Global Styles
   Palette: slate-900 bg · emerald-500 accent · mono data
──────────────────────────────────────────────────────── */

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

:root {
  --bg:         #0f172a;
  --bg-2:       #1e293b;
  --bg-3:       #334155;
  --border:     #334155;
  --accent:     #10b981;
  --accent-dim: #064e3b;
  --accent-glow:rgba(16,185,129,.25);
  --text:       #f1f5f9;
  --text-2:     #94a3b8;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --radius:     10px;
  --font:       'Inter', sans-serif;
  --mono:       'JetBrains Mono', monospace;
  --sidebar-w:  230px;
  --topbar-h:   72px;
}

html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
.mono { font-family: var(--mono); }

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

/* ── Auth Page ────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.auth-bg {
  position: fixed; inset: 0; z-index: 0;
  background: radial-gradient(ellipse at 20% 50%, rgba(16,185,129,.08) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 20%, rgba(6,182,212,.06) 0%, transparent 40%),
              var(--bg);
}

.grid-overlay {
  position: absolute; inset: 0;
  background-image: linear-gradient(var(--border) 1px, transparent 1px),
                    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: .35;
}

.auth-container { position: relative; z-index: 1; width: 380px; padding: 1rem; }

.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  backdrop-filter: blur(8px);
  box-shadow: 0 24px 64px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.04);
}

.auth-logo { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.75rem; }
.logo-icon {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
  box-shadow: 0 0 20px var(--accent-glow);
}
.logo-icon svg { width: 24px; height: 24px; }
.logo-icon.sm { width: 32px; height: 32px; border-radius: 8px; }
.logo-icon.sm svg { width: 18px; height: 18px; }
.auth-logo h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.logo-sub { font-size: .75rem; color: var(--text-2); }

.auth-tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; background: var(--bg); border-radius: 8px; padding: .25rem; }
.tab-btn {
  flex: 1; padding: .5rem; border: none; background: transparent; color: var(--text-2);
  border-radius: 6px; cursor: pointer; font-size: .875rem; font-family: var(--font); transition: all .2s;
}
.tab-btn.active { background: var(--bg-2); color: var(--text); font-weight: 600; }

/* ── Forms ────────────────────────────────────────────── */
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .375rem; }
.field label { font-size: .8rem; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.field input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: .625rem .875rem; border-radius: var(--radius); font-size: .9375rem; font-family: var(--font);
  transition: border-color .2s, box-shadow .2s; outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.field input::placeholder { color: var(--bg-3); }

.error-msg { color: var(--danger); font-size: .8rem; padding: .5rem .75rem; background: rgba(239,68,68,.1); border-radius: 6px; border: 1px solid rgba(239,68,68,.25); }
.hidden { display: none !important; }
.mb-3 { margin-bottom: .75rem; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border: none; border-radius: var(--radius);
  font-family: var(--font); font-size: .875rem; font-weight: 600; cursor: pointer;
  transition: all .2s; white-space: nowrap; text-decoration: none;
}
.btn svg { width: 16px; height: 16px; }
.btn-full { width: 100%; padding: .75rem; font-size: .9375rem; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 14px var(--accent-glow); }
.btn-primary:hover { background: #0ea472; transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }
.btn-danger { background: rgba(239,68,68,.1); color: var(--danger); border: 1px solid rgba(239,68,68,.25); }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn-sm { padding: .375rem .75rem; font-size: .8125rem; }
.btn.loading { opacity: .6; pointer-events: none; }
.btn-close { background: none; border: none; color: var(--text-2); font-size: 1.1rem; cursor: pointer; padding: .25rem; border-radius: 4px; transition: color .2s; }
.btn-close:hover { color: var(--text); }

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

.sidebar {
  width: var(--sidebar-w); background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 10;
}

.sidebar-logo {
  display: flex; align-items: center; gap: .75rem; padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 1rem; font-weight: 700; letter-spacing: -.01em;
}

.sidebar-nav { flex: 1; padding: .75rem .75rem; display: flex; flex-direction: column; gap: .25rem; }
.nav-link {
  display: flex; align-items: center; gap: .625rem; padding: .625rem .875rem;
  border-radius: 8px; color: var(--text-2); text-decoration: none; font-size: .875rem; font-weight: 500;
  transition: all .2s; cursor: pointer;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: var(--bg-3); color: var(--text); }
.nav-link.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.text-muted { color: var(--text-2); }

.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1.25rem 2rem; background: var(--bg); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.topbar h2 { font-size: 1.15rem; font-weight: 700; }
.topbar .text-muted { font-size: .8rem; margin-top: .1rem; }

.content-section { padding: 1.75rem 2rem; }

/* ── Instance Grid ────────────────────────────────────── */
.instances-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }

.instance-card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;
  transition: border-color .2s, box-shadow .2s;
}
.instance-card:hover { border-color: var(--bg-3); box-shadow: 0 4px 20px rgba(0,0,0,.3); }

.ic-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.ic-name { font-weight: 600; font-size: .9375rem; word-break: break-word; }
.ic-id { font-size: .75rem; color: var(--text-2); font-family: var(--mono); }

.ic-footer { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }

.ic-actions { display: flex; gap: .5rem; }

.status-badge {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .75rem; font-weight: 600; padding: .25rem .625rem;
  border-radius: 999px; font-family: var(--mono);
}
.status-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; }
.status-badge.connected { background: rgba(16,185,129,.12); color: var(--accent); }
.status-badge.connected::before { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.status-badge.disconnected { background: rgba(100,116,139,.12); color: var(--text-2); }
.status-badge.disconnected::before { background: var(--text-2); }
.status-badge.connecting { background: rgba(245,158,11,.12); color: var(--warning); }
.status-badge.connecting::before { background: var(--warning); animation: pulse 1s infinite; }
.status-badge.qr_pending { background: rgba(99,102,241,.12); color: #818cf8; }
.status-badge.qr_pending::before { background: #818cf8; animation: pulse 1.2s infinite; }
.status-badge.pairing_pending { background: rgba(167,139,250,.12); color: #a78bfa; }
.status-badge.pairing_pending::before { background: #a78bfa; animation: pulse 1.5s infinite; }

@keyframes pulse { 0%,100%{opacity:1}50%{opacity:.3} }

.empty-state {
  grid-column: 1/-1; display: flex; flex-direction: column; align-items: center;
  gap: .75rem; padding: 4rem 2rem; color: var(--text-2); text-align: center;
}
.empty-state svg { width: 48px; height: 48px; opacity: .4; }
.empty-state h4 { color: var(--text); font-weight: 600; }

/* ── Skeleton ────────────────────────────────────────── */
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.skeleton-card { height: 120px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); animation: shimmer 1.4s infinite; }
@keyframes shimmer { 0%,100%{opacity:1}50%{opacity:.5} }

/* ── Cards ───────────────────────────────────────────── */
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: .75rem; }
.api-doc-layout { display: flex; flex-direction: column; gap: 1rem; max-width: 720px; }

.apikey-display {
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: .75rem 1rem; overflow: hidden;
}
.apikey-display code { flex: 1; word-break: break-all; font-size: .8rem; color: var(--accent); }

.endpoint-badge { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.method-badge { font-family: var(--mono); font-size: .75rem; font-weight: 700; padding: .2rem .55rem; border-radius: 5px; }
.method-badge.post { background: rgba(16,185,129,.15); color: var(--accent); border: 1px solid var(--accent-dim); }
.endpoint-url { font-size: .85rem; color: var(--text-2); }

.doc-section { margin-top: 1.25rem; }
.doc-section h4 { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-2); margin-bottom: .5rem; }
.code-block { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; }
.code-block pre { padding: 1rem; }
.code-block code { font-family: var(--mono); font-size: .8rem; color: #a5f3cf; white-space: pre; }
.inline-code { font-family: var(--mono); font-size: .8em; background: var(--bg); padding: .1em .35em; border-radius: 4px; border: 1px solid var(--border); color: var(--accent); }

/* ── Modals ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from{opacity:0}to{opacity:1} }

.modal-card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.75rem; width: 100%; max-width: 420px;
  animation: slideUp .2s ease;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.modal-card.qr-modal { max-width: 340px; }
@keyframes slideUp { from{transform:translateY(16px);opacity:0}to{transform:translateY(0);opacity:1} }

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }

.qr-content { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.qr-hint { font-size: .8rem; text-align: center; }
.qr-box {
  width: 220px; height: 220px; background: #fff; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.qr-box img { width: 100%; height: 100%; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab-btn {
  flex: 1; padding: .75rem; border: none; background: none; color: var(--text-2);
  font-weight: 600; cursor: pointer; transition: all .2s; border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text-1); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.qr-spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to{transform:rotate(360deg)} }

.pairing-code-box {
  background: var(--bg); border: 2px dashed var(--accent); border-radius: 12px;
  padding: 1.5rem; text-align: center; font-family: var(--mono);
  font-size: 2rem; font-weight: 700; color: var(--accent); letter-spacing: 0.1em;
  margin: 1rem 0; box-shadow: 0 0 20px var(--accent-glow);
}

.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: 1rem; }

/* ── Admin Section ────────────────────────────────────────── */
.table-container { width: 100%; overflow-x: auto; margin-top: 1rem; }
.admin-table { width: 100%; border-collapse: collapse; text-align: left; font-size: .875rem; }
.admin-table th { padding: .75rem 1rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; font-size: .75rem; border-bottom: 1px solid var(--border); }
.admin-table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .mono { font-size: .8rem; color: var(--text-2); }

.limit-input-group { display: flex; align-items: center; gap: .5rem; }
.limit-input { width: 60px; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: .25rem .5rem; border-radius: 4px; font-family: var(--mono); font-size: .875rem; outline: none; transition: border-color .2s; }
.limit-input:focus { border-color: var(--accent); }
.limit-input:disabled { opacity: .5; cursor: not-allowed; }

.badge-admin { background: rgba(16,185,129,.1); color: var(--accent); padding: .15rem .4rem; border-radius: 4px; font-size: .7rem; font-weight: 700; text-transform: uppercase; }
