:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

header {
  padding: 2rem 1.5rem 1rem;
  max-width: 720px;
  margin: 0 auto;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.subtitle {
  color: var(--muted);
  margin-top: 0.25rem;
}

.badge {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

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

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.label {
  color: var(--muted);
  font-size: 0.9rem;
}

.status-pill {
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-pill.stopped { background: #374151; color: #d1d5db; }
.status-pill.live, .status-pill.running { background: #14532d; color: #86efac; }
.status-pill.starting { background: #713f12; color: #fde68a; }
.status-pill.error { background: #7f1d1d; color: #fca5a5; }

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

.form-group label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.form-group small {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.schedule-options {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.day-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.day-tag {
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--border);
  color: var(--text);
}

.status-pill.scheduled { background: #1e3a5f; color: #93c5fd; }
.status-pill.paused { background: #374151; color: #d1d5db; }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="time"],
input[type="datetime-local"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.input-row {
  display: flex;
  gap: 0.5rem;
}

.input-row input {
  flex: 1;
}

.btn-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { background: var(--border); color: var(--text); }
.btn.secondary:hover:not(:disabled) { background: #3d4f6a; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn.small { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

.error-msg {
  background: #7f1d1d33;
  border: 1px solid #7f1d1d;
  color: #fca5a5;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.info-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.hidden { display: none !important; }

.preview-wrap {
  margin-top: 1rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-wrap img {
  width: 100%;
  display: block;
}

.liveview-wrap {
  position: relative;
  margin-bottom: 1rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  aspect-ratio: 16 / 9;
}

.liveview-wrap:fullscreen,
.liveview-wrap:-webkit-full-screen {
  aspect-ratio: unset;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  border: none;
}

.liveview-wrap:fullscreen img,
.liveview-wrap:-webkit-full-screen img {
  object-fit: contain;
}

/* CSS fullscreen — works on http://Pi-IP (native API blocked without HTTPS) */
.liveview-wrap.liveview-fs-pseudo {
  position: fixed;
  inset: 0;
  z-index: 10000;
  width: 100vw;
  height: 100vh;
  max-width: none;
  margin: 0;
  border-radius: 0;
  border: none;
  aspect-ratio: unset;
}

.liveview-wrap.liveview-fs-pseudo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

body.liveview-fs-active {
  overflow: hidden;
}

.liveview-fs-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 20;
  pointer-events: auto;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.liveview-fs-btn:disabled {
  opacity: 1;
  cursor: pointer;
}

.liveview-fs-btn:hover {
  background: rgba(0, 0, 0, 0.85);
}

#liveview-fullscreen-btn:disabled {
  opacity: 1;
  cursor: pointer;
}

.liveview-wrap img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.session-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.session-item h3 {
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

.session-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.session-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

@media (max-width: 480px) {
  .btn-row { flex-direction: column; }
  .btn { width: 100%; }
}
