/* ============================================================
   S1 — app stylesheet (auth + dashboard)
   Mirrors the tokens and primitives defined in home.css.
   ============================================================ */

:root {
  --bg:          oklch(0.985 0.004 75);
  --bg-elev:    oklch(0.975 0.005 70);
  --bg-sunken:  oklch(0.955 0.007 65);
  --ink:        oklch(0.22 0.010 60);
  --ink-2:      oklch(0.40 0.010 55);
  --ink-3:      oklch(0.56 0.010 55);
  --ink-4:      oklch(0.72 0.010 55);
  --hairline:   oklch(0.90 0.012 60);
  --hairline-2: oklch(0.82 0.014 60);

  --accent:     oklch(0.72 0.15 55);
  --accent-ink: oklch(0.60 0.18 50);
  --live:       oklch(0.65 0.14 150);
  --danger:     oklch(0.58 0.18 25);

  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 22px;

  --shadow-card:  0 1px 2px oklch(0 0 0 / 0.04), 0 8px 32px oklch(0 0 0 / 0.04);
  --shadow-float: 0 30px 80px -20px oklch(0 0 0 / 0.18), 0 10px 30px -10px oklch(0 0 0 / 0.10);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }
.mono   { font-family: var(--font-mono); }

/* ---------- Brand ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-mark { width: 26px; height: 26px; display: block; }
.brand-name { font-size: 17px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--hairline);
  color: var(--ink);
  font: 500 14px/1 var(--font-sans);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover  { background: var(--bg-sunken); border-color: var(--hairline-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px oklch(0.72 0.15 55 / 0.25);
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.btn-primary:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
}

.btn-ghost {
  background: transparent;
  border-color: var(--hairline);
  color: var(--ink-2);
}
.btn-ghost:hover { background: var(--bg-elev); color: var(--ink); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-sm   { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font: 500 11px/1 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--ink);
  font: 400 14px/1.4 var(--font-sans);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--ink-4); }
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent-ink);
  box-shadow: 0 0 0 3px oklch(0.72 0.15 55 / 0.15);
}
.form-group input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
  accent-color: var(--accent-ink);
}
.form-group textarea {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

.error-message {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0;
  min-height: 1em;
}
.error-message:empty { margin: 0; }

/* ---------- Auth page ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 28px 20px;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, oklch(0.97 0.02 65) 0%, transparent 60%),
    var(--bg);
}
.auth-container { width: 100%; max-width: 420px; }

.auth-card {
  background: var(--bg-elev);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 36px 32px 32px;
  box-shadow: var(--shadow-card);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  text-decoration: none;
  color: var(--ink);
}
.auth-brand .brand-mark { width: 48px; height: 48px; }
.auth-brand .brand-name { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }

.auth-title {
  text-align: center;
  margin: 18px 0 4px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.auth-subtitle {
  text-align: center;
  color: var(--ink-3);
  margin-bottom: 24px;
  font-size: 13px;
}

.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--ink-3);
}
.auth-switch a {
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 500;
}
.auth-switch a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: oklch(0.985 0.004 75 / 0.85);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-user {
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
}
.toolbar-left  { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 10px; }
.toolbar-right label {
  font: 500 11px/1 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.toolbar-right select {
  padding: 6px 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--ink);
  font: 500 13px/1 var(--font-sans);
  cursor: pointer;
}

/* ---------- Stream grid ---------- */
.stream-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: 14px;
  padding: 20px 28px 28px;
}

.stream-cell {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.stream-cell:hover { box-shadow: var(--shadow-float); }

.stream-thumb {
  width: 100%; height: 100%;
  display: block;
  object-fit: cover;
  position: absolute;
  top: 0; left: 0;
}
.stream-thumb.hidden { display: none; }

.stream-video {
  width: 100%; height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}
.stream-video.hidden { display: none; }

.stream-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
  opacity: 0;
  transition: opacity 0.2s ease;
  color: #fff;
}
.stream-overlay--idle { opacity: 1; }
.stream-cell:hover .stream-overlay { opacity: 1; }

.stream-info { display: flex; flex-direction: column; gap: 3px; }
.stream-name { font-size: 13px; font-weight: 600; }
.stream-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.04em;
}

.health-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  background: #8a8a8a;
}
.health-dot[data-health="connecting"] { background: #f59e0b; }
.health-dot[data-health="live"]       { background: oklch(0.78 0.18 150); box-shadow: 0 0 6px oklch(0.78 0.18 150); }
.health-dot[data-health="error"]      { background: oklch(0.68 0.22 25); }
.health-dot[data-health="stopped"]    { background: #8a8a8a; }
.stream-status[data-status="live"]  { color: oklch(0.88 0.14 150); }
.stream-status[data-status="error"] { color: oklch(0.82 0.18 25); }

.stream-play-btn {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  z-index: 2;
  transition: background 0.2s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 4px;
}
.stream-play-btn:hover  { background: rgba(255, 255, 255, 0.28); }
.stream-play-btn:active { transform: translate(-50%, -50%) scale(0.96); }
.stream-play-btn.hidden { display: none; }

.stream-cell[draggable="true"] { cursor: grab; }
.stream-cell.dragging { opacity: 0.4; }
.stream-cell.drag-over {
  outline: 2px dashed var(--accent-ink);
  outline-offset: -2px;
}

.stream-controls { display: flex; gap: 4px; }
.stream-controls .btn-icon {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 13px;
}
.stream-controls .btn-icon:hover {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.35);
}

.record-btn.recording {
  color: oklch(0.72 0.22 25);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: oklch(0.2 0.01 60 / 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  z-index: 1;
  box-shadow: var(--shadow-float);
}
.modal-content h2 {
  margin-bottom: 18px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.modal-content-wide { max-width: 720px; }

/* ---------- Logs modal ---------- */
.logs-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}
.logs-head h2 { margin-bottom: 2px; }
.logs-status {
  font: 500 11px/1 var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.logs-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.logs-last-error {
  background: oklch(0.97 0.03 25);
  border: 1px solid oklch(0.88 0.08 25);
  color: oklch(0.45 0.18 25);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
  word-break: break-word;
}
.logs-body {
  max-height: 440px;
  overflow: auto;
  background: var(--bg-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: 400 12px/1.55 var(--font-mono);
  color: var(--ink-2);
  white-space: pre-wrap;
  word-break: break-all;
}
.logs-body .log-line { padding: 1px 0; }
.logs-body .log-ts   { color: var(--ink-4); margin-right: 6px; }
.logs-body .log-error { color: oklch(0.52 0.18 25); }
.logs-body .log-warn  { color: oklch(0.52 0.14 80); }
.logs-body .log-info  { color: var(--ink-2); }
.logs-body .log-empty { color: var(--ink-4); font-style: italic; }

/* ---------- Probe result (edit-stream modal) ---------- */
.probe-result {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin: 4px 0 10px;
  border: 1px solid var(--hairline);
  background: var(--bg-sunken);
}
.probe-result.ok {
  border-color: oklch(0.85 0.10 150);
  color: oklch(0.40 0.16 150);
  background: oklch(0.96 0.03 150);
}
.probe-result.error {
  border-color: oklch(0.88 0.08 25);
  color: oklch(0.45 0.18 25);
  background: oklch(0.97 0.03 25);
}
.probe-result strong { display: block; margin-bottom: 6px; font-weight: 700; }
.probe-result dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 0;
}
.probe-result dt { color: var(--ink-3); font-weight: 500; font-size: 12px; }
.probe-result dd {
  margin: 0;
  color: var(--ink);
  font: 500 12px/1.4 var(--font-mono);
  word-break: break-word;
}
.probe-error-detail {
  font: 400 12px/1.5 var(--font-mono);
  word-break: break-word;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--hairline);
}
.tab {
  padding: 9px 16px;
  background: none;
  border: none;
  color: var(--ink-3);
  cursor: pointer;
  font: 500 14px/1 var(--font-sans);
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
  margin-bottom: -1px;
}
.tab:hover  { color: var(--ink); }
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Share Result ---------- */
.share-result {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.share-result input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--ink);
  font: 400 13px/1.4 var(--font-mono);
}

/* ---------- Share page ---------- */
.share-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 20px;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, oklch(0.97 0.02 65) 0%, transparent 60%),
    var(--bg);
}
.share-container {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.share-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.share-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.share-title {
  font: 700 28px/1.15 var(--font-sans);
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}
.share-subtitle {
  font-size: 13px;
  color: var(--ink-3);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 8px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--hairline);
  font: 600 11px/1 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.live-pill::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 6px var(--live);
  animation: live-blink 1.8s ease-in-out infinite;
}
.live-pill[data-status="connecting"]::before { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; }
.live-pill[data-status="offline"]::before    { background: var(--ink-4); box-shadow: none; animation: none; }
@keyframes live-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

.share-player {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
}
.share-player video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}
.share-player-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #fff;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.15), rgba(0,0,0,0.6));
  transition: opacity 0.2s ease;
}
.share-player-state.hidden { display: none; }

.share-play-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 6px;
  transition: background 0.2s ease, transform 0.1s ease;
}
.share-play-btn:hover  { background: rgba(255, 255, 255, 0.28); }
.share-play-btn:active { transform: scale(0.96); }

.share-state-label {
  font-size: 13px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.78);
}
.share-state-label.error {
  color: oklch(0.88 0.15 25);
}

.share-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  font-size: 13px;
}
.share-footer .brand {
  color: var(--ink-3);
  font-weight: 500;
  gap: 6px;
}
.share-footer .brand-mark { width: 16px; height: 16px; }
.share-footer .brand strong {
  color: var(--ink);
  font-weight: 700;
}

@media (max-width: 640px) {
  .share-title { font-size: 22px; }
  .share-header { gap: 10px; }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .topbar, .toolbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
  .stream-grid { --cols: 1 !important; padding: 14px 16px; gap: 12px; }
  .auth-card { padding: 28px 22px; }
}
