:root {
  color-scheme: dark;
  --bg: #071116;
  --surface: #0d1c23;
  --surface-2: #12252e;
  --border: #1b3642;
  --text: #eef6f8;
  --muted: #8aa5b1;
  --primary: #10b981;
  --primary-hover: #059669;
  --accent: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 14px;
  --nav-h: 64px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100dvh;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12.5px;
}

/* LOGIN SCREEN */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top, #0f2c36 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-badge {
  display: inline-flex;
  margin-bottom: 10px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-form {
  margin-top: 20px;
  display: grid;
  gap: 12px;
}

.error-text {
  color: #fca5a5;
  font-size: 13px;
  margin: 12px 0 0;
}

/* APP SHELL */
.app-shell {
  max-width: 780px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(7, 17, 22, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-title {
  font-weight: 700;
  font-size: 16px;
}

.topbar-sub {
  font-size: 11.5px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* STATS STRIP */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 14px 4px;
}

.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}

.stat-lbl {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* MAIN CONTENT */
.main-content {
  padding: 12px 14px;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0 10px;
}

.section-header h2,
.card h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 14px;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

/* CHIPS */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  background: rgba(16, 185, 129, 0.16);
  border-color: var(--primary);
  color: #6ee7b7;
}

/* VIDEO GRID */
.video-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 600px) {
  .video-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: border-color 0.15s;
}

.video-card:active {
  transform: scale(0.985);
}

.video-thumb-wrap {
  position: relative;
  aspect-ratio: 9 / 12;
  background: #0a171d;
  overflow: hidden;
}

.video-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 28px;
}

.play-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(7, 17, 22, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  font-size: 13px;
}

.status-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.badge-ready {
  background: rgba(16, 185, 129, 0.88);
  color: #032117;
}

.badge-uploaded {
  background: rgba(56, 189, 248, 0.85);
  color: #041d29;
}

.badge-hold {
  background: rgba(245, 158, 11, 0.9);
  color: #291700;
}

.video-info {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.video-title {
  font-size: 13px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: auto;
}

/* FORMS & INPUTS */
.stack-form {
  display: grid;
  gap: 11px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.field-group {
  display: grid;
  gap: 5px;
}

.field-group label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(27, 54, 66, 0.55);
  cursor: pointer;
}

.toggle-row span {
  display: flex;
  flex-direction: column;
}

.toggle-row small {
  color: var(--muted);
  font-size: 12px;
}

.switch {
  appearance: none;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 999px;
  background: #233c48;
  position: relative;
  cursor: pointer;
  transition: background 0.18s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
}

.switch:checked {
  background: var(--primary);
}

.switch:checked::after {
  transform: translateX(20px);
}

.inline-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 6px;
}

.inline-checks label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  font-size: 13px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* BUTTONS */
.btn {
  border: none;
  border-radius: 11px;
  padding: 11px 15px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 12.5px;
}

.btn-xs {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #032016;
}

.btn-accent {
  background: var(--accent);
  color: #241400;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

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

/* LISTS */
.stack-list {
  display: grid;
  gap: 9px;
}

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.list-item-title {
  font-weight: 600;
  font-size: 14px;
}

.list-item-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.pill-green {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.pill-amber {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.pill-red {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.pill-blue {
  background: rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
}

/* CUSTOM RULES LIST */
.rules-list {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.rule-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 13px;
}

.rule-row span {
  flex: 1;
}

.add-rule-row {
  display: flex;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 780px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(13, 28, 35, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 30;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.nav-ico {
  font-size: 19px;
}

.nav-item.active {
  color: var(--primary);
}

/* MODAL DIALOG */
.video-modal {
  padding: 0;
  border: none;
  background: transparent;
  width: min(100vw, 520px);
  max-width: 100vw;
  max-height: 94dvh;
  margin: auto;
  color: var(--text);
}

.video-modal::backdrop {
  background: rgba(2, 8, 12, 0.82);
  backdrop-filter: blur(6px);
}

.modal-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
}

.modal-body {
  padding: 14px;
  overflow-y: auto;
  display: grid;
  gap: 12px;
}

.player-wrap {
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

.player-wrap video {
  width: 100%;
  max-height: 54dvh;
  background: #000;
}

.review-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 13px;
}

.review-box ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.revise-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.revise-box summary {
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
}

.revise-box form {
  margin-top: 10px;
}

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px);
  background: #0f2933;
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
