:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #242836;
  --border: #2a2e3a;
  --text: #e4e6eb;
  --text-muted: #8b8fa3;
  --primary: #4f8ff7;
  --primary-hover: #3a7ae0;
  --danger: #e5484d;
  --danger-hover: #cd2b31;
  --success: #30a46c;
  --warning: #f5a623;
  --radius: 8px;
  --radius-lg: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1117 0%, #1a1d27 50%, #0f1117 100%);
}

.login-container { width: 100%; max-width: 400px; padding: 20px; }

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
}

.login-header { text-align: center; margin-bottom: 32px; }

.login-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
  margin-bottom: 16px;
}

.login-header h1 { font-size: 24px; font-weight: 600; }
.login-subtitle { color: var(--text-muted); margin-top: 4px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.2s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: var(--text);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Alert */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 14px; }
.alert-error { background: rgba(229, 72, 77, 0.15); color: var(--danger); border: 1px solid rgba(229, 72, 77, 0.3); }

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
}

.nav-user { display: flex; align-items: center; gap: 12px; }
.nav-username { color: var(--text-muted); font-size: 14px; }

/* Container */
.container { max-width: 960px; margin: 0 auto; padding: 32px 24px; }

/* Session Banner */
.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 32px;
}

.session-status { display: flex; align-items: center; gap: 10px; }
.session-actions { display: flex; gap: 8px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.running { background: var(--success); box-shadow: 0 0 8px rgba(48, 164, 108, 0.5); }
.status-dot.stopped { background: var(--text-muted); }

.badge {
  padding: 2px 8px;
  background: var(--bg-hover);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.badge-active {
  background: rgba(48, 164, 108, 0.15);
  color: var(--success);
}

.badge-inactive {
  background: rgba(229, 72, 77, 0.15);
  color: var(--danger);
}

.image-disabled td {
  opacity: 0.5;
}

/* Image Grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.image-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s;
}

.image-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(79, 143, 247, 0.15);
}

.image-card-icon {
  width: 48px;
  height: 48px;
  background: var(--bg-hover);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  color: var(--primary);
}

.image-card h3 { font-size: 16px; margin-bottom: 4px; }
.image-card p { color: var(--text-muted); font-size: 14px; }

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Admin */
h1 { font-size: 24px; margin-bottom: 24px; }
h2 { font-size: 18px; }

.admin-section {
  margin-bottom: 40px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}

.card h3 { margin-bottom: 16px; font-size: 16px; }

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table th, .data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.data-table th {
  background: var(--bg-hover);
  font-weight: 500;
  color: var(--text-muted);
  font-size: 13px;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

.table-actions { display: flex; gap: 6px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; margin: 0; }

.modal-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.modal-header button:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

.checkbox-list label:hover {
  background: var(--bg-hover);
}

.checkbox-list input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-list .image-label-info {
  display: flex;
  flex-direction: column;
}

.checkbox-list .image-label-name {
  font-weight: 500;
}

.checkbox-list .image-label-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.checkbox-list.disabled label {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== Desktop View with Sidebar ===== */

.desktop-view-page {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.desktop-frame {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  z-index: 1;
}

/* Sidebar Tab (pull-out trigger) */
.sidebar-tab {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 100;
  width: 28px;
  height: 56px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  opacity: 0.6;
}

.sidebar-tab:hover {
  opacity: 1;
  width: 34px;
  background: var(--bg-hover);
  color: var(--primary);
}

.sidebar-tab.hidden {
  transform: translateY(-50%) translateX(100%);
  opacity: 0;
  pointer-events: none;
}

/* Sidebar Overlay */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Sidebar Panel */
.desktop-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.desktop-sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.sidebar-close:hover {
  color: var(--text);
  background: var(--bg-hover);
}

/* User section */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7c5cfc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-username {
  font-weight: 500;
  font-size: 14px;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-status .status-dot {
  width: 8px;
  height: 8px;
}

/* Navigation links */
.sidebar-nav {
  flex: 1;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.sidebar-link:hover {
  background: var(--bg-hover);
}

.sidebar-link svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.sidebar-link:hover svg {
  color: var(--primary);
}

.sidebar-link-danger {
  color: var(--danger);
}

.sidebar-link-danger svg {
  color: var(--danger);
}

.sidebar-link-danger:hover {
  background: rgba(229, 72, 77, 0.1);
}

.sidebar-link-danger:hover svg {
  color: var(--danger);
}

.sidebar-link-muted {
  color: var(--text-muted);
}

.sidebar-link-muted:hover {
  color: var(--text);
}

/* Footer */
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-hint {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
}

/* Responsive */
@media (max-width: 640px) {
  .session-banner { flex-direction: column; gap: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .navbar { padding: 12px 16px; }
  .container { padding: 20px 16px; }
}
