:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --green: #16a34a;
  --amber: #d97706;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--surface-2);
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #4f46e5 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  width: 100%;
  max-width: 400px;
  border-radius: 20px;
  padding: 40px 38px 32px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.45);
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  margin-bottom: 28px;
}
.login-titles { display: flex; flex-direction: column; gap: 4px; }
.login-brand h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
.login-sub { color: var(--muted); margin: 0; font-size: 14px; }
.brand-logo {
  display: block;
  flex: none;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.3);
}
.login-brand .brand-logo { width: 60px; height: 60px; }
.brand .brand-logo { width: 34px; height: 34px; box-shadow: none; }
.login-form .field { display: block; margin-bottom: 18px; }
.login-form span { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 7px; }
.login-form input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-form input::placeholder { color: #94a3b8; }
.login-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
/* password field with press-and-hold reveal */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  color: #94a3b8;
  cursor: pointer;
  border-radius: 0 10px 10px 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: color .15s;
}
.pw-toggle:hover { color: var(--muted); }
.pw-toggle.is-active { color: var(--primary); }
.btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary.inline { width: auto; display: inline-block; padding: 10px 18px; text-decoration: none; }
.alert {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 18px;
}
.alert svg { flex: none; }
/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px;
  background: var(--bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.brand-text { font-weight: 700; color: #fff; font-size: 16px; }
.menu { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.menu a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.menu a:hover { background: var(--bg-soft); color: #fff; }
.menu a.active { background: var(--primary); color: #fff; }
.sidebar-foot { border-top: 1px solid #243047; padding-top: 16px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.user-name { color: #fff; font-size: 14px; }
.user-role { font-size: 12px; color: #94a3b8; text-transform: capitalize; }
.btn-logout {
  width: 100%;
  background: transparent;
  border: 1px solid #334155;
  color: #cbd5e1;
  padding: 9px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s;
}
.btn-logout:hover { background: var(--bg-soft); color: #fff; }

.content { flex: 1; padding: 32px 40px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-head p { margin: 0 0 24px; color: var(--muted); }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.card-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.card-value { font-size: 22px; font-weight: 700; text-transform: capitalize; }

/* ---------- Panel / tables ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 24px;
}
.panel h2 { margin: 0 0 16px; font-size: 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 12px; border-bottom: 1px solid var(--surface-2); }
.table tr:last-child td { border-bottom: none; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: #eef2ff;
  color: var(--primary-dark);
  border: 1px solid #e0e7ff;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.badge-admin { background: #eef2ff; color: var(--primary-dark); border-color: #e0e7ff; }
.badge-manager { background: #ecfdf5; color: var(--green); border-color: #d1fae5; }
.badge-viewer { background: #f1f5f9; color: var(--muted); }
.badge-published { background: #ecfdf5; color: var(--green); border-color: #d1fae5; }
.badge-draft { background: #fffbeb; color: var(--amber); border-color: #fef3c7; }

/* ---------- Media ---------- */
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form input[type="text"], .inline-form select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; outline: none;
}
.inline-form input[type="text"] { flex: 1; min-width: 180px; }
.inline-form input:focus, .inline-form select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: 12px; }
.btn-secondary {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--border); border-radius: 9px;
  background: #fff; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 9px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-primary.tiny, .btn-secondary.tiny, .btn-danger.tiny { padding: 6px 11px; font-size: 12px; }
.row-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.row-actions form { margin: 0; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.media-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  text-decoration: none; color: var(--text); transition: transform .12s, box-shadow .12s;
}
.media-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(2,6,23,.12); }
.media-thumb {
  position: relative; aspect-ratio: 16/9;
  background: linear-gradient(135deg, #1e293b, #4f46e5);
  display: flex; align-items: center; justify-content: center;
}
.media-thumb .play { color: #fff; font-size: 30px; opacity: .9; }
.media-tag { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 5px; letter-spacing: .05em; }
.media-badge { position: static; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: capitalize; background: var(--surface-2); border: 1px solid var(--border); }
.media-thumb .media-badge { position: absolute; top: 8px; right: 8px; }
.badge-ready, .badge-live { background: #ecfdf5; color: var(--green); border-color: #d1fae5; }
.badge-processing, .badge-provisioning, .badge-starting, .badge-stopping, .badge-deleting { background: #fffbeb; color: var(--amber); border-color: #fef3c7; }
.badge-errored, .badge-stopped { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.media-meta { padding: 12px 14px; }
.media-title { font-weight: 600; font-size: 14px; }
.media-sub { color: var(--muted); font-size: 12px; margin-top: 3px; text-transform: capitalize; }

.player-wrap { background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16/9; margin-bottom: 14px; }
.player-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 12px 0 4px; }
.progress-fill { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.broadcast-controls { display: flex; gap: 10px; align-items: center; margin: 14px 0 0; flex-wrap: wrap; }

/* ---------- Forbidden ---------- */
.forbidden { text-align: center; padding: 30px 0; }
.forbidden-code { font-size: 56px; font-weight: 800; color: var(--primary); }
.forbidden p { color: var(--muted); margin: 8px 0 20px; }
