:root {
  color-scheme: light dark;
  --bg: #0b111f;
  --bg-accent: rgba(20, 41, 82, 0.65);
  --surface: rgba(14, 22, 45, 0.68);
  --border: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --text-muted: rgba(255, 255, 255, 0.65);
  --primary: #61dafb;
  --primary-strong: #3fb8ff;
  --secondary: #7f8bff;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --transition: 0.2s ease;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at top right, rgba(70, 111, 255, 0.32), transparent 55%),
    radial-gradient(circle at 15% 20%, rgba(44, 255, 215, 0.3), transparent 40%),
    linear-gradient(160deg, #05080f, #0a1224 65%, #05080f);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: clamp(16px, 5vw, 48px);
}

.background {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 20% 20%, rgba(110, 196, 255, 0.15), transparent 45%),
    radial-gradient(circle at 70% 15%, rgba(82, 94, 255, 0.2), transparent 50%);
  filter: blur(40px);
  opacity: 0.7;
  z-index: 0;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(1200px, 100%);
  max-height: 100vh;
  backdrop-filter: blur(26px);
  background: rgba(7, 14, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 1;
}

.app-header,
.app-footer {
  padding: 24px clamp(24px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.app-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--text-muted);
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  font-size: 24px;
  background: linear-gradient(140deg, rgba(129, 218, 255, 0.25), rgba(173, 137, 255, 0.2));
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 4px 0 0;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.primary-button,
.ghost-button {
  appearance: none;
  border: none;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: 999px;
  padding: 12px 22px;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  font-size: 15px;
  text-decoration: none;
}

.primary-button {
  color: #0a152d;
  background: linear-gradient(140deg, var(--primary), var(--primary-strong));
  box-shadow: 0 12px 24px rgba(72, 208, 255, 0.25);
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 40px rgba(72, 208, 255, 0.32);
}

.ghost-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ghost-button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.app-main {
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr;
  gap: 24px;
  padding: 24px clamp(24px, 4vw, 40px) 32px;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: hidden;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 20px 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.panel-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.search-icon {
  opacity: 0.7;
}

.hint-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.tree-panel {
  flex: 1;
  min-height: 280px;
}

.tree {
  overflow-y: auto;
  max-height: 100%;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tree::-webkit-scrollbar {
  width: 6px;
}

.tree::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.tree-node {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tree-item {
  position: relative;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.tree-item[data-type="folder"]::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(126, 140, 255, 0.15), transparent 70%);
  opacity: 0;
  border-radius: inherit;
  transition: opacity var(--transition);
}

.tree-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tree-item.active {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.tree-item.active::before {
  opacity: 1;
}

.tree-item.match:not(.active) {
  box-shadow: inset 0 0 0 1px rgba(97, 218, 251, 0.35);
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  z-index: 1;
}

.tree-toggle {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.tree-toggle span {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid rgba(255, 255, 255, 0.85);
  transform: translateX(1px);
  transition: transform var(--transition);
}

.tree-toggle.expanded {
  background: rgba(255, 255, 255, 0.12);
}

.tree-toggle.expanded span {
  transform: rotate(90deg);
}

.tree-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

.tree-spacer {
  width: 22px;
  height: 22px;
}

.tree-icon {
  font-size: 18px;
  width: 22px;
  text-align: center;
}

.tree-label {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-weight: 500;
}

.tree-path {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.children-container {
  margin-left: 18px;
  border-left: 1px dashed rgba(255, 255, 255, 0.12);
  padding-left: 14px;
  display: grid;
  gap: 6px;
}

.children-container.collapsed {
  display: none;
}

.children-container.anim-enter {
  animation: fadeSlide 0.2s ease;
}

@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
}

.detail {
  min-height: 320px;
}

.detail-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

.empty-state h2 {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 12px;
}

.detail-meta {
  display: grid;
  gap: 12px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: var(--radius-sm);
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  font-size: 14px;
  color: var(--text-muted);
}

.meta-row strong {
  color: var(--text);
  font-weight: 600;
}

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

.secondary-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.secondary-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.chunk-list {
  display: grid;
  gap: 10px;
}

.chunk-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.24);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
}

.chunk-item button {
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
}

.chunk-item .chunk-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chunk-item .chunk-size {
  font-size: 12px;
  color: var(--text-muted);
}

.segment-list {
  margin-top: 12px;
}

.segment-list code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}

.media-card {
  display: grid;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 18px;
}

.media-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.media-player {
  width: 100%;
  max-height: 420px;
  border-radius: var(--radius-sm);
  background: #000;
  outline: none;
}

.toast {
  position: fixed;
  inset: auto 24px 24px auto;
  min-width: 280px;
  max-width: 340px;
  background: rgba(12, 31, 60, 0.92);
  border: 1px solid rgba(97, 218, 251, 0.32);
  color: var(--text);
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.32);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: rgba(71, 255, 193, 0.32);
}

.toast.error {
  border-color: rgba(255, 119, 119, 0.32);
}

.loading-backdrop {
  position: fixed;
  inset: 0;
  backdrop-filter: blur(12px);
  background: rgba(5, 10, 20, 0.54);
  display: grid;
  place-items: center;
  z-index: 150;
  transition: opacity 0.25s ease;
}

.loading-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-card {
  background: rgba(10, 18, 36, 0.92);
  border-radius: var(--radius-md);
  padding: 26px 36px;
  display: grid;
  justify-items: center;
  gap: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
}

.spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}

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

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    max-height: none;
  }

  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .sidebar {
    order: 2;
  }

  .content {
    order: 1;
  }
}

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

  .app-header,
  .app-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
