:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  padding:
    calc(16px + var(--safe-top))
    16px
    calc(16px + var(--safe-bottom));
}

.app {
  max-width: 480px;
  margin: 0 auto;
}

header {
  margin-bottom: 20px;
}

header h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 700;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
}

.badge.active {
  color: var(--success);
  background: rgba(74, 222, 128, 0.12);
}

.badge.warn {
  color: var(--warning);
  background: rgba(251, 191, 36, 0.12);
}

.card {
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.hidden {
  display: none !important;
}

.option-group {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
}

.option input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.btn-row {
  display: grid;
  gap: 10px;
}

button {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #082f49;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.16);
  color: var(--danger);
}

.preview-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: #020617;
  aspect-ratio: 16 / 9;
}

#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #020617;
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  padding: 16px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.9rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.live {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18);
}

.status-dot.recording {
  background: var(--danger);
  animation: pulse 1.2s infinite;
}

.status-dot.connected {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.18);
}

.btn-approve.connected {
  background: rgba(74, 222, 128, 0.2);
  color: var(--success);
}

.hint-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.link-btn {
  appearance: none;
  border: none;
  background: none;
  color: var(--accent);
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.ios-limit-banner {
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.guide-context,
.guide-note {
  margin: 8px 0 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.72);
}

.modal-panel {
  width: min(100%, 420px);
  max-height: min(85vh, 640px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: var(--radius);
  padding: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
}

.modal-body ol {
  margin: 8px 0 0;
  padding-right: 18px;
  line-height: 1.6;
}

body.modal-open {
  overflow: hidden;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.recordings-list {
  display: grid;
  gap: 10px;
}

.recording-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
}

.recording-item audio {
  width: 100%;
  max-width: 220px;
}

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.5;
}

.alert-info {
  background: rgba(56, 189, 248, 0.12);
  color: #bae6fd;
}

.alert-error {
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
}

.alert ol {
  margin: 8px 0 0;
  padding-left: 18px;
}

.install-steps {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.webrtc-panel label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.webrtc-panel input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: var(--surface-2);
  color: var(--text);
}

footer {
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  text-align: center;
}

.login-app label,
.stack-form label,
.admin-app label {
  display: block;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.login-app input,
.stack-form input,
.stack-form select,
.admin-app input,
.admin-app select {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 4px;
}

.btn-approve {
  width: 100%;
  min-height: 64px;
  font-size: 1.4rem;
  margin-top: 16px;
}

.approve-card .lead {
  text-align: center;
  margin: 0 0 16px;
  line-height: 1.6;
}

.alert-warning {
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
}

.ios-warning p {
  margin: 8px 0 0;
  line-height: 1.5;
}

.status-list {
  margin: 0;
  padding-right: 18px;
  line-height: 1.8;
}

.admin-app {
  max-width: 1100px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.admin-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-grid .span-2 {
  grid-column: span 2;
}

.admin-controls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-preview {
  aspect-ratio: 16 / 9;
}

.schedule-item,
.recording-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.schedule-item {
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 8px;
}

.recording-controls {
  flex-direction: column;
  align-items: stretch;
  min-width: 220px;
}

.recording-controls audio {
  width: 100%;
}

.recording-controls a {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
}

.stack-form {
  display: grid;
  gap: 4px;
}

@media (max-width: 768px) {
  .admin-grid,
  .admin-grid .span-2 {
    grid-template-columns: 1fr;
    grid-column: auto;
  }

  .admin-controls {
    grid-template-columns: 1fr;
  }
}
