@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0d0f14;
  --bg-surface: #161b25;
  --bg-card: rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --accent: #6c63ff;
  --accent-hover: #7c74ff;
  --accent-2: #00d4aa;
  --accent-danger: #ff4d6a;
  --accent-warn: #ffb830;
  --accent-success: #00d4aa;
  --text-primary: #f0f2f8;
  --text-secondary: #a0aec0;
  --text-muted: #6b7280;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.3);
  --transition: 0.22s ease;
}

[data-theme="light"] {
  --bg-primary: #f0f4ff;
  --bg-surface: #ffffff;
  --bg-card: rgba(0,0,0,0.03);
  --bg-card-hover: rgba(0,0,0,0.06);
  --text-primary: #1a1d2e;
  --text-secondary: #4a5568;
  --text-muted: #9aa3b2;
  --border: rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.15);
  --shadow: 0 4px 24px rgba(0,0,0,0.1);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.08);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: width var(--transition);
  overflow: hidden;
}

#sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
}

.logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}

.logo-text { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }
.logo-sub  { font-size: 11px; color: var(--text-muted); }

.sidebar-nav { flex: 1; padding: 16px 10px; overflow-y: auto; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 8px 10px 4px;
  white-space: nowrap;
  overflow: hidden;
}

#sidebar.collapsed .nav-section-label,
#sidebar.collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.nav-item.active {
  background: linear-gradient(135deg, rgba(108,99,255,0.18), rgba(0,212,170,0.08));
  color: var(--accent);
  border: 1px solid rgba(108,99,255,0.2);
}

.nav-icon { font-size: 18px; flex-shrink: 0; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 16px 10px;
  border-top: 1px solid var(--border);
}

/* ── Main content ── */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

#main.expanded { margin-left: var(--sidebar-w-collapsed); }

/* ── Topbar ── */
#topbar {
  height: 64px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 100;
}

#btn-toggle-sidebar {
  background: none; border: none; color: var(--text-secondary);
  font-size: 22px; cursor: pointer; padding: 6px; border-radius: 8px;
  transition: background var(--transition), color var(--transition);
}
#btn-toggle-sidebar:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.topbar-title { font-size: 18px; font-weight: 600; flex: 1; }

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

.btn-icon {
  background: none; border: 1px solid var(--border); color: var(--text-secondary);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 16px;
  display: grid; place-items: center;
  transition: all var(--transition);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* ── Page content ── */
#page-content { flex: 1; padding: 28px 28px; }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(12px);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.card:hover { border-color: var(--border-hover); box-shadow: var(--shadow-card); }

.card-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.card-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(108,99,255,0.2), rgba(0,212,170,0.1));
  display: grid; place-items: center; font-size: 18px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ── Form elements ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 6px;
}
.form-control {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px; font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.15);
}
textarea.form-control { resize: vertical; min-height: 120px; line-height: 1.6; }

.input-wrapper { position: relative; }
.input-toggle-pw {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px;
}

.form-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--text-secondary); cursor: pointer;
}
.form-check input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; font-family: inherit;
  border: none; cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  box-shadow: 0 4px 16px rgba(108,99,255,0.35);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(108,99,255,0.45);
}

.btn-secondary {
  background: var(--bg-card-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--border-hover); color: var(--text-primary); }

.btn-success {
  background: linear-gradient(135deg, var(--accent-2), #00b894);
  color: #000; font-weight: 700;
}
.btn-danger {
  background: linear-gradient(135deg, var(--accent-danger), #c9184a);
  color: #fff;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Result block ── */
.result-block {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 16px;
  animation: fadeSlideIn 0.3s ease;
}

.result-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.result-row:last-child { border-bottom: none; }
.result-label { font-size: 12px; color: var(--text-muted); font-weight: 500; min-width: 160px; flex-shrink: 0; }
.result-value { font-size: 13px; color: var(--text-primary); font-family: 'Courier New', monospace; word-break: break-all; flex: 1; }

.cid-display {
  font-size: 15px; font-weight: 700; color: var(--accent-2);
  letter-spacing: 1px; padding: 12px 16px;
  background: rgba(0,212,170,0.07);
  border: 1px solid rgba(0,212,170,0.2);
  border-radius: var(--radius-sm);
  word-break: break-all;
  margin-bottom: 8px;
}

/* ── Badge ── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: rgba(0,212,170,0.15); color: var(--accent-2); border: 1px solid rgba(0,212,170,0.25); }
.badge-danger  { background: rgba(255,77,106,0.15); color: var(--accent-danger); border: 1px solid rgba(255,77,106,0.25); }
.badge-warn    { background: rgba(255,184,48,0.15); color: var(--accent-warn); border: 1px solid rgba(255,184,48,0.25); }
.badge-info    { background: rgba(108,99,255,0.15); color: var(--accent); border: 1px solid rgba(108,99,255,0.25); }

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108,99,255,0.06);
}
.drop-zone-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.drop-zone-text { font-size: 15px; font-weight: 500; color: var(--text-secondary); }
.drop-zone-sub  { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
#file-input { display: none; }

.image-preview {
  max-width: 100%; max-height: 280px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  display: none;
  margin: 12px auto 0;
}

/* ── Scan animation ── */
@keyframes scanLine {
  0%   { top: 0; }
  100% { top: 100%; }
}
.scan-container { position: relative; display: inline-block; }
.scan-line {
  position: absolute; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-2), transparent);
  box-shadow: 0 0 8px var(--accent-2);
  animation: scanLine 1.4s ease-in-out infinite;
  pointer-events: none;
}

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Table ── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
table.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.data-table thead tr {
  background: rgba(108,99,255,0.06);
  border-bottom: 1px solid var(--border);
}
.data-table th {
  padding: 12px 14px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-muted);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.data-table th:hover { color: var(--accent); }
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-card-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }
.key-cell { font-family: 'Courier New', monospace; font-size: 12px; letter-spacing: 0.5px; }

/* ── Search bar ── */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
}
.search-bar input {
  background: none; border: none; color: var(--text-primary);
  font-size: 14px; font-family: inherit;
  padding: 9px 0; outline: none; flex: 1;
  min-width: 0;
}
.search-icon { color: var(--text-muted); }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; gap: 4px;
  justify-content: center; margin-top: 16px;
}
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: 6px;
  cursor: pointer; font-size: 13px;
  display: grid; place-items: center;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Toast ── */
#toast-container {
  position: fixed; top: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  min-width: 280px; max-width: 400px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  pointer-events: all;
  font-size: 13px;
}
.toast.removing { animation: toastOut 0.3s ease forwards; }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-msg { flex: 1; }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; }
.toast.success { border-left: 3px solid var(--accent-success); }
.toast.error   { border-left: 3px solid var(--accent-danger); }
.toast.warn    { border-left: 3px solid var(--accent-warn); }
.toast.info    { border-left: 3px solid var(--accent); }

@keyframes toastIn  { from { opacity:0; transform:translateX(40px); } to { opacity:1; transform:none; } }
@keyframes toastOut { to   { opacity:0; transform:translateX(40px); } }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 500; display: none;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(90vw, 700px);
  max-height: 80vh;
  display: flex; flex-direction: column;
  animation: modalIn 0.25s ease;
  overflow: hidden;
}
@keyframes modalIn { from { opacity:0; transform:scale(0.94); } to { opacity:1; transform:none; } }
.modal-header {
  display: flex; align-items: center;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 600; flex: 1; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
pre.json-pre {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px;
  font-size: 12px; overflow-x: auto;
  color: var(--accent-2); line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}

/* ── History panel ── */
#history-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 320px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 300;
  transform: translateX(100%);
  transition: transform var(--transition);
  display: flex; flex-direction: column;
  overflow: hidden;
}
#history-panel.open { transform: translateX(0); }
.history-header {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}
.history-title { font-size: 15px; font-weight: 600; flex: 1; }
.history-list { flex: 1; overflow-y: auto; padding: 12px; }
.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 12px;
}
.history-item:hover { border-color: var(--accent); }
.history-item-type { font-weight: 600; color: var(--accent); font-size: 11px; margin-bottom: 4px; }
.history-item-preview { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item-time { color: var(--text-muted); font-size: 10px; margin-top: 4px; }

/* ── Toolbar row ── */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar-right { margin-left: auto; display: flex; gap: 8px; }

/* ── Status indicator ── */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-right: 6px;
}
.status-dot.online  { background: var(--accent-2); box-shadow: 0 0 6px var(--accent-2); }
.status-dot.offline { background: var(--accent-danger); }
.status-dot.warn    { background: var(--accent-warn); }

/* ── Animations ── */
@keyframes fadeSlideIn {
  from { opacity:0; transform:translateY(10px); }
  to   { opacity:1; transform:none; }
}
.fade-in { animation: fadeSlideIn 0.3s ease; }

/* ── Tab nav ── */
.tab-nav {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tab-btn {
  padding: 10px 18px; background: none; border: none;
  color: var(--text-muted); font-size: 14px; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all var(--transition);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeSlideIn 0.25s ease; }

/* ── Stats bar ── */
.stat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px;
  font-size: 12px; font-weight: 500;
}

/* ── Copy feedback ── */
.copy-check { color: var(--accent-2) !important; }

/* ── Responsive ── */
@media (max-width: 900px) {
  #sidebar { width: var(--sidebar-w-collapsed); }
  #main { margin-left: var(--sidebar-w-collapsed); }
  #sidebar .nav-label,
  #sidebar .nav-section-label,
  #sidebar .logo-text,
  #sidebar .logo-sub { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  #sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
  #sidebar.mobile-open { transform: none; }
  #main { margin-left: 0; }
  #page-content { padding: 16px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { margin-left: 0; }
}
