:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #edf2f5;
  --ink: #172026;
  --muted: #60707d;
  --line: #d8e0e6;
  --accent: #0f766e;
  --accent-strong: #0b5d57;
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #166534;
  --focus: #4f46e5;
  --shadow: 0 10px 30px rgba(23, 32, 38, 0.08);
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --pill-bg: #f8fafb;
  --pill-ink: #40505b;
  --requester-bg: #f8fafb;
  --poster-bg: #dce5ea;
  --poster-fallback: #52616d;
  --brand-mark-bg: var(--ink);
  --brand-mark-ink: #ffffff;
  --status-pending-bg: #fff7e6;
  --status-pending-line: #f4cf82;
  --status-pending-ink: var(--warning);
  --status-approved-bg: #e9fbf8;
  --status-approved-line: #9bd7d1;
  --status-approved-ink: var(--accent-strong);
  --status-available-bg: #edf8f0;
  --status-available-line: #a7d7b6;
  --status-available-ink: var(--ok);
  --status-denied-bg: #fff1ef;
  --status-denied-line: #f1aaa3;
  --status-denied-ink: var(--danger);
  --danger-soft-bg: #fff1ef;
  --danger-soft-line: #ffd1cc;
  --danger-soft-ink: var(--danger);
  --tab-active-bg: var(--ink);
  --tab-active-ink: #ffffff;
  --nav-bg: rgba(255, 255, 255, 0.94);
  --nav-active-bg: #dff4f1;
  --nav-active-ink: #0b5d57;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1418;
  --surface: #182026;
  --surface-2: #202a33;
  --ink: #edf3f7;
  --muted: #9fb0bb;
  --line: #31414d;
  --accent: #2ca69c;
  --accent-strong: #49c1b6;
  --danger: #f26b5c;
  --warning: #f1b561;
  --ok: #65c27a;
  --focus: #8b93ff;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --topbar-bg: rgba(16, 23, 29, 0.92);
  --pill-bg: #1d2730;
  --pill-ink: #d4e0e7;
  --requester-bg: #1d2730;
  --poster-bg: #24313a;
  --poster-fallback: #a1b2be;
  --brand-mark-bg: #edf3f7;
  --brand-mark-ink: #10171d;
  --status-pending-bg: rgba(241, 181, 97, 0.12);
  --status-pending-line: rgba(241, 181, 97, 0.45);
  --status-pending-ink: #f6c46f;
  --status-approved-bg: rgba(73, 193, 182, 0.12);
  --status-approved-line: rgba(73, 193, 182, 0.35);
  --status-approved-ink: #7bd6ca;
  --status-available-bg: rgba(101, 194, 122, 0.12);
  --status-available-line: rgba(101, 194, 122, 0.35);
  --status-available-ink: #8fe09f;
  --status-denied-bg: rgba(242, 107, 92, 0.12);
  --status-denied-line: rgba(242, 107, 92, 0.35);
  --status-denied-ink: #ff9b92;
  --danger-soft-bg: rgba(242, 107, 92, 0.12);
  --danger-soft-line: rgba(242, 107, 92, 0.35);
  --danger-soft-ink: #ff9b92;
  --tab-active-bg: var(--surface);
  --tab-active-ink: var(--ink);
  --nav-bg: rgba(24, 32, 38, 0.94);
  --nav-active-bg: rgba(73, 193, 182, 0.16);
  --nav-active-ink: #9ee3dc;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--line);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(79, 70, 229, 0.25);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-strong);
}

button.ghost {
  background: transparent;
  border-color: var(--line);
}

button.danger {
  background: var(--danger-soft-bg);
  border-color: var(--danger-soft-line);
  color: var(--danger-soft-ink);
}

button.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

a {
  color: var(--accent-strong);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(100%, 460px);
}

.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.setup-panel {
  width: min(100vw - 48px, 640px);
}

.stack {
  display: grid;
  gap: 16px;
}

.option-stack {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin: 0 0 22px;
}

.theme-toggle {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  white-space: nowrap;
}

.theme-toggle input {
  width: 18px;
  min-height: 18px;
}

.check-row {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.interval-row {
  display: grid;
  grid-template-columns: minmax(90px, 140px) minmax(120px, 1fr);
  gap: 10px;
}

.interval-row.disabled {
  opacity: 0.55;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 24px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  text-decoration: none;
}

.brand-lockup.compact {
  margin: 0;
  font-size: 18px;
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--brand-mark-bg);
  color: var(--brand-mark-ink);
  font-size: 18px;
}

.panel-head .brand-lockup {
  margin: 0;
}

.form-message,
.empty,
.hint {
  margin: 0;
  color: var(--muted);
}

.form-message.error,
.toast.error {
  color: var(--danger);
}

.form-message.success,
.toast.success {
  color: var(--ok);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  padding: 12px 20px;
  backdrop-filter: blur(12px);
}

.account-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.account-bar .theme-toggle {
  margin-right: 2px;
}

#accountName {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 22px;
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 22px 20px 36px;
}

.side-nav {
  position: sticky;
  top: 86px;
  align-self: start;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--nav-bg);
  box-shadow: var(--shadow);
}

.nav-button {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  border-color: transparent;
  text-align: left;
  font-weight: 700;
}

.nav-button.active {
  background: var(--nav-active-bg);
  border-color: var(--line);
  color: var(--nav-active-ink);
  box-shadow: 0 3px 12px rgba(23, 32, 38, 0.05);
}

.workspace {
  min-width: 0;
}

.toast {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 18px;
}

.page-title {
  margin: 0;
  font-size: 25px;
  line-height: 1.15;
}

.page-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.backup-toolbar {
  margin-bottom: 12px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 150px auto;
  gap: 10px;
  margin: 0 0 18px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.media-card,
.panel,
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.media-card {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 12px;
  min-height: 154px;
  padding: 10px;
}

.poster {
  width: 82px;
  height: 123px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--poster-bg);
}

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

.poster-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: var(--poster-fallback);
  font-size: 12px;
  text-align: center;
}

.media-body {
  display: grid;
  min-width: 0;
  gap: 7px;
  align-content: start;
}

.media-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--pill-bg);
  color: var(--pill-ink);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.pill.pending {
  border-color: var(--status-pending-line);
  background: var(--status-pending-bg);
  color: var(--status-pending-ink);
}

.pill.approved {
  border-color: var(--status-approved-line);
  background: var(--status-approved-bg);
  color: var(--status-approved-ink);
}

.pill.available {
  border-color: var(--status-available-line);
  background: var(--status-available-bg);
  color: var(--status-available-ink);
}

.pill.denied {
  border-color: var(--status-denied-line);
  background: var(--status-denied-bg);
  color: var(--status-denied-ink);
}

.overview {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: end;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.title-cell {
  display: grid;
  gap: 3px;
}

.title-cell strong {
  line-height: 1.25;
}

.requesters-popover {
  display: inline-block;
  max-width: 100%;
}

.requesters-popover > summary {
  list-style: none;
}

.requesters-popover > summary::-webkit-details-marker {
  display: none;
}

.requesters-popover > summary.pill {
  cursor: pointer;
  user-select: none;
}

.requesters-popover[open] > summary.pill {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.requester-list {
  display: none;
  gap: 6px;
  margin-top: -1px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 0 8px 8px 8px;
  background: var(--requester-bg);
  box-shadow: var(--shadow);
}

.requesters-popover[open] .requester-list {
  display: grid;
}

.requester-name {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  word-break: break-word;
}

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

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tab-button {
  border-color: transparent;
  font-weight: 800;
}

.tab-button.active {
  background: var(--tab-active-bg);
  color: var(--tab-active-ink);
}

.panel {
  padding: 16px;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.admin-form {
  display: grid;
  gap: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.update-panel {
  margin-bottom: 12px;
}

.update-folder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.update-folder > div {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.label-text {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

code {
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
}

.status-select {
  min-width: 136px;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    padding: 12px 14px;
  }

  .account-bar {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px 14px 92px;
  }

  .side-nav {
    position: fixed;
    right: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    top: auto;
    border-radius: 8px;
    padding: 7px;
    backdrop-filter: blur(14px);
  }

  .nav-button {
    justify-content: center;
    min-height: 44px;
    border-radius: 7px;
    text-align: center;
  }

  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 7px;
    scroll-snap-type: x proximity;
  }

  .tab-button {
    flex: 0 0 auto;
    min-height: 38px;
    scroll-snap-align: start;
  }

  .search-form,
  .panel-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table {
    border-collapse: separate;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  tr:last-child {
    margin-bottom: 0;
  }

  td {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    border-bottom: 1px solid var(--line);
    padding: 11px 12px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
  }

  td:last-child {
    border-bottom: 0;
  }

  td[data-label="Actions"] .actions-row {
    justify-content: flex-start;
  }

  td[data-label="Actions"] button {
    flex: 1 1 112px;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 14px;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .auth-page {
    padding: 14px;
  }

  .auth-panel {
    padding: 20px;
  }

  .setup-panel {
    width: 100%;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .brand-lockup {
    font-size: 20px;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar {
    flex-direction: column;
    gap: 10px;
    min-height: 0;
  }

  .account-bar {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  #accountName {
    max-width: 150px;
  }

  .page-head {
    display: grid;
    align-items: start;
    gap: 8px;
    margin-bottom: 12px;
  }

  .page-title {
    font-size: 22px;
  }

  .search-form {
    gap: 8px;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }

  .media-card {
    grid-template-columns: 78px minmax(0, 1fr);
    min-height: 0;
    padding: 12px;
  }

  .poster {
    width: 78px;
    height: 117px;
  }

  .side-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .nav-button {
    min-height: 44px;
    padding: 0 8px;
    font-size: 13px;
  }

  .update-folder {
    align-items: stretch;
    flex-direction: column;
  }

  .actions-row {
    width: 100%;
  }

  .actions-row button {
    flex: 1 1 auto;
  }
}
