:root {
  color-scheme: dark;
  --bg: #0b0b0d;
  --panel: #141419;
  --panel-2: #1b1b22;
  --text: #f4f4f6;
  --muted: #a8a8b3;
  --line: #2a2a34;
  --accent: #e7ff38;
  --accent-2: #ff4d8d;
  --danger: #ff7474;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(231, 255, 56, 0.11), transparent 30rem),
    radial-gradient(circle at 90% 10%, rgba(255, 77, 141, 0.12), transparent 28rem),
    var(--bg);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(420px, 100%);
  padding: 1.5rem;
  background: rgba(20, 20, 25, 0.95);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: -0.05em;
  text-transform: uppercase;
}

.login-submit {
  width: 100%;
}

.login-error {
  min-height: 1.25rem;
  margin-bottom: 0;
  color: var(--danger);
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  background: rgba(11, 11, 13, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 3.2rem);
  letter-spacing: -0.06em;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.stats {
  min-width: max-content;
  padding: 0.65rem 0.9rem;
  color: var(--accent);
  background: rgba(231, 255, 56, 0.08);
  border: 1px solid rgba(231, 255, 56, 0.28);
  border-radius: 999px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.account-name {
  color: var(--muted);
  font-size: 0.9rem;
}

.account-button,
.icon-button,
.primary-button,
.danger-button,
.delete-button {
  min-height: 2.4rem;
  padding: 0 0.8rem;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  cursor: pointer;
}

.primary-button {
  color: #0b0b0d;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 800;
}

.danger-button {
  color: var(--danger);
  border-color: rgba(255, 116, 116, 0.4);
}

.delete-button {
  color: #0b0b0d;
  background: var(--danger);
  border-color: var(--danger);
  font-weight: 800;
}

.admin-dialog {
  width: min(680px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.25rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}

.admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

.dialog-header,
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.audit-dialog {
  width: min(980px, calc(100% - 2rem));
}

.audit-filters {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(190px, 1fr) 130px auto;
  align-items: end;
  gap: 0.7rem;
  margin-top: 1rem;
}

.audit-filters .field {
  margin: 0;
}

.audit-status {
  min-height: 1.25rem;
}

.audit-list {
  display: grid;
  gap: 0.5rem;
  max-height: 58vh;
  overflow: auto;
}

.audit-row {
  display: grid;
  grid-template-columns: 170px minmax(150px, 0.8fr) minmax(180px, 1fr);
  gap: 0.35rem 0.8rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
}

.audit-row time,
.audit-row span,
.audit-row small {
  color: var(--muted);
}

.audit-row small {
  grid-column: 2 / -1;
}

.user-row > div {
  display: grid;
  gap: 0.2rem;
}

.user-row > .user-actions {
  display: flex;
  grid-auto-flow: column;
  gap: 0.5rem;
}

.user-row small {
  color: var(--muted);
}

.dialog-header h2 {
  margin: 0;
}

.icon-button {
  width: 2.5rem;
  padding: 0;
  font-size: 1.5rem;
}

.user-form {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--panel-2);
  border-radius: 1rem;
}

.form-message {
  min-height: 1.25rem;
  margin: 0.7rem 0 0;
  color: var(--accent);
}

.user-list {
  display: grid;
  gap: 0.6rem;
  margin-top: 1rem;
}

.user-row {
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1.25rem;
  padding: 1.25rem;
}

.filters,
.player-panel,
.card {
  background: rgba(20, 20, 25, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.filters {
  position: sticky;
  top: 6.4rem;
  align-self: start;
  max-height: calc(100vh - 7.8rem);
  overflow: auto;
  padding: 1rem;
  border-radius: 1.25rem;
}

.field {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}

.field span,
.filter-section .section-title {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0 0.8rem;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(231, 255, 56, 0.7);
  box-shadow: 0 0 0 3px rgba(231, 255, 56, 0.13);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.5rem 0 1rem;
  color: var(--muted);
}

.check input {
  width: 1.1rem;
  min-height: 1.1rem;
  accent-color: var(--accent);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.7rem;
}

.section-title button,
.reset,
.open-file {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
}

.section-title button {
  padding: 0.25rem 0.55rem;
  color: var(--muted);
}

.tags,
.player-tags,
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tag {
  padding: 0.38rem 0.55rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.tag.active {
  color: #0b0b0d;
  background: var(--accent);
  border-color: var(--accent);
}

.tag small {
  opacity: 0.72;
}

.reset {
  width: 100%;
  margin-top: 1rem;
  padding: 0.75rem 0.9rem;
}

.content {
  min-width: 0;
}

.player-panel {
  margin-bottom: 1rem;
  padding: 1rem;
  border-radius: 1.25rem;
}

.player-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.player-header h2 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 2rem);
}

.open-file {
  min-width: max-content;
  padding: 0.6rem 0.8rem;
}

video {
  width: 100%;
  max-height: 72vh;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 1rem;
}

.player-tags {
  margin-top: 0.8rem;
}

.resultbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.25rem 0 1rem;
  color: var(--muted);
}

kbd {
  padding: 0.12rem 0.35rem;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.35rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 0.9rem;
}

.card {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  border-radius: 1.1rem;
}

.card h3 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.25;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.pill {
  padding: 0.25rem 0.45rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
}

.play,
.favorite {
  min-height: 2.4rem;
  padding: 0 0.75rem;
  border: 0;
  border-radius: 0.75rem;
  cursor: pointer;
  font-weight: 800;
}

.play {
  flex: 1;
  color: #0b0b0d;
  background: var(--accent);
}

.favorite {
  width: 2.6rem;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.favorite.active {
  color: #0b0b0d;
  background: var(--accent-2);
}

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

.empty {
  padding: 2rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--line);
  border-radius: 1rem;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .filters {
    position: static;
    max-height: none;
  }

  .topbar,
  .topbar-actions,
  .resultbar,
  .player-header {
    align-items: stretch;
    flex-direction: column;
  }

  .stats,
  .open-file {
    width: fit-content;
  }

  .audit-filters,
  .audit-row {
    grid-template-columns: 1fr;
  }

  .audit-row small {
    grid-column: auto;
  }
}

[hidden] { display: none !important; }
input[readonly] { color: var(--muted); border-style: dashed; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.invite-note { font-size: 0.85rem; line-height: 1.5; }
.login-card a { color: var(--accent); }
#inviteLinkPanel { margin-top: 1rem; }
.user-row > div { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .user-row { align-items: stretch; flex-direction: column; }
  .user-actions { flex-wrap: wrap; }
}

#adminDialog {
  height: min(760px, calc(100dvh - 2rem));
  overflow: hidden;
}
#adminDialog[open] { display: flex; flex-direction: column; }
.access-header { flex: 0 0 auto; }
.access-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
  margin-top: 1rem;
  padding: 0.25rem;
  background: var(--bg);
  border-radius: 0.8rem;
}
.access-tabs button {
  min-width: 0;
  min-height: 44px;
  padding: 0.5rem 0.25rem;
  border: 0;
  border-radius: 0.6rem;
  color: var(--muted);
  background: transparent;
  font-size: 0.85rem;
  cursor: pointer;
}
.access-tabs button[aria-selected="true"] { color: var(--text); background: var(--panel-2); }
.access-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.access-panel { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; padding-top: 0.8rem; }
.access-panel .user-form, .access-panel .user-list { margin-top: 0; }
.access-panel .user-form > .primary-button { min-height: 44px; height: auto; padding: 0.7rem; }
body:has(dialog[open]) { overflow: hidden; }
@media (max-width: 600px) {
  #adminDialog {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
  }
  #adminDialog .dialog-header h2 { font-size: 1.35rem; }
  #adminDialog .icon-button { width: 44px; min-height: 44px; }
  .access-panel .user-form { padding: 0.4rem 0; background: transparent; }
  .access-panel input, .access-panel select { font-size: 16px; }
  .access-panel .primary-button, .access-panel .danger-button, .access-panel .delete-button { min-height: 44px; }
  .access-panel .user-form > .primary-button { width: 100%; }
  .access-tabs button { font-size: 0.8rem; }
}

.user-row.user-card { flex-direction: column; align-items: stretch; }
.user-row > .user-summary { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.user-summary > div:first-child { display: grid; gap: 0.25rem; min-width: 0; }
.user-summary > .user-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.access-duration-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 0.6rem; }
.access-duration-form .field { margin: 0; }
.access-duration-form button { min-height: 44px; }
.access-duration-message { grid-column: 1 / -1; margin: 0; }
@media (max-width: 600px) {
  .user-row > .user-summary { flex-direction: column; }
  .access-duration-form { grid-template-columns: 1fr; }
  .access-duration-form button { width: 100%; }
}
