/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg-primary:  #0f0f1a;
  --bg-card:     #1a1a2e;
  --bg-hover:    #16213e;
  --accent:      #00d4ff;
  --accent-2:    #7c3aed;
  --text-primary:#e2e8f0;
  --text-muted:  #64748b;
  --success:     #10b981;
  --danger:      #ef4444;
  --warning:     #f59e0b;
  --border:      #2d2d4e;
  --sidebar-w:   240px;
  --radius:      12px;
  --radius-sm:   8px;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { background: var(--bg-primary); color: var(--text-primary); font-family: 'Segoe UI', system-ui, sans-serif; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
ul { list-style: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Layout ────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.main-content { flex: 1; margin-left: var(--sidebar-w); padding: 28px 32px; max-width: 1400px; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100; overflow-y: auto;
}
.sidebar-logo {
  padding: 22px 20px; font-size: 1.15rem; font-weight: 700;
  color: var(--accent); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; letter-spacing: 0.3px;
}
.sidebar-logo span { font-size: 1.3rem; }
.sidebar nav { padding: 10px 8px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 0.88rem; font-weight: 500;
  transition: all 0.18s; margin-bottom: 2px;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-link.active { background: rgba(0,212,255,0.12); color: var(--accent); }
.nav-link .icon { font-size: 1rem; width: 20px; text-align: center; }
.nav-divider { height: 1px; background: var(--border); margin: 8px 14px; }
.sidebar-bottom { padding: 12px 8px; border-top: 1px solid var(--border); }
.hamburger { display: none; background: none; border: none; color: var(--text-primary); font-size: 1.4rem; padding: 4px 8px; }

/* ── Page header ───────────────────────────────────────────────────────── */
.page-header { margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
.page-header p { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.card-title { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 16px; }

/* ── Stat cards ────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; gap: 16px;
}
.stat-icon { font-size: 2rem; width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; background: rgba(0,212,255,0.08); border-radius: 10px; }
.stat-body .stat-value { font-size: 1.7rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.stat-body .stat-label { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.stat-body .stat-sub { font-size: 0.75rem; color: var(--success); margin-top: 1px; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
thead th { background: var(--bg-primary); color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.5px; padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text-primary); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }
.td-mono { font-family: monospace; font-size: 0.82rem; color: var(--text-muted); }
.td-wrap { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 0.84rem;
  font-weight: 600; border: 1px solid transparent; transition: all 0.18s;
  white-space: nowrap;
}
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.85; }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger); border-color: rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-secondary { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-secondary:hover { color: var(--text-primary); border-color: var(--text-muted); }
.btn-success { background: rgba(16,185,129,0.15); color: var(--success); border-color: rgba(16,185,129,0.3); }
.btn-success:hover { background: rgba(16,185,129,0.25); }
.btn-warning { background: rgba(245,158,11,0.15); color: var(--warning); border-color: rgba(245,158,11,0.3); }
.btn-icon { padding: 6px 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 0.74rem; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-connected, .badge-success   { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-disconnected, .badge-danger  { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-qr_pending, .badge-warning  { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-reconnecting                { background: rgba(124,58,237,0.15); color: #a78bfa; }
.badge-pending                     { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.badge-running                     { background: rgba(0,212,255,0.12); color: var(--accent); }
.badge-completed                   { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-cancelled, .badge-failed    { background: rgba(239,68,68,0.15); color: var(--danger); }

/* ── Toggle switch ─────────────────────────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 22px; transition: 0.25s; cursor: pointer; }
.toggle-slider::before { content: ''; position: absolute; width: 16px; height: 16px; bottom: 3px; left: 3px; background: #fff; border-radius: 50%; transition: 0.25s; }
.toggle input:checked + .toggle-slider { background: var(--success); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-control {
  width: 100%; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  padding: 9px 12px; font-size: 0.87rem; outline: none; transition: border-color 0.2s;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text-muted); }
select.form-control option { background: var(--bg-card); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; color: var(--text-muted); }
.form-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.input-group { position: relative; }
.input-group .form-control { padding-right: 40px; }
.input-group-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text-muted); font-size: 1rem; padding: 4px; }
.input-group-btn:hover { color: var(--text-primary); }
.form-hint { font-size: 0.76rem; color: var(--text-muted); margin-top: 4px; }
.slider-wrap { display: flex; align-items: center; gap: 12px; }
input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-val { font-size: 0.85rem; color: var(--accent); min-width: 32px; text-align: right; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 1000; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto; animation: slideIn 0.2s ease;
}
.modal-lg { max-width: 720px; }
@keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.3rem; line-height: 1; padding: 2px 4px; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 18px;
  font-size: 0.85rem; color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.25s ease; min-width: 240px; max-width: 360px;
  border-left: 3px solid var(--success);
}
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes toastIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.hide { animation: toastOut 0.2s ease forwards; }
@keyframes toastOut { to { transform: translateX(40px); opacity: 0; } }

/* ── Loading ───────────────────────────────────────────────────────────── */
.spinner { width: 22px; height: 22px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td { text-align: center; padding: 32px; color: var(--text-muted); }

/* ── QR Container ──────────────────────────────────────────────────────── */
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px; }
.qr-box { background: #fff; border-radius: 10px; padding: 12px; display: inline-flex; }
.qr-status { font-size: 0.85rem; color: var(--text-muted); text-align: center; }
.qr-status.connected { color: var(--success); font-weight: 600; }

/* ── Progress bar ──────────────────────────────────────────────────────── */
.progress-wrap { background: var(--bg-primary); border-radius: 20px; height: 8px; overflow: hidden; margin: 6px 0; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 20px; transition: width 0.4s; }

/* ── Pagination ────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 6px; margin-top: 16px; justify-content: center; }
.page-btn { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); font-size: 0.84rem; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-muted); transition: all 0.18s; cursor: pointer; }
.page-btn:hover, .page-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.page-info { font-size: 0.8rem; color: var(--text-muted); }

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn { padding: 9px 18px; background: none; border: none; color: var(--text-muted); font-size: 0.87rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.18s; margin-bottom: -1px; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 10px; opacity: 0.4; }
.empty-state p { font-size: 0.86rem; }

/* ── Alert ─────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 0.84rem; margin-bottom: 16px; }
.alert-danger { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.25); color: var(--danger); }
.alert-success { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.25); color: var(--success); }

/* ── Login page ────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-primary); padding: 16px; }
.login-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px 32px; width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon { font-size: 2.8rem; }
.login-logo h1 { font-size: 1.3rem; font-weight: 700; margin-top: 8px; }
.login-logo p { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ── Misc ──────────────────────────────────────────────────────────────── */
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.flex-1 { flex: 1; } .justify-between { justify-content: space-between; }
.mt-4 { margin-top: 16px; } .mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); font-size: 0.83rem; }
.text-success { color: var(--success); } .text-danger { color: var(--danger); }
.font-mono { font-family: monospace; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; } .text-center { text-align: center; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); width: 240px; transition: transform 0.28s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 20px 16px; }
  .hamburger { display: block; }
  .page-header { margin-top: 10px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
