:root {
  --bg: #0c0f14;
  --sidebar: #121820;
  --surface: #1a2230;
  --border: #2a3548;
  --text: #eef2f8;
  --muted: #8b9ab5;
  --accent: #3b82f6;
  --accent-h: #2563eb;
  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --sidebar-w: 320px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: Outfit, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.5rem;
}

.sidebar-head h1 {
  margin: 0;
  font-size: 1.15rem;
}

.sidebar-close { display: none; }

.panel {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: none;
}

.panel-collapsible {
  padding: 0;
}

.panel-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.65rem 1rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

.panel-toggle-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  flex: 1;
}

.panel-toggle-meta {
  font-size: 0.7rem;
  color: var(--accent);
}

.panel-toggle-icon {
  font-size: 0.65rem;
  color: var(--muted);
  transition: transform 0.2s;
}

.panel-collapsible.collapsed .panel-toggle-icon {
  transform: rotate(-90deg);
}

.panel-collapsible .panel-body {
  padding: 0 1rem 0.65rem;
}

.panel-collapsible.collapsed .panel-body {
  display: none;
}

.label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.hint {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

.hint code {
  background: var(--surface);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.tailscale-hint {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(59, 130, 246, 0.12);
  border-radius: 8px;
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: #93c5fd;
}

.row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.select, .search, .input, .import-area {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
}

.select, .search, .input {
  padding: 0.55rem 0.75rem;
  min-height: 40px;
}

.select { flex: 1; }

.input-mono {
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}

.modal-box .label {
  margin-top: 0.75rem;
}

.modal-box .label:first-of-type {
  margin-top: 0;
}

.import-area {
  min-height: 72px;
  max-height: 100px;
  padding: 0.5rem 0.65rem;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  resize: vertical;
  margin-bottom: 0.5rem;
}

.import-area.dragover {
  border-color: var(--accent);
  background: #1e2a3d;
}

.search { margin-bottom: 0.5rem; }

.btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 36px;
}

.btn:hover { background: var(--accent-h); }

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

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

.btn.danger:hover { background: #dc2626; }

.btn.danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.secondary.active {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm { font-size: 0.8rem; padding: 0.4rem 0.65rem; min-height: 34px; }

.btn-block { width: 100%; margin-top: 0.35rem; }

.file-btn { cursor: pointer; display: inline-flex; align-items: center; }

.badge {
  background: var(--surface);
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  font-size: 0.7rem;
}

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

.filter-flags {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.status-flags {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 0.55rem;
}

.flag-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0;
}

.flag-item input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.channel-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.channel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.channel-row {
  display: flex;
  align-items: stretch;
  gap: 0.2rem;
  margin-bottom: 2px;
}

.channel-row.select-mode { margin-bottom: 4px; }

.channel-item {
  display: block;
  flex: 1;
  min-width: 0;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
}

.channel-edit,
.channel-delete {
  flex-shrink: 0;
  width: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.channel-delete {
  font-size: 1.1rem;
}

.channel-edit {
  font-size: 0.95rem;
}

.channel-row:hover .channel-edit,
.channel-row:hover .channel-delete { opacity: 1; }

.channel-edit:hover {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.channel-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #fecaca;
}

.channel-select {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.45rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  background: var(--surface);
  border: 1px solid transparent;
}

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

.channel-select.checked {
  border-color: var(--bad);
  background: rgba(239, 68, 68, 0.1);
}

.channel-select input {
  margin-top: 0.15rem;
  accent-color: var(--bad);
}

.channel-select-name { flex: 1; min-width: 0; }

.channel-item:hover { background: var(--surface); }

.channel-item.active {
  background: var(--accent);
  color: #fff;
}

.channel-item .flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin-top: 0.2rem;
}

.mini-flag {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  background: rgba(0,0,0,0.25);
}

.channel-item.active .mini-flag { background: rgba(255,255,255,0.2); }

.mini-flag.issue { background: rgba(239,68,68,0.35); color: #fecaca; }
.mini-flag.ok { background: rgba(34,197,94,0.35); color: #bbf7d0; }

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
}

.main-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar);
}

#open-sidebar { display: none; }

.now-playing h2 {
  margin: 0.15rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.now-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.player-wrap {
  position: relative;
  background: #000;
  aspect-ratio: 16/9;
  max-height: 55vh;
}

#player {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}

.player-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--muted);
  pointer-events: none;
  font-size: 0.95rem;
}

.player-hint.hidden { display: none; }

.stream-info {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--sidebar);
}

.stream-info-title {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stream-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.55rem 1rem;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.info-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.info-value {
  font-size: 0.92rem;
  font-weight: 600;
  word-break: break-word;
}

.channel-url-box {
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.channel-url-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin-top: 0.35rem;
}

.channel-url {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  word-break: break-all;
  color: #93c5fd;
  background: transparent;
}

.channel-url-row .btn {
  flex-shrink: 0;
}

.status-panel {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(26, 34, 48, 0.35) 0%, transparent 100%);
}

.status-head {
  margin-bottom: 0.85rem;
}

.status-panel h3 {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
}

.status-panel .hint {
  margin: 0;
}

.status-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.status-btn:hover {
  border-color: #4b5f7d;
  color: var(--text);
}

.status-btn:active {
  transform: scale(0.98);
}

.status-btn.active.status-ok {
  background: rgba(34, 197, 94, 0.18);
  border-color: var(--ok);
  color: #bbf7d0;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25);
}

.status-btn.active.status-bad {
  background: rgba(239, 68, 68, 0.18);
  border-color: var(--bad);
  color: #fecaca;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.25);
}

.status-btn.active.status-warn {
  background: rgba(245, 158, 11, 0.16);
  border-color: var(--warn);
  color: #fde68a;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.22);
}

.status-btn-label {
  pointer-events: none;
}

.status-panel.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.status-panel .btn-block { margin-top: 0.85rem; }

@media (min-width: 900px) {
  .status-flags {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .status-btn {
    min-height: 58px;
    font-size: 1rem;
  }
}

.icon-btn {
  border: none;
  background: var(--surface);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  width: min(400px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-box.modal-wide {
  width: min(520px, 100%);
}

.modal-box h2 { margin: 0 0 0.5rem; }

.export-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}

.export-count {
  margin: 0.5rem 0 0;
  text-align: center;
}

#btn-filter.active {
  border-color: var(--accent);
  color: var(--accent);
}

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

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.65rem 1rem;
  border-radius: 10px;
  z-index: 300;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* Mobile */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 32px rgba(0,0,0,0.4);
  }

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

  .sidebar-close, #open-sidebar { display: inline-flex; align-items: center; justify-content: center; }

  .player-wrap { max-height: none; }
}

@media (hover: none) {
  .channel-edit,
  .channel-delete {
    opacity: 0.65;
  }
}

@media (min-width: 1200px) {
  :root { --sidebar-w: 360px; }
  .player-wrap { max-height: 60vh; }
}
