:root {
  --bg: #f1f5f9;
  --surface: #fff;
  --header-bg: #182958;
  --text: #0f172a;
  --muted: #475569;
  --primary: #1d4ed8;
  --border: #a5b1bd;
  --danger: #b91c1c;
  --success: #166534;
  --badge-bg: #dbeafe;
  --badge-text: #1e40af;
  --active-bg: #eff6ff;
  --header-height: 74px;
  --header-height-compact: 54px;
  --header-offset: 74px;
  --border-disabled: #cbd5e1;
}

body.theme-dark {
  --bg: #020617;
  --surface: #0f172a;
  --header-bg: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #60a5fa;
  --border: #386182;
  --danger: #fca5a5;
  --success: #86efac;
  --badge-bg: #1e293b;
  --badge-text: #bfdbfe;
  --active-bg: #172554;
  --border-disabled: #020617;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial;
  transition: background-color 0.2s ease, color 0.2s ease;
  padding-top: var(--header-offset);
  display: flex;
  flex-direction: column;
}

main.container {
  flex: 1 0 auto;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

.container {
  width: min(100%, 1160px);
  padding-inline: clamp(0.75rem, 2.2vw, 1.15rem);
}

.header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 80;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  transition: transform 0.2s ease, min-height 0.2s ease, box-shadow 0.2s ease;
  min-height: var(--header-height);
}

.header .container {
  display: grid;
  /* Symmetric side tracks keep the center column truly centered. */
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
}

.header-center {
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
  min-width: 0;
  max-width: 100%;
}

.header-home-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  flex: 0 0 auto;
  background: rgba(15, 23, 42, 0.22);
  color: #e2e8f0;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.header-home-btn:hover {
  text-decoration: none;
  background: rgba(148, 163, 184, 0.26);
  border-color: rgba(226, 232, 240, 0.42);
  transform: translateY(-1px);
}

.header-home-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header-row {
  box-sizing: border-box;
  gap: 0.8rem;
  min-height: var(--header-height);
  transition: min-height 0.2s ease;
}

.header-compact {
  min-height: var(--header-height-compact);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.1);
}

.header-compact .header-row {
  min-height: var(--header-height-compact);
}

.header-hidden {
  transform: translateY(-100%);
}

.header-home-link {
  color: #e2e8f0;
  font-weight: 700;
  text-align: center;
  max-width: min(62vw, 760px);
  line-height: 1.25;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-left,
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

.header-left {
  justify-self: start;
}

.header-actions {
  justify-self: end;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.95rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  justify-content: stretch;
}

.grid.single-item {
  grid-template-columns: minmax(240px, 420px);
  justify-content: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.card-content {
  padding: 0.8rem;
}

.card-content h2 {
  margin: 0 0 0.6rem;
  font-family: Arial;
}

.card-content p {
  margin: 0;
  color: var(--muted);
}

.card-link {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-link:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
}

.thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

.badge {
  background: var(--badge-bg);
  color: var(--badge-text);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
}

.badge.active {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.status-badge-success {
  background: #dcfce7;
  color: #166534;
}

.status-badge-muted {
  background: #e2e8f0;
  color: #334155;
}

body.theme-dark .status-badge-success {
  background: #14532d;
  color: #bbf7d0;
}

body.theme-dark .status-badge-muted {
  background: #1e293b;
  color: #cbd5e1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.panel-list {
  order: 1;
}

.panel-video {
  order: 2;
}

.layout>* {
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.video-link {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 0.7rem;
  align-items: center;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.6rem;
  color: inherit;
  text-decoration: none;
  min-height: 66px;
}

.video-link:hover {
  text-decoration: none;
  background: var(--active-bg);
}

.video-link.active {
  border-color: var(--primary);
  background: var(--active-bg);
}

.video-link-thumb {
  width: 88px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.video-link-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
  font-size: 0.94rem;
  min-width: 0;
}

.video-list-scroll {
  max-height: min(66vh, 560px);
  overflow-y: auto;
  padding-right: 0.2rem;
  scrollbar-width: thin;
}

.video-list-scroll::-webkit-scrollbar {
  width: 8px;
}

.video-list-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.video-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  margin-bottom: 1rem;
}

.video-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.video-meta {
  margin-top: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.9rem;
}

.video-meta-head {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.video-meta-chip {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--active-bg);
  padding: 0.6rem 0.7rem;
  display: grid;
  gap: 0.25rem;
}

.video-meta-chip-accent {
  border-color: var(--primary);
}

.video-meta-chip-label {
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  color: var(--muted);
  text-transform: uppercase;
}

.video-meta-chip-value {
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.2;
}

.video-meta-note {
  margin-top: 0.75rem;
  padding-top: 0.72rem;
  border-top: 1px dashed var(--border);
}

.video-meta-note h3 {
  margin: 0 0 0.45rem;
  font-size: 0.86rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.video-meta-description {
  white-space: pre-wrap;
  margin: 0;
  color: var(--text);
  line-height: 1.55;
  font-size: 0.96rem;
}

/* JavaScript'in kullanacağı animasyonlu kapsayıcı */
.video-meta-description-wrapper {
  --collapsed-height: 1.55em;
  /* Sadece 1 satır (line-height kadar) gösterir */
  max-height: var(--collapsed-height);
  overflow: hidden;
  transition: max-height 0.35s ease-in-out;
  position: relative;
}

/* Kapalıyken yazının altına doğru flu bir geçiş (fade out) ekler. Şık durur. */
[data-description-panel].is-collapsed .video-meta-description-wrapper::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1.2em;
  background: linear-gradient(transparent, var(--surface));
  pointer-events: none;
}

/* Devamını Oku butonu tasarımı */
.video-description-btn {
  background: transparent;
  color: var(--primary);
  border: none;
  padding: 0.5rem 0 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-block;
}

.video-description-btn:hover {
  text-decoration: underline;
  filter: none;
}

/* JS çalıştığında buton içindeki metinlerin değiştirilmesi */
[data-description-panel].is-collapsed .btn-text-collapse {
  display: none;
}

[data-description-panel].is-expanded .btn-text-expand {
  display: none;
}

.video-description-toggle {
  margin-top: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.65rem;
}

.video-description-toggle>summary {
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--muted);
  list-style: none;
}

.video-description-toggle>summary::-webkit-details-marker {
  display: none;
}

.video-description-toggle>summary::after {
  content: " +";
}

.video-description-toggle[open]>summary::after {
  content: " -";
}

.alert {
  padding: 0.75rem;
  border-radius: 10px;
  margin-bottom: 0.8rem;
}

.alert.error {
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.alert.success {
  color: var(--success);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

input[type='text'],
input[type='number'],
.list-select,
input[type='password'],
textarea {
  width: 100%;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  resize: vertical;
}

button,
.theme-toggle {
  background: var(--muted);
  color: yellow;
  border: 0;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  cursor: pointer;
}

button:hover,
.theme-toggle:hover {
  filter: brightness(1.05);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}

.button-secondary {
  background: #475569;
}

.button-danger {
  background: #b91c1c;
}

.admin-subpanel {
  margin-top: 1rem;
}

.admin-subpanel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.admin-workspace {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 1rem;
  align-items: start;
}

.category-workspace {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 1rem;
  align-items: start;
}

.folder-nav,
.category-nav {
  position: sticky;
  top: calc(var(--header-offset) + 0.8rem);
  max-height: calc(100vh - var(--header-offset) - 1.6rem);
  overflow: auto;
  scrollbar-width: thin;
}

.folder-nav .editor-stack,
.category-nav .editor-stack {
  max-height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 0.25rem;
}

.folder-nav-item,
.category-nav-item {
  width: 100%;
  text-align: left;
  margin-bottom: 0.45rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.folder-nav-item.active,
.category-nav-item.active {
  border-color: var(--primary);
  background: var(--active-bg);
}

.folder-filter-group {
  display: grid;
  gap: 0.55rem;
}

.folder-row.is-hidden,
.category-row.is-hidden {
  display: none;
}

.folder-row.is-filtered-out,
.folder-row.is-inactive {
  display: none;
}

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.action-bar>form {
  margin: 0;
}

.admin-inline-status {
  margin: 0.35rem 0 0.7rem;
  font-size: 0.9rem;
  min-height: 1.2rem;
  color: var(--muted);
}

.admin-inline-status.is-loading {
  color: var(--primary);
}

.admin-inline-status.is-success {
  color: var(--success);
}

.admin-inline-status.is-error {
  color: var(--danger);
}

.editor-stack {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.editor-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  background: var(--surface);
}

.form-grid {
  display: grid;
  gap: 0.7rem;
}

.form-grid.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.four-col {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.form-field {
  display: grid;
  gap: 0.35rem;
}

.form-field span {
  font-size: 0.86rem;
  color: var(--muted);
}

.form-field-full {
  grid-column: 1 / -1;
}

.form-field-id {
  opacity: 0.6;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 0.7rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 0.55rem;
  vertical-align: top;
  text-align: left;
}

.data-table th {
  background: var(--active-bg);
  font-size: 0.9rem;
  font-weight: 600;
}

.data-table td input,
.data-table td textarea {
  margin: 0;
}

.editor-grid {
  display: grid;
  gap: 0.7rem;
  margin-bottom: 0.6rem;
}

.editor-grid.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.editor-grid.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.row-actions {
  display: flex;
  justify-content: flex-end;
}

.video-row {
  vertical-align: middle;
}

.video-row-link {
  font-size: 0.9rem;
  color: var(--muted);
  word-break: break-all;
}

.videos-table-wrap {
  max-height: 420px;
  overflow: auto;
  scrollbar-width: thin;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.videos-table {
  margin-bottom: 0;
}

.videos-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.folder-nav .editor-stack::-webkit-scrollbar,
.category-nav .editor-stack::-webkit-scrollbar,
.videos-table-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.folder-nav .editor-stack::-webkit-scrollbar-thumb,
.category-nav .editor-stack::-webkit-scrollbar-thumb,
.videos-table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.videos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.5rem;
}

.videos-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.playlist-import-row {
  margin-bottom: 0.65rem;
}

.playlist-status {
  margin: 0.4rem 0 0;
  font-size: 0.86rem;
  color: var(--muted);
  min-height: 1.1rem;
}

.playlist-status.is-loading {
  color: var(--primary);
}

.playlist-status.is-success {
  color: var(--success);
}

.playlist-status.is-error {
  color: var(--danger);
}

.videos-header h5,
.admin-subpanel h3,
.admin-subpanel h4 {
  margin: 0;
}

.filters {
  margin: 1rem 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.site-footer {
  color: #e2e8f0;
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--header-bg);
}

body.theme-dark .site-footer {
  background: #111827;
}

.site-footer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 1rem;
  align-items: start;
}

.site-footer-col h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.site-footer-col p,
.site-footer-col li {
  color: #94a3b8;
  line-height: 1.75;
}

.site-footer-col ul {
  margin: 0;
  padding-left: 1rem;
}

.site-footer-logo {
  width: min(100%, 280px);
  height: auto;
  display: block;
}

.site-footer-copy {
  margin-top: 0.8rem;
  font-size: 0.9rem;
}

.site-footer-copy span {
  display: block;
  font-size: 0.8rem;
}

@media (max-width: 1200px) {
  .site-footer-grid {
    grid-template-columns: 1fr 1fr;
  }

  .site-footer-col:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 920px) {
  :root {
    --header-offset: 54px;
  }

  .header .container {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    column-gap: 0.55rem;
  }

  .header-home-link {
    text-align: center;
    max-width: 100%;
    font-size: 0.93rem;
  }

  .header-center {
    grid-column: auto;
    order: 0;
    justify-self: center;
    justify-content: center;
    max-width: 100%;
  }

  .header-left,
  .header-actions {
    justify-content: center;
  }

  .panel {
    padding: 0.85rem;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .panel-video {
    order: 1;
  }

  .panel-list {
    order: 2;
  }

  .video-list-scroll {
    max-height: 300px;
  }

  .admin-workspace {
    grid-template-columns: 1fr;
  }

  .folder-nav {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .category-workspace {
    grid-template-columns: 1fr;
  }

  .category-nav {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .folder-nav,
  .category-nav {
    padding-bottom: 0.75rem;
  }

  .folder-filter-group {
    grid-template-columns: 1fr;
  }

  .folder-nav .editor-stack,
  .category-nav .editor-stack {
    display: flex;
    gap: 0.55rem;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding-bottom: 0.35rem;
    margin-top: 0.65rem;
  }

  .folder-nav-item,
  .category-nav-item {
    margin-bottom: 0;
    white-space: nowrap;
    width: auto;
    flex: 0 0 auto;
  }

  .editor-grid.two-col,
  .editor-grid.three-col,
  .form-grid.two-col,
  .form-grid.four-col {
    grid-template-columns: 1fr;
  }

  .site-footer-grid {
    grid-template-columns: 1fr;
  }

  .site-footer-col:last-child {
    grid-column: auto;
  }

  .videos-table-wrap {
    max-height: 300px;
  }

  .filters {
    padding-top: 15px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0.2rem;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .filters .badge {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

@media (max-width: 700px) {
  .header-row {
    gap: 0.55rem;
  }

  .back-link {
    font-size: 0.87rem;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 0.8rem;
  }

  .video-link {
    grid-template-columns: 78px 1fr;
    gap: 0.55rem;
    padding: 0.45rem;
  }

  .video-link-thumb {
    width: 78px;
  }

  .video-link-title {
    font-size: 0.9rem;
  }

  .video-list-scroll {
    max-height: 250px;
  }

  .videos-header {
    align-items: stretch;
    flex-direction: column;
  }

  .videos-actions {
    width: 100%;
  }

  .videos-actions .button-secondary,
  .videos-actions button {
    width: 100%;
  }

  .videos-header .button-secondary,
  .videos-header button {
    width: 100%;
  }

  .action-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .action-bar>button,
  .action-bar>form,
  .action-bar>form>button {
    width: 100%;
  }

  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table th,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    margin-bottom: 0.35rem;
  }

  .data-table th,
  .data-table td {
    border-bottom-width: 0;
  }

  .data-table tr:last-child td:last-child {
    border-bottom-width: 1px;
  }

  .videos-table,
  .videos-table thead,
  .videos-table tbody,
  .videos-table tr {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  .videos-table thead {
    display: table-header-group;
  }

  .videos-table tbody {
    display: table-row-group;
  }

  .videos-table th,
  .videos-table td {
    display: table-cell;
    width: auto;
  }

  .videos-table-wrap {
    max-height: 280px;
  }

  .video-meta {
    padding: 0.75rem;
  }

  .video-meta-head {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .site-footer {
    margin-top: auto;
  }
}

@media (max-width: 420px) {
  .header-home-link {
    font-size: 0.9rem;
  }

  .header-home-btn,
  .theme-toggle {
    width: 32px;
    height: 32px;
  }

  .site-footer-col h2 {
    font-size: 0.95rem;
  }
}

.form-field-id>.js-folder-id-input,
.form-field-id>.js-category-id-input {
  border: 1px solid var(--border-disabled);
}

.field-info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  color: white;
  font-size: 10px;
  font-weight: bold;
  border: none;
  margin-left: 6px;
  cursor: help;
  vertical-align: middle;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

.field-info-btn:hover {
  background: var(--primary);
}

.admin-help-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  max-width: 250px;
  line-height: 1.4;
}