/* =============================================================================
   SW-CameraControl - Global Styles (Dark theme - NodeJsFront style)
   ============================================================================= */

:root {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-hover: #141414;
  --primary: #d4ed31;
  --primary-dark: #b3c922;
  --primary-hover: #b3c922;
  --success: #00ff88;
  --warning: #ffbb00;
  --danger: #ff4444;
  --text: #ffffff;
  --text-muted: #888888;
  --border: #222222;
  --border-light: #333333;
  /* Legacy names for compatibility */
  --gray-50: #1a1a1a;
  --gray-100: #141414;
  --gray-200: #222222;
  --gray-300: #444444;
  --gray-400: #888888;
  --gray-500: #888888;
  --gray-600: #aaaaaa;
  --gray-700: #cccccc;
  --gray-800: #0a0a0a;
  --gray-900: #000000;
  --border-radius: 8px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  background-image: radial-gradient(circle at 50% 0%, rgba(212, 237, 49, 0.03) 0%, transparent 50%);
}

/* =============================================================================
   Layout
   ============================================================================= */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.page {
  padding: 2rem 1rem;
}

/* =============================================================================
   Header / Navigation
   ============================================================================= */

.header {
  background: linear-gradient(to bottom, #111111, rgba(17, 17, 17, 0.85));
  color: var(--text);
  padding: 12px 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.header-nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.header-nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  transition: background 0.2s, color 0.2s;
}

.header-nav a:hover,
.header-nav a.active {
  color: var(--primary);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.user-role {
  background: var(--primary);
  color: #000;
  padding: 0.25rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.header a#logout-btn {
  color: var(--text-muted);
}

.header a#logout-btn:hover {
  color: var(--text);
}

/* =============================================================================
   Login Page
   ============================================================================= */

.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-box {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.login-box .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.875rem;
}

.dev-mode-banner {
  background: rgba(255, 187, 0, 0.15);
  color: var(--warning);
  border: 1px solid rgba(255, 187, 0, 0.3);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
}

/* =============================================================================
   Forms
   ============================================================================= */

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 1rem;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(212, 237, 49, 0.2);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

/* =============================================================================
   Buttons
   ============================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #000;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #000;
}

.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 68, 68, 0.1);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-secondary:hover {
  background: rgba(212, 237, 49, 0.1);
}

.btn-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =============================================================================
   Cards
   ============================================================================= */

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.card-body {
  padding: 1.5rem;
}

/* =============================================================================
   Tables
   ============================================================================= */

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: transparent;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  color: var(--text-muted);
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
}

/* =============================================================================
   Camera Grid
   ============================================================================= */

.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.camera-card {
  background: #111;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  overflow: hidden;
  transition: border-color 0.2s;
}

.camera-card:hover {
  border-color: rgba(212, 237, 49, 0.3);
}

.camera-card.sharing {
  border-left: 3px solid var(--success);
}

.camera-card.offline {
  border-left: 3px solid var(--danger);
  opacity: 0.9;
}

.camera-preview {
  background: var(--surface);
  aspect-ratio: 16/9;
  border-radius: 12px;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  position: relative;
}

.camera-preview video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.camera-status {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.camera-status.online,
.camera-status.sharing {
  background: rgba(0, 255, 136, 0.1);
  color: var(--success);
  border: 1px solid rgba(0, 255, 136, 0.2);
}

.camera-status.offline {
  background: rgba(255, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(255, 68, 68, 0.2);
}

.camera-info {
  padding: 0;
}

.camera-info h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
  color: var(--text);
  font-weight: 500;
}

.camera-info .camera-location {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.camera-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* =============================================================================
   Alerts / Messages
   ============================================================================= */

.alert {
  padding: 1rem;
  border-radius: 20px;
  margin-bottom: 1rem;
}

.alert-error {
  background: rgba(255, 68, 68, 0.1);
  border: 1px solid rgba(255, 68, 68, 0.3);
  color: #ff8888;
}

.alert-success {
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.2);
  color: var(--success);
}

.alert-warning {
  background: rgba(255, 187, 0, 0.1);
  border: 1px solid rgba(255, 187, 0, 0.3);
  color: var(--warning);
}

.alert-info {
  background: rgba(212, 237, 49, 0.08);
  border: 1px solid rgba(212, 237, 49, 0.25);
  color: var(--primary);
}

/* =============================================================================
   Status Badges
   ============================================================================= */

.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-success {
  background: rgba(0, 255, 136, 0.15);
  color: var(--success);
}

.badge-warning {
  background: rgba(255, 187, 0, 0.15);
  color: var(--warning);
}

.badge-danger {
  background: rgba(255, 68, 68, 0.15);
  color: var(--danger);
}

.badge-info {
  background: rgba(212, 237, 49, 0.15);
  color: var(--primary);
}

/* =============================================================================
   Modal
   ============================================================================= */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.125rem;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* =============================================================================
   Loading / Spinner
   ============================================================================= */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =============================================================================
   Empty State
   ============================================================================= */

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.5;
  stroke: var(--text-muted);
}

.empty-state h3 {
  margin-bottom: 0.5rem;
  color: var(--text);
}

/* Page titles */
.page h2,
main h2 {
  color: var(--text);
  font-weight: 500;
}

/* Tabs (Admin) */
.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
  margin-bottom: 1rem;
}

.tab-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  background: none;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Pre/code blocks (e.g. MediaMTX Debug) */
pre {
  background: #1a1a1a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow: auto;
  font-size: 0.85rem;
}

/* =============================================================================
   Utilities
   ============================================================================= */

.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.flex {
  display: flex;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* =============================================================================
   Dashboard Page - Stream viewer and refresh button (rest uses global dark theme)
   ============================================================================= */

.dashboard-page .container {
  max-width: 1400px;
}

/* Audit log — wide table (full JSON columns) */
.audit-page .header-content,
.audit-page .container {
  max-width: min(100vw - 2rem, 1680px);
}

/* Stream viewer card - main video area */
.dashboard-page .stream-viewer-card {
  border-radius: var(--radius-xl);
  padding: 24px;
}

.dashboard-page .stream-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.dashboard-page .stream-viewer-title {
  font-weight: 400;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dashboard-page .stream-wrapper {
  width: 100%;
  padding-bottom: 56.25%;
  background: #000;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.dashboard-page .stream-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.dashboard-page .btn-refresh-dash {
  background: var(--primary);
  color: #000;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 0.2s, background 0.2s;
}

.dashboard-page .btn-refresh-dash:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.dashboard-page .camera-list-mount {
  margin-top: 0.5rem;
}

.dashboard-page .camera-list-mount .mtx-badge-cell {
  white-space: nowrap;
}

.dashboard-page .camera-list-mount .camera-path-code {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dashboard-page .camera-list-mount .camera-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.dashboard-page .camera-list-mount .codec-line {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-page .camera-list-mount .watch-btn-cell {
  text-align: right;
  white-space: nowrap;
}

/* Stream URL bar - shown below video when a stream is active */
.stream-url-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.6rem 1rem;
  background: #0e0e0e;
  border: 1px solid var(--border);
  border-radius: 20px;
  flex-wrap: wrap;
}

.stream-url-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.stream-url-text {
  flex: 1;
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
  color: var(--primary);
  word-break: break-all;
  min-width: 0;
}

.stream-url-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-url-action {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.2s, color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.btn-url-action:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-url-action.copied {
  border-color: var(--success);
  color: var(--success);
}

/* Watch button on dashboard camera cards */
.dashboard-page .watch-btn {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.dashboard-page .watch-btn:hover:not(:disabled) {
  background: rgba(212, 237, 49, 0.1);
}

.dashboard-page .watch-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: var(--border);
  color: var(--text-muted);
}
