:root {
  --bg: #07100f;
  --surface: #0d1817;
  --surface-strong: #132321;
  --line: #243633;
  --text: #f4f7f5;
  --muted: #95aaa5;
  --accent: #ff5a36;
  --accent-soft: rgba(255, 90, 54, 0.14);
  --success: #62d49b;
  --warning: #ffc166;
  --radius: 18px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 75% 5%, rgba(255, 90, 54, 0.09), transparent 30rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
body.drawer-open { overflow: hidden; }

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.login-card {
  width: min(620px, 100%);
  padding: clamp(30px, 7vw, 64px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(19, 35, 33, 0.96), rgba(9, 19, 17, 0.96));
  box-shadow: var(--shadow);
}

.login-brand { margin-bottom: 64px; }
.login-card h1 { max-width: 520px; }
.login-copy { max-width: 520px; margin: 22px 0 28px; color: var(--muted); font-size: 1.06rem; line-height: 1.7; }
.login-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.login-security { display: flex; align-items: center; gap: 10px; margin-top: 22px; color: var(--muted); font-size: 0.8rem; }
.login-card footer { display: flex; gap: 18px; margin-top: 64px; padding-top: 20px; border-top: 1px solid var(--line); }
.login-card footer a { color: var(--muted); font-size: 0.8rem; text-decoration: none; }
.login-card footer a:hover, .login-card footer a:focus-visible { color: var(--text); }

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
  background: rgba(7, 16, 15, 0.9);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 12px 30px rgba(255, 90, 54, 0.24);
  font-weight: 900;
}

.brand strong, .brand small, .sidebar-footer strong, .sidebar-footer small { display: block; }
.brand strong { letter-spacing: 0.08em; }
.brand small, .sidebar-footer small { color: var(--muted); }

nav { margin-top: 56px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 4px 0;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav-item:hover, .nav-item:focus-visible, .nav-item.is-active {
  color: var(--text);
  border-color: var(--line);
  background: var(--surface-strong);
}

.nav-item.is-active span { color: var(--accent); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 0.82rem;
}

.connection-status { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sidebar-footer .icon-button { margin-left: auto; }

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(98, 212, 155, 0.1);
}

.main-content {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 42px clamp(24px, 4vw, 64px) 64px;
}

.topbar, .panel-heading, .topbar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.topbar-actions { justify-content: flex-end; }

.timezone-pill, .count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(13, 24, 23, 0.7);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1;
  letter-spacing: -0.055em;
}

h2 { margin-bottom: 0; font-size: 1.3rem; }

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.button {
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface-strong);
  font-weight: 700;
}

.button:hover, .button:focus-visible { border-color: #4b625d; }
.button:disabled { cursor: wait; opacity: 0.62; }
.button-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button-primary:hover, .button-primary:focus-visible { border-color: #ff846a; background: #ff6847; }
.button-danger { border-color: #d83f3f; background: #d83f3f; color: #fff; }

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
}

.icon-button:hover, .icon-button:focus-visible { color: var(--text); border-color: #4b625d; }
.icon-button-large { width: 42px; height: 42px; font-size: 1.6rem; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 34px 0 20px;
}

.summary-card {
  min-height: 118px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--surface-strong), var(--surface));
  box-shadow: var(--shadow);
}

.summary-card span { display: block; color: var(--muted); font-size: 0.83rem; }
.summary-card strong { display: block; margin-top: 14px; font-size: 1.7rem; }
.summary-card-accent { border-color: rgba(255, 90, 54, 0.42); background: var(--accent-soft); }

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(13, 24, 23, 0.88);
  box-shadow: var(--shadow);
}

.panel-heading { padding: 22px 24px; border-bottom: 1px solid var(--line); }

.search-field input {
  width: min(310px, 42vw);
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  color: var(--text);
  background: #091311;
}

.search-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.feedback { padding: 18px 24px; color: var(--muted); }
.feedback:empty { display: none; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 17px 24px; border-top: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.09em; text-transform: uppercase; }
td { font-size: 0.9rem; }
.video-title { color: var(--text); font-weight: 720; }
.video-id { display: block; margin-top: 5px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.72rem; }

.row-action, .remove-button {
  border: 0;
  color: var(--accent);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 800;
}

.row-action:hover, .row-action:focus-visible, .remove-button:hover, .remove-button:focus-visible { text-decoration: underline; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--muted);
  background: #1b2a28;
  font-size: 0.74rem;
  font-weight: 760;
}

.badge.private { color: var(--warning); background: rgba(255, 193, 102, 0.11); }
.badge.public { color: var(--success); background: rgba(98, 212, 155, 0.11); }
.video-cards { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.playlist-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.75fr) minmax(420px, 1.25fr);
  gap: 18px;
}

.playlist-list, .playlist-items { display: grid; gap: 1px; background: var(--line); }

.playlist-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  padding: 18px 20px;
  border: 0;
  color: var(--text);
  background: var(--surface);
  text-align: left;
}

.playlist-card:hover, .playlist-card:focus-visible, .playlist-card.is-selected { background: var(--surface-strong); }
.playlist-card.is-selected { box-shadow: inset 3px 0 0 var(--accent); }
.playlist-card strong, .playlist-card small, .playlist-item strong, .playlist-item small { display: block; }
.playlist-card small, .playlist-item small { overflow: hidden; margin-top: 6px; color: var(--muted); font-size: 0.76rem; text-overflow: ellipsis; }
.playlist-card-meta { display: flex; align-items: center; gap: 10px; }
.playlist-card-meta b { color: var(--muted); }

.playlist-items-heading { min-height: 92px; }
.inline-form { display: flex; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.inline-form label { flex: 1; }
.inline-form select { width: 100%; height: 44px; }

.playlist-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
}

.position { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; color: var(--muted); background: #192825; font-size: 0.75rem; }
.remove-button { color: #ff8c7a; }

.automation-layout {
  display: grid;
  grid-template-columns: minmax(480px, 1.15fr) minmax(320px, 0.85fr);
  align-items: start;
  gap: 18px;
}

.automation-intro {
  margin: 0;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.65;
}

.automation-instructions {
  display: grid;
  gap: 9px;
  padding: 22px 24px;
  color: #cbd7d3;
  font-size: 0.84rem;
  font-weight: 720;
}

.automation-instructions .field-hint { margin-left: 0; }
.automation-instructions textarea { width: 100%; }

.permission-fieldset {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 0 24px 22px;
  border: 0;
}

.permission-fieldset legend {
  padding: 0 0 12px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.check-row, .toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  background: rgba(7, 16, 15, 0.55);
}

.check-row:first-of-type { border-radius: 12px 12px 0 0; }
.check-row:last-of-type { border-radius: 0 0 12px 12px; }
.check-row + .check-row { border-top: 0; }
.check-row strong, .check-row small, .toggle-row strong, .toggle-row small { display: block; }
.check-row small, .toggle-row small { margin-top: 4px; color: var(--muted); font-size: 0.75rem; font-weight: 500; }
.check-row input, .toggle-row input { width: 18px; height: 18px; min-height: 0; margin: 2px 0 0; padding: 0; accent-color: var(--accent); }

.automation-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid var(--line);
}

.automation-options > label:first-child { display: grid; gap: 8px; color: var(--muted); font-size: 0.78rem; }
.automation-options select { width: 100%; }
.toggle-row { min-height: 72px; border-radius: 12px; }

.automation-actions { display: flex; gap: 10px; padding: 0 24px 22px; }
.automation-config > .feedback { border-top: 1px solid var(--line); }
.count-pill.is-ready { color: var(--success); border-color: rgba(98, 212, 155, 0.34); }

.automation-result { padding: 22px 24px; }
.automation-result.empty-state { color: var(--muted); line-height: 1.7; }
.automation-result-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.automation-result-heading span { color: var(--accent); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.automation-result-heading code { color: var(--muted); font-size: 0.7rem; }
.automation-result p { margin: 20px 0; color: #cbd7d3; line-height: 1.65; }
.automation-result ol { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.automation-result li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: #091311; }
.automation-result li small { grid-column: 2; overflow-wrap: anywhere; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.68rem; }
.automation-action-status { align-self: start; padding: 3px 6px; border-radius: 999px; color: var(--warning); background: rgba(255, 193, 102, 0.11); font-size: 0.62rem; text-transform: uppercase; }
.automation-action-status.completed { color: var(--success); background: rgba(98, 212, 155, 0.11); }
.automation-action-status.failed { color: #ff8c7a; background: rgba(255, 90, 54, 0.12); }

.drawer-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(3px);
}

.drawer {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  width: min(620px, 100%);
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: #091311;
  box-shadow: -30px 0 80px rgba(0, 0, 0, 0.46);
  transform: translateX(102%);
  transition: transform 220ms ease;
}

.drawer.is-open { transform: translateX(0); }
.drawer-header { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 24px; border-bottom: 1px solid var(--line); background: rgba(9, 19, 17, 0.94); backdrop-filter: blur(14px); }
.drawer-header > div { min-width: 0; }
.drawer-header h2 { min-width: 0; max-width: 470px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-header .icon-button { flex: 0 0 auto; }
.drawer-content { padding: 0 24px 40px; }
.detail-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 4px; }
.muted { color: var(--muted); }

.form-stack fieldset { display: grid; gap: 17px; margin: 20px 0 0; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.form-stack legend { padding: 0 8px; color: var(--text); font-weight: 820; }
.form-stack label { display: grid; gap: 8px; color: #cbd7d3; font-size: 0.82rem; font-weight: 720; }
.field-count, .field-hint { margin-left: auto; color: var(--muted); font-weight: 500; }
.field-note, .schedule-current { margin: 0; color: var(--muted); font-size: 0.8rem; line-height: 1.55; }

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  color: var(--text);
  background: #07100f;
}

input, select { min-height: 44px; padding: 0 12px; }
textarea { resize: vertical; min-height: 150px; padding: 12px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.confirm-dialog {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.66); backdrop-filter: blur(4px); }
.confirm-dialog form { padding: 26px; }
.confirm-dialog h2 { margin: 14px 0 8px; }
.confirm-dialog p { color: var(--muted); line-height: 1.6; }
.confirm-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 12px; color: #fff; background: #d83f3f; font-weight: 900; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.toast-region { position: fixed; z-index: 80; right: 22px; bottom: 22px; display: grid; gap: 10px; width: min(380px, calc(100% - 44px)); }
.toast { padding: 14px 16px; border: 1px solid rgba(98, 212, 155, 0.35); border-radius: 12px; color: var(--text); background: #163227; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: 180ms ease; }
.toast.error { border-color: rgba(255, 112, 94, 0.42); background: #351a17; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; align-items: center; height: auto; padding: 16px 20px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; margin: 0 0 0 auto; }
  .nav-item { width: auto; margin: 0 2px; }
  .sidebar-footer { display: none; }
  .main-content { padding-top: 30px; }
  .playlist-layout { grid-template-columns: 1fr; }
  .automation-layout { grid-template-columns: 1fr; }
  .automation-options { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .sidebar { align-items: center; padding-inline: 14px; }
  .brand small, .nav-label { display: none; }
  .sidebar nav { gap: 2px; }
  .nav-item { justify-content: center; width: 42px; height: 42px; padding: 0; }
  .topbar, .panel-heading { align-items: stretch; flex-direction: column; }
  .topbar-actions { align-items: stretch; }
  .timezone-pill { align-self: flex-start; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-card-accent { grid-column: 1 / -1; }
  .search-field input { width: 100%; }
  .table-wrap { display: none; }
  .video-cards { display: grid; gap: 1px; background: var(--line); }
  .video-card { padding: 18px 20px; background: var(--surface); }
  .video-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
  .video-card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; margin: 18px 0 0; }
  .video-card dt { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }
  .video-card dd { margin: 4px 0 0; font-size: 0.84rem; }
  .video-card .button { width: 100%; margin-top: 16px; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .playlist-item { grid-template-columns: 30px minmax(0, 1fr); }
  .playlist-item .remove-button { grid-column: 2; justify-self: start; padding: 0; }
  .automation-actions { align-items: stretch; flex-direction: column; }
  .automation-actions .button { width: 100%; }
  .drawer-content { padding-inline: 16px; }
  .drawer-header { padding: 18px 16px; }
  .form-stack fieldset { padding: 18px 15px; }
}
