/* ===== CAMPORTAL — Multi-Camera Dashboard Theme ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg-deep: #0b0f14;
  --bg-surface: #111820;
  --bg-elevated: #1a2230;
  --bg-card: rgba(26, 34, 48, 0.8);

  --accent: #38bdf8;
  --accent-vivid: #7dd3fc;
  --accent-deep: #0c4a6e;
  --accent-dim: rgba(56, 189, 248, 0.1);
  --accent-glow: rgba(56, 189, 248, 0.3);

  --btn-bg: #0e7490;
  --btn-bg-hover: #0891b2;
  --btn-glow: rgba(14, 116, 144, 0.4);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border: rgba(148, 163, 184, 0.1);
  --border-hover: rgba(148, 163, 184, 0.22);

  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --logo-filter: brightness(0) invert(1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
  --bg-deep: #f8fafc;
  --bg-surface: #ffffff;
  --bg-elevated: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.9);
  --accent: #0284c7;
  --accent-vivid: #0369a1;
  --accent-deep: #0c4a6e;
  --accent-dim: rgba(2, 132, 199, 0.08);
  --accent-glow: rgba(2, 132, 199, 0.2);
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --border-hover: rgba(15, 23, 42, 0.15);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --btn-bg: #0e7490;
  --btn-bg-hover: #0891b2;
  --btn-glow: rgba(14, 116, 144, 0.35);
  --logo-filter: none;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(56, 189, 248, 0.04), transparent 50%),
    radial-gradient(ellipse 50% 40% at 80% 100%, rgba(14, 116, 144, 0.03), transparent);
  pointer-events: none;
  z-index: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-vivid); }

/* ===== TOPNAV ===== */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  background: rgba(17, 24, 32, 0.92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

[data-theme="light"] .topnav {
  background: rgba(255, 255, 255, 0.92);
}

[data-theme="light"] .toggle-track {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

[data-theme="light"] .toggle-track::after {
  background: #94a3b8;
}

[data-theme="light"] .toggle-switch input:checked + .toggle-track {
  background: var(--accent-deep);
  border-color: var(--accent);
}

[data-theme="light"] .toggle-switch input:checked + .toggle-track::after {
  background: var(--accent);
}

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

.logo-link { display: flex; align-items: center; }
.logo {
  height: 30px;
  filter: var(--logo-filter);
  transition: opacity 0.2s;
}
.logo:hover { opacity: 0.8; }

.portal-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(56, 189, 248, 0.15);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-right a, .nav-right button {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s var(--ease-out);
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.nav-right a:hover, .nav-right button:hover {
  color: var(--text-primary);
  background: var(--accent-dim);
}

.nav-right .nav-active {
  color: var(--accent);
  background: var(--accent-dim);
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  padding: 0 !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: block; }

/* ===== MAIN CONTAINER ===== */
.container {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
  width: 100%;
}

/* ===== PAGE HEADER ===== */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ===== CAMERA GRID (Dashboard) ===== */
.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.25rem;
}

.camera-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.3s var(--ease-out);
  backdrop-filter: blur(10px);
}

.camera-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  transform: translateY(-2px);
}

.camera-card-preview {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-surface);
  overflow: hidden;
}

.camera-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s var(--ease-out);
}

.camera-card:hover .camera-card-preview img {
  transform: scale(1.03);
}

.camera-card-preview .no-image {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.camera-card-preview .no-image svg {
  width: 48px;
  height: 48px;
  opacity: 0.3;
}

/* Status badge na kartici */
.status-badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  backdrop-filter: blur(8px);
}

.status-badge.online {
  background: rgba(52, 211, 153, 0.2);
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.status-badge.offline {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.online .status-dot {
  animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.camera-card-body {
  padding: 1rem 1.25rem;
}

.camera-card-name {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

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

.camera-card-stats {
  display: flex;
  gap: 1.25rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.camera-card-stats span {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.camera-card-stats svg {
  width: 13px;
  height: 13px;
  opacity: 0.6;
}

.camera-card-actions {
  display: flex;
  border-top: 1px solid var(--border);
}

.camera-card-actions a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s;
  border-right: 1px solid var(--border);
}

.camera-card-actions a:last-child { border-right: none; }

.camera-card-actions a:hover {
  color: var(--accent);
  background: var(--accent-dim);
}

.camera-card-actions svg {
  width: 14px;
  height: 14px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  text-decoration: none;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--btn-bg);
  color: white;
  box-shadow: 0 2px 8px var(--btn-glow);
}

.btn-primary:hover {
  background: var(--btn-bg-hover);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--btn-glow);
}

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

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--accent-dim);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.form-input {
  width: 100%;
  padding: 0.55rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

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

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

/* ===== CARD (generic) ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  backdrop-filter: blur(10px);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.modal h2 {
  font-size: 1.15rem;
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* ===== API KEY display ===== */
.api-key-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
}

.api-key-box code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
  transition: color 0.2s;
}

.copy-btn:hover { color: var(--accent); }

/* ===== IMAGE GALLERY ===== */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.img-card {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: all 0.3s var(--ease-out);
  cursor: pointer;
}

.img-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  transform: translateY(-2px);
}

.img-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}

.img-card-info {
  padding: 0.6rem 0.85rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ===== SETTINGS SECTIONS ===== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  backdrop-filter: blur(10px);
}

.settings-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-section h3 svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.settings-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* ===== FLASH MESSAGES ===== */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.flash-success {
  background: rgba(52, 211, 153, 0.1);
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.flash-error {
  background: rgba(248, 113, 113, 0.1);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

/* ===== SUB-NAV (per camera) ===== */
.sub-nav {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  padding: 0.25rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.sub-nav a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all 0.2s;
}

.sub-nav a:hover {
  color: var(--text-primary);
  background: var(--accent-dim);
}

.sub-nav a.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.sub-nav svg {
  width: 15px;
  height: 15px;
}

/* ===== LIVESTREAM ===== */
.stream-container {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.stream-container img,
.stream-container canvas {
  width: 100%;
  display: block;
}

.stream-overlay {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.stream-live-badge {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  background: rgba(239, 68, 68, 0.85);
  color: white;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  backdrop-filter: blur(4px);
}

.stream-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
  animation: pulse-dot 1.5s ease infinite;
}

/* ===== FOOTER ===== */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer-dot { margin: 0 0.5rem; opacity: 0.4; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.3;
}

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

.empty-state p {
  font-size: 0.88rem;
  margin-bottom: 1.5rem;
}

/* ===== CHECKBOX/TOGGLE ===== */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-primary);
  user-select: none;
  line-height: 1.3;
}

.toggle-switch input { 
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-track {
  display: inline-block;
  width: 40px;
  min-width: 40px;
  height: 22px;
  background: var(--bg-elevated);
  border: 2px solid var(--border-hover);
  border-radius: 22px;
  position: relative;
  transition: all 0.25s;
  flex-shrink: 0;
  overflow: hidden;
  vertical-align: middle;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.25s;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--accent-deep);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-track::after {
  left: 20px;
  background: var(--accent-vivid);
}

/* ===== LOGIN ===== */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  backdrop-filter: blur(10px);
  text-align: center;
}

.login-card .logo {
  height: 28px;
  margin-bottom: 1.5rem;
}

.login-card h2 {
  font-size: 1.15rem;
  margin-bottom: 0.35rem;
}

.login-card .subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.75rem;
}

.login-card .form-group {
  text-align: left;
}

.login-card .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 0.65rem;
  margin-top: 0.5rem;
}

.login-error {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .topnav { padding: 0 1rem; }
  .nav-right a span, .nav-right button span { display: none; }
  .container { padding: 1.25rem 1rem; }
  .camera-grid { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .portal-badge { display: none; }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.camera-card { animation: fadeIn 0.4s var(--ease-out) both; }
.camera-card:nth-child(2) { animation-delay: 0.05s; }
.camera-card:nth-child(3) { animation-delay: 0.1s; }
.camera-card:nth-child(4) { animation-delay: 0.15s; }
.camera-card:nth-child(5) { animation-delay: 0.2s; }
