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

:root {
  --bg: #0b0b14;
  --bg-card: #12121f;
  --bg-card-hover: #1a1a2e;
  --bg-sidebar: #0e0e1a;
  --bg-input: #1a1a2e;
  --bg-terminal: #080810;
  --border: #2a2a3e;
  --text: #e0e0e8;
  --text-muted: #6b6b80;
  --accent: #4f6ef7;
  --accent-hover: #3b5ce4;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --radius: 8px;
  --sidebar-w: 220px;
}

html.light {
  --bg: #f4f5f7;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f1f3;
  --bg-sidebar: #ffffff;
  --bg-input: #f4f5f7;
  --bg-terminal: #1e1e2e;
  --border: #e0e2e8;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --accent: #4f6ef7;
  --accent-hover: #3b5ce4;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #2563eb;
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 1rem 0;
}
.sidebar-brand {
  padding: 0.5rem 1.2rem 1.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
}
.brand-icon { margin-right: 0.5rem; }
.nav-link {
  display: block;
  padding: 0.7rem 1.2rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-link:hover { color: var(--text); background: var(--bg-card); }
.nav-link.active {
  color: var(--accent);
  background: var(--bg-card);
  border-left-color: var(--accent);
}
.nav-icon { margin-right: 0.6rem; }
.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.user-label { font-size: 0.85rem; color: var(--text-muted); }

/* Global theme toggle — top right, always visible */
.theme-toggle-global {
  position: fixed;
  top: 0.75rem;
  right: 1rem;
  z-index: 9999;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle-global:hover { color: var(--text); border-color: var(--text-muted); }

/* Main content */
.content {
  margin-left: var(--sidebar-w);
  padding: 2rem 2.5rem;
  flex: 1;
  max-width: 1200px;
}
.content-full { margin-left: 0; max-width: 100%; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}
.page-header h1 { font-size: 1.6rem; font-weight: 600; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.2rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.2rem; }
.card-body p { margin-bottom: 0.5rem; }
.card-body p:last-child { margin-bottom: 0; }
.card-inline { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card-actions {
  padding: 0.8rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.2rem;
  margin-bottom: 1.2rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-ghost { background: rgba(128,128,128,0.1); color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  color: var(--text);
  background: transparent;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.85; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-outline { border-color: var(--border); color: var(--text); background: var(--bg-input); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { border: none; color: var(--text-muted); background: none; padding: 0.4rem 0.6rem; }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}
input, textarea, select {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Log output */
.log-output {
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  overflow: auto;
  max-height: 300px;
  white-space: pre-wrap;
  word-break: break-all;
  color: #a0a0b0;
}

/* Terminal (interactive console) */
.terminal-output {
  background: var(--bg-terminal);
  padding: 0.8rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  overflow: auto;
  max-height: 450px;
  min-height: 200px;
  white-space: pre-wrap;
  word-break: break-all;
  color: #c8c8d8;
  margin: 0;
  border-bottom: 1px solid var(--border);
}
.terminal-input-row {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-terminal);
  border-radius: 0 0 var(--radius) var(--radius);
}
.terminal-prompt {
  padding: 0.6rem 0.5rem 0.6rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--success);
  white-space: nowrap;
  user-select: none;
}
.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: #c8c8d8;
  padding: 0.6rem 0.5rem;
}
.terminal-input:focus { outline: none; border: none; }
.terminal-input-row .btn { border-radius: 0 0 var(--radius) 0; }

/* Alert */
.alert {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.85rem;
}
.alert-error { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.alert-success { background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }

/* Image gallery */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.gallery-empty { grid-column: 1 / -1; }
.gallery-item {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0a0a12;
  transition: border-color 0.2s;
}
html.light .gallery-item { background: #f0f0f4; }
.gallery-item:hover { border-color: var(--accent); }
.gallery-item img {
  width: 100%;
  height: 280px;
  object-fit: contain;
  display: block;
  cursor: pointer;
}
.gallery-overlay {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.7rem;
  background: rgba(0,0,0,0.6);
}
html.light .gallery-overlay { background: rgba(0,0,0,0.05); }
.gallery-name {
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 50%;
}
.gallery-actions { display: flex; gap: 0.3rem; }

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.92);
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.lightbox.active { display: flex; }
.lightbox-content {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lightbox-content img {
  max-width: 90vw;
  max-height: calc(90vh - 50px);
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.8rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.lightbox-bar .btn-group { flex-shrink: 0; }

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.85);
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
html.light .modal { background: rgba(0,0,0,0.4); }
.modal.active { display: flex; }
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }

/* Sessions */
.session-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.session-item:last-child { border-bottom: none; }
.session-id { font-weight: 600; color: var(--success); white-space: nowrap; }

/* Login */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { text-align: center; margin-bottom: 0.3rem; }
.login-sub { text-align: center; color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.fw-600 { font-weight: 600; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.hidden { display: none; }
.text-center { text-align: center; }
.no-pad { padding: 0; }
.mb-0 { margin-bottom: 0; }
.m-0 { margin: 0; }
.mw-200 { max-width: 200px; }
.mw-220 { max-width: 220px; }
.select-all { user-select: all; font-weight: 600; }
.mx-auto { margin-left: auto; margin-right: auto; }
.flex-col { flex-direction: column; }
.gap-sm { gap: 0.8rem; }
.ports-output { max-height: 100px; font-size: 0.72rem; margin-top: 0.5rem; }
.webcam-media { max-width: 100%; border-radius: 8px; }

/* Pineapple page */
.check-grid {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}
.check-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.check-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}
.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.2rem 0 0.5rem;
  color: var(--text);
}
.section-title:first-child { margin-top: 0; }
.setup-list {
  padding-left: 1.5rem;
  margin-bottom: 0.8rem;
  font-size: 0.88rem;
  line-height: 1.7;
}
.setup-list.compact { font-size: 0.82rem; line-height: 1.6; }
.setup-list li { margin-bottom: 0.15rem; }
.setup-list code {
  background: var(--bg-input);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.82rem;
}
.config-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin: 0.5rem 0 1rem;
  display: inline-block;
}
.config-table { border-collapse: collapse; font-size: 0.88rem; }
.config-table td {
  padding: 0.3rem 1rem 0.3rem 0;
  border: none;
}
.config-table td:first-child {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.config-table code {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--success);
}
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.2rem;
}
.feature-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.feature-block .section-title { margin-top: 0; }
.mb-1 { margin-bottom: 0.5rem; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .brand-text, .nav-link span:not(.nav-icon), .user-label { display: none; }
  .sidebar-brand { padding: 0.5rem; text-align: center; }
  .nav-link { padding: 0.7rem; text-align: center; }
  .sidebar-footer { flex-direction: column; padding: 0.5rem; }
  .content { margin-left: 60px; padding: 1rem; }
  .cards-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
