@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;0,500;0,600;0,700;1,500&display=swap');

:root {
  --bg-deep: #080a0f;
  --bg-mid: #0f1219;
  --surface: rgba(22, 27, 38, 0.72);
  --surface-solid: #161b26;
  --surface-elevated: rgba(28, 34, 48, 0.85);
  --text: #f0f2f7;
  --muted: rgba(240, 242, 247, 0.62);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --accent: #5b8cff;
  --accent-dim: #3d6fd9;
  --accent-glow: rgba(91, 140, 255, 0.35);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-drawer-section: 0 2px 12px rgba(0, 0, 0, 0.22);
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-deep);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(91, 140, 255, 0.18), transparent),
    radial-gradient(ellipse 70% 50% at 100% 50%, rgba(139, 92, 246, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 0% 80%, rgba(34, 211, 238, 0.06), transparent);
  background-attachment: fixed;
}

body.drawer-open {
  overflow: hidden;
  touch-action: none;
}

/* ——— Header ——— */
.app-header {
  padding:
    max(14px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    14px
    max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  background: rgba(8, 10, 15, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-header__brand {
  flex: 1;
  min-width: 0;
}

.app-header h1 {
  font-size: clamp(1.05rem, 2.8vw, 1.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.2;
}

.app-header .sub {
  color: var(--muted);
  font-size: 0.8125rem;
  margin-top: 2px;
}

.app-header__meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.lastUpdate {
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}

.header-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  touch-action: manipulation;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.header-logout:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.header-logout:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header-logout[hidden] {
  display: none !important;
}

/* ——— Layout ——— */
.layout {
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr;
  min-height: calc(100vh - 57px);
  min-height: calc(100dvh - 57px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding:
    16px
    max(16px, env(safe-area-inset-right))
    16px
    max(16px, env(safe-area-inset-left));
  overflow: auto;
}

.content {
  padding:
    16px
    max(20px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  overflow: auto;
}

/* ——— Cards ——— */
.card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(91, 140, 255, 0.12);
  border: 1px solid rgba(91, 140, 255, 0.25);
}

.units {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

/* ——— Buttons ——— */
.btn {
  width: 100%;
  min-height: 44px;
  text-align: left;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.btn:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.btn:active {
  transform: scale(0.99);
}

.btn.active {
  border-color: rgba(91, 140, 255, 0.55);
  background: rgba(91, 140, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(91, 140, 255, 0.2);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-accent {
  color: #fff;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 20px var(--accent-glow);
  touch-action: manipulation;
}

.btn-accent:hover {
  filter: brightness(1.06);
  border-color: rgba(255, 255, 255, 0.28);
}

.btn-accent:active {
  filter: brightness(0.96);
}

.btn-reload {
  color: #1a1a1a;
  font-weight: 700;
  background: linear-gradient(180deg, #fecaca, #fca5a5);
  border: 1px solid rgba(220, 38, 38, 0.45);
  touch-action: manipulation;
}

.btn-reload:hover {
  filter: brightness(1.05);
}

.btn-reload:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

.btn-menu {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  touch-action: manipulation;
}

.btn-menu__icon {
  flex-shrink: 0;
  display: block;
}

.btn-menu:hover {
  border-color: var(--border-strong);
}

.btn-menu:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.topRow {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.topRow h2 {
  margin: 0;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.topRow .meta {
  color: var(--muted);
  font-size: 0.8125rem;
  margin-top: 4px;
}

.headingBlock {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

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

.tools button {
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  min-height: 44px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, background 0.15s;
}

.tools button:hover {
  border-color: var(--border-strong);
}

/* ——— Player ——— */
.player-wrapper {
  position: relative;
  width: min(1100px, 100%);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-top: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.player-wrapper iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #000;
  transition: filter 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.player-wrapper.loading iframe {
  filter: blur(5px) brightness(0.72);
  transform: scale(1.01);
  opacity: 0.88;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.player-wrapper.loading .loading-overlay {
  opacity: 1;
  pointer-events: auto;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.loading-text {
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  user-select: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.subtitles {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 7%;
  padding: 0 16px;
  text-align: center;
  font-size: clamp(16px, 2.2vw, 28px);
  line-height: 1.28;
  font-weight: 500;
  color: #fff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.95),
    0 2px 16px rgba(0, 0, 0, 0.85);
  pointer-events: none;
  z-index: 10;
  user-select: none;
  white-space: pre-wrap;
}

.player-wrapper:fullscreen {
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  border-radius: 0;
  border: none;
}

.player-wrapper:fullscreen .subtitles {
  font-size: clamp(18px, 3vw, 40px);
  bottom: calc(8% + env(safe-area-inset-bottom));
}

.status {
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--muted);
  word-break: break-word;
}

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

.status-error {
  color: #fecaca;
  background: var(--danger-bg);
  border: 1px solid rgba(248, 113, 113, 0.35);
  padding: 12px 14px;
  border-radius: var(--radius-md);
}

/* ——— Drawer ——— */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 60;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(88vw, 380px);
  max-width: calc(100vw - env(safe-area-inset-left));
  padding-left: env(safe-area-inset-left);
  background: var(--surface-solid);
  border-right: 1px solid var(--border-strong);
  transform: translateX(-102%);
  transition: transform 0.22s ease;
  z-index: 70;
  display: flex;
  flex-direction: column;
  box-shadow: 12px 0 40px rgba(0, 0, 0, 0.48);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding:
    max(16px, env(safe-area-inset-top))
    16px
    16px
    16px;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
}

.drawer-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.drawer-body {
  overflow: auto;
  padding:
    14px
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    14px;
  display: grid;
  gap: 14px;
}

.drawer-section {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow-drawer-section);
}

.drawer-section h3 {
  margin: 0 0 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.drawer-list {
  display: grid;
  gap: 8px;
}

.drawer-note {
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 4px 0 0;
}

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

  .sidebar {
    display: none;
  }

  .btn-menu {
    display: inline-flex;
  }

  .videosGrid {
    display: none;
  }
}

@media (max-width: 680px) {
  .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 10px;
    row-gap: 8px;
    align-items: start;
    padding:
      max(12px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      12px
      max(14px, env(safe-area-inset-left));
  }

  .app-header__brand {
    flex: unset;
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .app-header__meta {
    display: contents;
  }

  .lastUpdate {
    grid-column: 1 / -1;
    grid-row: 2;
    white-space: normal;
    font-size: 0.75rem;
    line-height: 1.35;
    max-width: 100%;
  }

  .header-logout {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: start;
    min-height: 40px;
    padding: 6px 12px;
  }

  /* Logged-out / static preview: no logout link — title uses full width */
  .app-header:not(:has(.header-logout:not([hidden]))) .app-header__brand {
    grid-column: 1 / -1;
  }

  .sidebar,
  .content {
    padding:
      12px
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .drawer-list {
    gap: 10px;
  }

  .topRow {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .headingBlock {
    width: 100%;
    justify-content: space-between;
  }

  .tools {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }

  .tools button {
    width: 100%;
    min-height: 44px;
  }

  .player-wrapper {
    width: 100%;
    border-radius: var(--radius-md);
    margin-top: 12px;
  }

  .subtitles {
    padding: 0 10px;
    bottom: calc(8% + env(safe-area-inset-bottom));
    font-size: clamp(14px, 4.2vw, 22px);
    line-height: 1.32;
  }

  .drawer {
    width: min(92vw, 380px);
  }
}

@media (min-width: 1025px) {
  .drawer,
  .drawer-backdrop {
    display: none;
  }
}

/* ——— Login page (login.php) ——— */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(24px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  box-shadow: var(--shadow-card), 0 0 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(12px);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: clamp(1.2rem, 4vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.auth-card .lead {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 0.875rem;
}

.auth-field {
  margin-bottom: 16px;
}

.auth-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.auth-field input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}

.auth-field input:focus {
  outline: none;
  border-color: rgba(91, 140, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.2);
}

.auth-submit {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  box-shadow: 0 4px 20px var(--accent-glow);
}

.auth-submit:hover {
  filter: brightness(1.06);
}

.auth-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--danger-bg);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

/* ——— Reduced motion ——— */
@media (prefers-reduced-motion: reduce) {
  .drawer,
  .drawer-backdrop {
    transition-duration: 0.01ms !important;
  }

  .loading-overlay,
  .player-wrapper iframe {
    transition-duration: 0.01ms !important;
  }

  .loading-spinner {
    animation: none;
    border-color: rgba(255, 255, 255, 0.28);
    border-top-color: rgba(255, 255, 255, 0.92);
  }

  .btn:active {
    transform: none;
  }

  .header-logout,
  .btn,
  .btn-menu,
  .drawer-close,
  .tools button,
  .auth-submit {
    transition-duration: 0.01ms !important;
  }
}
