/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0b0d12;
  --bg-secondary: #12141a;
  --bg-card: #1a1d27;
  --bg-card-hover: #1f2330;
  --bg-elevated: #242837;
  --border: #2a2e3e;
  --border-light: #363b50;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0b0;
  --text-muted: #5c6178;
  --accent: #6c5ce7;
  --accent-hover: #7c6ff0;
  --accent-dim: #4a3ea8;
  --green: #00c853;
  --green-bg: rgba(0, 200, 83, 0.12);
  --red: #ff5252;
  --red-bg: rgba(255, 82, 82, 0.12);
  --yellow: #ffd740;
  --yellow-bg: rgba(255, 215, 64, 0.12);
  --blue: #448aff;
  --blue-bg: rgba(68, 138, 255, 0.12);
  --orange: #ff9100;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 14px;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0);
}

/* iOS PWA status bar */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
  }
  .main-content {
    padding-top: calc(28px + env(safe-area-inset-top));
  }
  .mobile-nav {
    padding-bottom: env(safe-area-inset-bottom, 4px);
  }
}

/* Safe area adjustments for iOS PWA in landscape */
@supports (padding-left: env(safe-area-inset-left)) {
  .main-content {
    padding-left: calc(32px + env(safe-area-inset-left));
    padding-right: calc(32px + env(safe-area-inset-right));
  }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  color: var(--accent);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 10px 4px;
  font-weight: 600;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  text-align: left;
  font-family: var(--font);
}

.nav-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-btn svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-btn.active svg {
  opacity: 1;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.gpu-badge {
  font-size: 0.65rem;
  padding: 4px 8px;
  background: var(--bg-card);
  border-radius: 4px;
  color: var(--text-muted);
  text-align: center;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ===== MAIN ===== */
.main-content {
  flex: 1;
  padding: 28px 32px;
  max-width: 1200px;
  overflow-y: auto;
  height: 100vh;
}

.tab-content {
  display: none;
  animation: fadeIn 0.25s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.tab-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.tab-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tab-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.35);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(255, 82, 82, 0.2);
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* ===== FILES GRID ===== */
.files-grid {
  display: grid;
  gap: 10px;
}

.file-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  cursor: default;
}

.file-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
}

.file-card.selected {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.06);
}

.file-card.converted {
  border-color: var(--green);
  opacity: 0.75;
}

.file-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  background: transparent;
  position: relative;
}

.file-card.selected .file-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.file-checkbox.checked::after {
  content: '✓';
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.file-checkbox.converted-check {
  background: var(--green);
  border-color: var(--green);
}

.file-checkbox.converted-check::after {
  content: '✓';
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.file-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-meta-item svg {
  opacity: 0.6;
}

.file-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-warn { background: var(--yellow-bg); color: var(--yellow); }

.stream-detail {
  font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.stream-detail.sub-bitmap {
  border-color: rgba(255, 82, 82, 0.2);
  color: var(--red);
}

.stream-detail.sub-text {
  border-color: rgba(0, 200, 83, 0.2);
  color: var(--green);
}

/* ===== SETTINGS ===== */
.settings-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.setting-group h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.setting-row {
  margin-bottom: 16px;
}

.setting-row label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

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

.range-input {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-elevated);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-card);
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
}

.range-value {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 32px;
  text-align: center;
}

.select-input {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  width: 100%;
  max-width: 320px;
  transition: var(--transition);
}

.select-input:hover {
  border-color: var(--border-light);
}

.select-input:focus {
  border-color: var(--accent);
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.radio-item:hover {
  background: var(--bg-elevated);
}

.radio-item input[type="radio"] {
  display: none;
}

.radio-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.radio-item input:checked + .radio-mark {
  border-color: var(--accent);
  background: var(--accent);
}

.radio-item input:checked + .radio-mark::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

/* ===== HISTORY ===== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== LOADING ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== PROGRESS OVERLAY ===== */
.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.progress-overlay.active {
  display: flex;
}

.progress-panel {
  width: 620px;
  max-width: 92vw;
  max-height: 92vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.progress-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.progress-file {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 500;
}

.progress-bar-track {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-stats {
  display: flex;
  gap: 16px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.progress-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.progress-log {
  flex: 1 1 auto;
  min-height: 160px;
  max-height: 55vh;
  overflow-y: auto;
  background: #080a0e;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
}

.log-line {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-line.log-info { color: var(--text-secondary); }
.log-line.log-success { color: var(--green); }
.log-line.log-error { color: var(--red); }
.log-line.log-warn { color: var(--yellow); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 0.85rem;
}

/* ===== PROGRESS HEADER ACTIONS ===== */
.progress-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-close-overlay {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.btn-close-overlay:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-light);
}

/* ===== FLOATING CONVERTING BUTTON ===== */
.floating-converting {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(108, 92, 231, 0.5);
  transition: var(--transition);
  animation: pulseGlow 2s ease-in-out infinite;
}

.floating-converting.active {
  display: flex;
}

.floating-converting:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 6px 28px rgba(108, 92, 231, 0.6);
}

.floating-file {
  font-size: 0.7rem;
  opacity: 0.8;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.7); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 4px 20px rgba(108, 92, 231, 0.5); }
  50% { box-shadow: 0 4px 30px rgba(108, 92, 231, 0.8); }
}

@keyframes slideDownPanel {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ===== VIDEOS TAB ===== */
.videos-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  height: calc(100vh - 160px);
}

.videos-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.video-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}

.video-item:hover {
  background: var(--bg-card-hover);
}

.video-item.active {
  background: rgba(108, 92, 231, 0.1);
  border-color: var(--accent);
}

.video-item-icon {
  color: var(--accent);
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
}

.video-item-info {
  flex: 1;
  min-width: 0;
}

.video-item-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.video-item-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.video-item-actions {
  display: none;
  flex-shrink: 0;
  gap: 4px;
  margin-left: 8px;
}

.video-item:hover .video-item-actions {
  display: flex;
}

.video-action-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.video-action-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.rename-btn:hover {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.delete-btn:hover {
  color: var(--red);
  border-color: rgba(255, 82, 82, 0.3);
}

/* ===== VIDEO PLAYER ===== */
.video-player-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.video-player-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  text-align: center;
}

.video-player-empty h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-top: 12px;
  margin-bottom: 4px;
}

.video-player-empty p {
  font-size: 0.85rem;
}

.video-player-active {
  flex: 1;
  display: none;
  flex-direction: column;
  background: #000;
}

#videoPlayer {
  width: 100%;
  max-height: calc(100vh - 300px);
  background: #000;
  display: block;
}

#videoPlayer::-webkit-media-controls-panel {
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

.video-info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.video-info-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-info-size {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 12px;
}

/* ===== SERVER PANEL ===== */
.server-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.server-status-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.server-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.server-status-row:last-child {
  border-bottom: none;
}

.server-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.server-value {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.server-value.mono {
  font-family: var(--mono);
}

.server-actions {
  display: flex;
  gap: 12px;
}

.server-actions .btn {
  flex: 1;
  justify-content: center;
  padding: 14px 20px;
  font-size: 0.9rem;
}

.server-actions .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.server-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  background: var(--yellow-bg);
  border: 1px solid rgba(255, 215, 64, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--yellow);
  line-height: 1.5;
}

.server-warning svg {
  flex-shrink: 0;
  margin-top: 2px;
}

.server-warning strong {
  color: var(--text-primary);
}

/* ===== INSTALL PWA BUTTON (sidebar) ===== */
.btn-install-pwa {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(108, 92, 231, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
}

.btn-install-pwa:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== PWA INSTALL PROMPT (mobile banner) ===== */
.pwa-install-prompt {
  position: fixed;
  bottom: 70px;
  left: 0;
  right: 0;
  z-index: 200;
  display: none;
  padding: 8px 12px;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.pwa-install-content {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  max-width: 500px;
  margin: 0 auto;
}

.pwa-install-icon {
  color: var(--accent);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-install-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pwa-install-text strong {
  font-size: 0.85rem;
  color: var(--text-primary);
}

.pwa-install-text span {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.pwa-install-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: var(--transition);
  flex-shrink: 0;
}

.pwa-install-close:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ===== MOBILE BOTTOM NAV ===== */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 6px 0;
  padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
  justify-content: space-around;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(18, 20, 26, 0.92);
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.6rem;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
  border-radius: var(--radius-sm);
  min-width: 52px;
  position: relative;
}

.mobile-nav-btn::after {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 24px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-nav-btn.active::after {
  transform: translateX(-50%) scaleX(1);
}

.mobile-nav-btn svg {
  opacity: 0.5;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  width: 22px;
  height: 22px;
}

.mobile-nav-btn span {
  font-size: 0.55rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: color 0.2s ease;
}

.mobile-nav-btn:active {
  transform: scale(0.92);
}

.mobile-nav-btn.active {
  color: var(--accent);
}

.mobile-nav-btn.active svg {
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(108, 92, 231, 0.4));
}

/* ===== RESPONSIVE — Mobile (<=768px) ===== */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .mobile-nav {
    display: flex;
  }

  .main-content {
    padding: 16px 16px;
    padding-bottom: 86px;
    height: auto;
    min-height: 100vh;
    max-width: 100%;
    overflow-y: visible;
  }

  /* ---- Tab Header ---- */
  .tab-header {
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
  }

  .tab-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
  }

  .tab-desc {
    font-size: 0.78rem;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-actions .btn {
    flex: 1;
    justify-content: center;
    font-size: 0.78rem;
    padding: 12px 14px;
    min-height: 44px;
    border-radius: var(--radius-sm);
  }

  .header-actions .btn svg {
    width: 16px;
    height: 16px;
  }

  /* ---- File Cards ---- */
  .file-card {
    padding: 14px 16px;
    gap: 12px;
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
  }

  .file-card:active {
    transform: scale(0.985);
    background: var(--bg-card-hover);
  }

  .file-card.selected:active {
    background: rgba(108, 92, 231, 0.1);
  }

  .file-name {
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.3;
    margin-bottom: 6px;
  }

  .file-meta {
    gap: 8px;
  }

  .file-meta-item {
    font-size: 0.68rem;
    gap: 3px;
  }

  .file-checkbox {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border-radius: 6px;
  }

  .file-checkbox.checked::after {
    font-size: 14px;
  }

  .file-badges {
    flex-wrap: wrap;
  }

  .stream-detail {
    font-size: 0.65rem;
  }

  .badge {
    font-size: 0.65rem;
    padding: 3px 7px;
  }

  .file-card.converted {
    opacity: 0.6;
  }

  /* ---- Settings Panel ---- */
  .settings-panel {
    padding: 18px 16px;
    border-radius: var(--radius);
    gap: 24px;
  }

  .setting-group h3 {
    font-size: 0.78rem;
    margin-bottom: 14px;
    padding-bottom: 6px;
  }

  .setting-row {
    margin-bottom: 14px;
  }

  .setting-row label {
    font-size: 0.82rem;
    margin-bottom: 8px;
  }

  .setting-hint {
    font-size: 0.7rem;
    margin-top: 6px;
    line-height: 1.4;
  }

  .range-input {
    height: 8px;
  }

  .range-input::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  .range-value {
    font-size: 1.1rem;
    min-width: 36px;
  }

  .select-input {
    padding: 12px 14px;
    font-size: 0.9rem;
    max-width: 100%;
    border-radius: var(--radius-sm);
  }

  .radio-item {
    padding: 12px 14px;
    font-size: 0.85rem;
  }

  .radio-mark {
    width: 22px;
    height: 22px;
  }

  /* ---- History Tab ---- */
  .history-item {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.82rem;
  }

  .history-list {
    gap: 8px;
  }

  /* ---- Videos Tab ---- */
  .videos-layout {
    grid-template-columns: 1fr;
    height: auto;
    gap: 12px;
  }

  .videos-list {
    max-height: 45vh;
    border-radius: var(--radius);
    padding: 6px;
  }

  .video-item {
    padding: 10px 12px;
    gap: 10px;
    border-radius: var(--radius-sm);
  }

  .video-item:active {
    transform: scale(0.98);
  }

  .video-item-icon {
    width: 32px;
    height: 32px;
  }

  .video-item-icon svg {
    width: 18px;
    height: 18px;
  }

  .video-item-name {
    font-size: 0.78rem;
  }

  .video-item-meta {
    font-size: 0.65rem;
  }

  .video-player-panel {
    border-radius: var(--radius);
    min-height: 200px;
  }

  #videoPlayer {
    max-height: 40vh;
  }

  .video-info-bar {
    padding: 10px 14px;
  }

  .video-info-name {
    font-size: 0.78rem;
  }

  .video-info-size {
    font-size: 0.7rem;
  }

  .video-player-empty {
    padding: 30px 20px;
    min-height: 180px;
  }

  .video-player-empty svg {
    width: 48px;
    height: 48px;
  }

  .video-player-empty h3 {
    font-size: 0.95rem;
  }

  .video-player-empty p {
    font-size: 0.78rem;
  }

  .video-item-actions {
    display: flex;
    gap: 3px;
    margin-left: 4px;
  }

  .video-action-btn {
    width: 32px;
    height: 32px;
  }

  .video-action-btn svg {
    width: 16px;
    height: 16px;
  }

  /* ---- Progress Overlay ---- */
  .progress-overlay {
    align-items: flex-start;
    padding-top: max(12px, env(safe-area-inset-top, 12px));
  }

  .progress-overlay.active {
    display: flex;
  }

  .progress-panel {
    width: 100%;
    max-width: 100%;
    max-height: 80vh;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    padding: 16px 18px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    animation: slideDownPanel 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  }

  /* Drag handle for the panel */
  .progress-panel::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 12px;
  }

  .progress-header {
    margin-bottom: 14px;
  }

  .progress-header h3 {
    font-size: 1rem;
  }

  .progress-header-actions .btn-sm {
    padding: 8px 16px;
    font-size: 0.78rem;
  }

  .progress-file {
    font-size: 0.78rem;
    margin-bottom: 10px;
  }

  .progress-bar-track {
    height: 8px;
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .progress-bar-fill {
    border-radius: 4px;
  }

  .progress-stats {
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.7rem;
    margin-bottom: 14px;
  }

  .progress-log {
    flex: 1 1 auto;
    min-height: 40vh;
    max-height: 58vh;
    padding: 10px 12px;
    font-size: 0.75rem;
  }

  .log-line {
    white-space: normal;
    word-break: break-all;
  }

  .btn-close-overlay {
    width: 36px;
    height: 36px;
  }

  /* ---- Floating Button ---- */
  .floating-converting {
    bottom: 84px;
    right: 14px;
    padding: 14px 22px;
    font-size: 0.8rem;
    border-radius: 50px;
    box-shadow: 0 6px 24px rgba(108, 92, 231, 0.5);
  }

  .floating-converting:active {
    transform: scale(0.94);
  }

  .pulse-dot {
    width: 10px;
    height: 10px;
  }

  .floating-file {
    font-size: 0.68rem;
    max-width: 100px;
  }

  /* ---- PWA Install ---- */
  .pwa-install-prompt {
    bottom: 72px;
    padding: 6px 12px;
  }

  .pwa-install-content {
    padding: 12px 14px;
    border-radius: var(--radius);
  }

  .pwa-install-icon svg {
    width: 36px;
    height: 36px;
  }

  .pwa-install-text strong {
    font-size: 0.8rem;
  }

  .pwa-install-text span {
    font-size: 0.68rem;
  }

  /* ---- Server Tab ---- */
  .server-panel {
    padding: 20px 16px;
    border-radius: var(--radius);
    gap: 20px;
  }

  .server-status-row {
    padding: 10px 0;
  }

  .server-label {
    font-size: 0.8rem;
  }

  .server-value {
    font-size: 0.8rem;
  }

  .server-actions {
    flex-direction: column;
    gap: 10px;
  }

  .server-actions .btn {
    padding: 14px;
    font-size: 0.85rem;
    justify-content: center;
  }

  .server-warning {
    font-size: 0.75rem;
    padding: 12px 14px;
  }

  /* ---- Loading & Empty States ---- */
  .loading-state {
    padding: 40px 16px;
  }

  .empty-state {
    padding: 50px 16px;
  }

  .empty-state svg {
    width: 40px;
    height: 40px;
  }

  .empty-state h3 {
    font-size: 1rem;
  }

  .empty-state p {
    font-size: 0.8rem;
  }

  .spinner {
    width: 28px;
    height: 28px;
    border-width: 3px;
  }
}

/* ===== RESPONSIVE — Small Mobile (<=480px) ===== */
@media (max-width: 480px) {
  .main-content {
    padding: 12px 12px;
    padding-bottom: 80px;
  }

  .tab-header h2 {
    font-size: 1.15rem;
  }

  .header-actions {
    gap: 6px;
  }

  .header-actions .btn {
    padding: 10px 10px;
    font-size: 0.72rem;
    min-height: 40px;
  }

  .file-card {
    padding: 12px 14px;
    gap: 10px;
  }

  .file-name {
    font-size: 0.78rem;
  }

  .file-meta {
    gap: 6px;
  }

  .file-meta-item {
    font-size: 0.62rem;
  }

  .file-checkbox {
    width: 20px;
    height: 20px;
    min-width: 20px;
  }

  .file-badges {
    flex-wrap: wrap;
  }

  .header-actions .btn svg {
    width: 14px;
    height: 14px;
  }

  .mobile-nav-btn {
    padding: 4px 10px;
    min-width: 44px;
  }

  .mobile-nav-btn svg {
    width: 20px;
    height: 20px;
  }

  .mobile-nav-btn span {
    font-size: 0.5rem;
  }

  .floating-converting {
    bottom: 76px;
    right: 10px;
    padding: 12px 18px;
    font-size: 0.75rem;
  }

  .progress-panel {
    padding: 16px 14px;
  }

  .progress-panel::before {
    margin-bottom: 12px;
  }

  .progress-stats {
    font-size: 0.65rem;
    gap: 6px;
  }

  .videos-list {
    max-height: 40vh;
  }

  .settings-panel {
    padding: 14px 12px;
    gap: 20px;
  }

  .select-input {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .radio-item {
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  .btn-install-pwa span {
    display: none;
  }

  .pwa-install-prompt {
    bottom: 68px;
    padding: 4px 8px;
  }

  .server-panel {
    padding: 16px 14px;
  }
}
