:root {
  color-scheme: dark;
  --background: #101212;
  --surface: #181c1b;
  --surface-hover: #202623;
  --border: #2c3430;
  --text: #eef3ef;
  --muted: #a1aaa4;
  --mint: #b6f874;
  --mint-dark: #172311;
  --danger: #ffaba9;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--background); color: var(--text); }
button, input, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }
p, h1, h2, h3 { margin: 0; }
svg { display: block; width: 20px; height: 20px; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }

.topbar {
  position: sticky;
  z-index: 1;
  top: 0;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px max(22px, calc((100vw - 1370px) / 2));
  background: var(--background);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 850; font-size: 1.21rem; letter-spacing: -.06em; white-space: nowrap; }
.brand strong { color: var(--mint); }
.brand-icon { display: grid; place-items: center; width: 37px; height: 37px; background: var(--mint); color: var(--mint-dark); border-radius: 10px; }
.brand-icon svg { width: 22px; height: 22px; }
.topbar-right { display: flex; align-items: center; gap: 4px; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 14px;
  font-weight: 670;
  font-size: .9rem;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.button:disabled, .icon-button:disabled { opacity: .55; cursor: wait; }
.button-primary { background: var(--mint); color: var(--mint-dark); }
.button-primary:hover:not(:disabled) { background: #c8ff95; }
.button-outline { border-color: var(--border); background: transparent; color: var(--text); }
.button-outline:hover:not(:disabled) { border-color: #515d54; background: var(--surface-hover); }
.button-quiet { background: transparent; color: var(--muted); }
.button-quiet:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.button-danger { background: #84322f; color: #fff; }
.button-danger:hover:not(:disabled) { background: #a63b37; }
.button-remove-source { color: var(--danger); }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 1.55rem; line-height: 1; cursor: pointer; }
.icon-button:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.auth-region { display: grid; place-items: start center; padding: clamp(56px, 14vh, 150px) 20px 48px; }
.auth-card { width: min(100%, 450px); padding: clamp(22px, 6vw, 38px); border: 1px solid var(--border); border-radius: 18px; background: var(--surface); }
.auth-card h1 { margin: 7px 0 10px; font-size: clamp(1.65rem, 5vw, 2.15rem); letter-spacing: -.055em; }
.auth-card > button { margin-top: 20px; }
.auth-form { display: grid; gap: 16px; margin-top: 22px; }
.muted, .field-hint { color: var(--muted); line-height: 1.5; }
.eyebrow { font-size: .78rem; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.auth-card .eyebrow { color: var(--mint); }

.workspace { display: grid; grid-template-columns: 225px minmax(0, 1fr); min-height: calc(100vh - 71px); max-width: 1414px; margin: 0 auto; }
.sidebar { position: sticky; top: 71px; display: flex; flex-direction: column; height: calc(100dvh - 71px); min-height: 360px; padding: 28px 15px 18px 22px; border-right: 1px solid var(--border); }
.sidebar > .eyebrow { margin: 0 11px 15px; }
.admin-nav { display: grid; gap: 6px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 12px; min-height: 46px; border: 1px solid transparent; border-radius: 9px; background: none; text-align: start; color: var(--muted); font-weight: 650; cursor: pointer; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.is-active { border-color: #33472c; background: #222f20; color: var(--mint); }
.sidebar-account { display: flex; align-items: center; gap: 10px; min-width: 0; margin-top: auto; padding: 15px 3px 0; border-top: 1px solid var(--border); }
.sidebar-account > span:last-child { min-width: 0; }
.account-icon { display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 50%; color: var(--muted); }
.sidebar-account strong, .sidebar-account small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-account small { margin-top: 1px; color: var(--muted); }
.workspace-content { padding: clamp(24px, 4vw, 50px); min-width: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 25px; }
.section-heading h1 { margin: 0 0 5px; font-size: clamp(1.75rem, 4vw, 2.55rem); letter-spacing: -.05em; line-height: 1.12; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 21px; }
.metric { min-width: 0; display: grid; gap: 7px; padding: clamp(10px, 2.6vw, 22px); border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
.metric span, .metric dt { color: var(--muted); line-height: 1.3; font-size: .9rem; }
.metric strong, .metric dd { margin: 0; font-size: clamp(1.4rem, 4vw, 2.2rem); line-height: 1; letter-spacing: -.06em; font-weight: 700; }
.metric:nth-child(2) :is(strong, dd) { color: var(--mint); }
.visits-metrics { margin-top: 0; }
.visits-metrics dd { overflow-wrap: anywhere; }
.panel { border: 1px solid var(--border); border-radius: 13px; background: var(--surface); overflow: hidden; }
.panel-heading { display: flex; gap: 12px; justify-content: space-between; align-items: center; padding: 16px 19px; }
.panel-heading h2 { font-size: 1.1rem; }
.search { display: flex; gap: 8px; align-items: center; min-width: 0; max-width: 100%; padding-left: 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--background); color: var(--muted); }
.search:focus-within { border-color: var(--mint); }
.search svg { height: 17px; width: 17px; }
.search input { min-width: 0; width: min(190px, 100%); padding: 8px 10px 8px 0; border: 0; outline: none; background: transparent; font-size: .9rem; color: var(--text); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .92rem; }
th, td { border-top: 1px solid var(--border); padding: 11px 18px; }
th { white-space: nowrap; color: var(--muted); font-weight: 600; background: #141816; }
td:last-child, th:last-child { width: 1%; white-space: nowrap; text-align: right; }
td:nth-child(3) { white-space: nowrap; }
td .button { min-height: 36px; padding: 5px 9px; }
td .button[data-delete] { color: var(--danger); }
.accounts-table tbody th { overflow-wrap: anywhere; white-space: normal; color: var(--text); background: transparent; }
.accounts-table :is(td, th):last-child { width: 40%; }
.accounts-table td:last-child { white-space: normal; }
.accounts-table .button { white-space: normal; text-align: right; }
#users-table .button:disabled { cursor: default; }
.film-cell { display: flex; align-items: center; gap: 10px; min-width: 135px; }
.film-thumb { width: 38px; height: 50px; object-fit: cover; background: #262e2a; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; flex: none; }
span.film-thumb { display: grid; place-items: center; }
.film-cell small { display: block; margin-top: 3px; color: var(--muted); }
.state-pill { display: inline-flex; border-radius: 999px; gap: 5px; align-items: center; padding: 4px 9px; background: #29302c; color: #c7cec9; font-size: .8rem; font-weight: 650; }
.state-pill.active { background: #293b25; color: var(--mint); }
.empty { padding: 32px 18px; color: var(--muted); text-align: center; border-top: 1px solid var(--border); }

.dialog { max-width: min(470px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); width: 100%; padding: 0; border: 1px solid #3c4640; border-radius: 16px; background: var(--surface); color: var(--text); overflow: hidden; }
.dialog-movie { max-width: min(760px, calc(100vw - 24px)); }
.dialog::backdrop { background: #080a09ce; }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 28px); }
.dialog-heading, .dialog-footer { display: flex; align-items: center; gap: 8px; padding: 14px clamp(14px, 4vw, 24px); flex-shrink: 0; }
.dialog-heading { justify-content: space-between; border-bottom: 1px solid var(--border); }
.dialog-heading h2 { font-size: 1.3rem; letter-spacing: -.025em; }
.dialog-footer { justify-content: flex-end; border-top: 1px solid var(--border); }
.dialog-content { padding: 20px clamp(14px, 4vw, 24px); overflow: auto; }
.dialog-content > p { line-height: 1.55; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.image-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin-top: 10px; }
.image-picker { display: grid; align-content: start; gap: 8px; min-width: 0; }
.image-picker .button { justify-self: start; max-width: 100%; white-space: normal; }
.full-width { grid-column: 1 / -1; }
.field { display: grid; align-content: start; min-width: 0; gap: 6px; font-size: .9rem; font-weight: 620; }
.field input, .field textarea, .field select { min-width: 0; width: 100%; padding: 10px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--background); color: var(--text); font-weight: 450; }
.field input::placeholder, .field textarea::placeholder, .search input::placeholder { color: #85908a; }
.field textarea { resize: vertical; min-height: 92px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 1px solid var(--mint); outline-offset: 0; }
.field.user-role-editor { display: flex; justify-content: end; align-items: center; flex-wrap: wrap; }
.user-role-editor select { width: auto; max-width: 100%; }
.required { color: var(--mint); }
.form-group { min-width: 0; margin: 18px 0 0; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.form-group legend, .form-group h3 { font-weight: 700; font-size: 1rem; }
.form-group legend { padding: 0 5px; }
.genre-options, .toggle-options { display: flex; flex-wrap: wrap; gap: 7px 14px; }
.genre-options label, .toggle-options label { display: inline-flex; align-items: start; gap: 6px; padding: 3px; font-size: .9rem; cursor: pointer; }
.genre-options input, .toggle-options input { margin: 3px 0 0; accent-color: var(--mint); }
.toggle-options { margin-top: 16px; }
.source-section-heading { display: flex; justify-content: space-between; align-items: start; gap: 9px; }
.source-section-heading p, .field-hint { font-size: .85rem; }
.source-section-heading p { margin-top: 4px; }
.source-card { background: #141816; border: 1px solid var(--border); border-radius: 9px; padding: 11px; margin-top: 12px; display: grid; gap: 10px; }
.source-heading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: 9px; }
.facebook-source-hint, .source-link-hint { margin-top: 5px; }
[data-saved-local-path] { overflow-wrap: anywhere; }
.media-picker { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 9px; }
.form-error { margin: 12px 0; padding: 10px 12px; border: 1px solid #794240; border-radius: 8px; color: var(--danger); background: #2f1d1d; font-size: .9rem; }
.auth-form .form-error { margin: 0; }
.notice { position: fixed; inset: auto 18px 18px auto; z-index: 2; max-width: calc(100% - 36px); padding: 12px 16px; border: 1px solid #485e3b; border-radius: 10px; background: #293b25; box-shadow: 0 5px 30px #0005; color: #e4ffcf; }

@media (max-width: 820px) {
  .workspace { display: block; }
  .sidebar { position: static; display: block; height: auto; min-height: 0; padding: 12px 20px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar > .eyebrow, .sidebar-account { display: none; }
  .admin-nav { display: flex; flex-wrap: wrap; }
  .nav-item { min-height: 40px; padding: 8px 12px; }
  .workspace-content { padding-inline: 20px; }
}

@media (max-width: 520px) {
  .topbar { padding-inline: 12px; }
  .topbar .button { padding-inline: 7px; font-size: .83rem; }
  .brand { gap: 5px; font-size: 1rem; }
  .brand-icon { width: 30px; height: 30px; }
  .brand-icon svg { width: 18px; height: 18px; }
  .workspace-content, .sidebar { padding-inline: 12px; }
  .section-heading { align-items: start; gap: 7px; }
  .section-heading p { font-size: .92rem; }
  .section-heading .button { padding-inline: 9px; }
  .section-heading .button svg { display: none; }
  .metrics { gap: 7px; }
  .panel-heading { align-items: start; flex-direction: column; padding-inline: 12px; }
  .search, .search input { width: 100%; }
  th, td { padding-inline: 10px; }
  .accounts-table th { white-space: normal; }
  .source-heading { grid-template-columns: minmax(0, 1fr); }
  .image-grid { grid-template-columns: minmax(0, 1fr); }
  .button-remove-source { justify-self: end; }
}

@media (max-width: 360px) {
  .topbar-link { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
