* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0a0a0a; color: #e0e0e0; overflow: hidden; height: 100vh; }

/* LOGIN */
.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 100%); }
.login-box { background: #1e1e2e; padding: 40px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); width: 360px; text-align: center; }
.login-box h1 { font-size: 28px; margin-bottom: 4px; color: #fff; }
.login-sub { color: #888; margin-bottom: 24px; font-size: 14px; }
.login-box input { width: 100%; padding: 12px 16px; margin-bottom: 12px; border: 1px solid #333; border-radius: 8px; background: #2a2a3a; color: #fff; font-size: 14px; outline: none; }
.login-box input:focus { border-color: #6366f1; }
.login-box button { width: 100%; padding: 12px; border: none; border-radius: 8px; background: #6366f1; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.login-box button:hover { background: #5558e6; }
.login-error { color: #ef4444; font-size: 13px; margin-top: 8px; min-height: 20px; }

/* HIDDEN */
.hidden { display: none !important; }

/* APP LAYOUT */
.app { display: flex; height: 100vh; }

/* SIDEBAR TOGGLE */
.sidebar-toggle { position: fixed; left: 0; top: 50%; transform: translateY(-50%); width: 24px; height: 60px; background: #1e1e2e; border: 1px solid #333; border-left: none; border-radius: 0 8px 8px 0; color: #aaa; display: none; align-items: center; justify-content: center; cursor: pointer; z-index: 50; font-size: 12px; }
.sidebar-toggle:hover { background: #2a2a3a; color: #fff; }
.sidebar-collapsed .sidebar-toggle { display: flex; }
.sidebar-collapsed .sidebar { position: fixed; left: -280px; top: 0; height: 100vh; z-index: 60; transition: left 0.2s; }
.sidebar-collapsed .sidebar:hover, .sidebar-collapsed .sidebar.sidebar-peek { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,0.5); }

/* SIDEBAR */
.sidebar { width: 280px; min-width: 280px; background: #141420; border-right: 1px solid #2a2a3a; display: flex; flex-direction: column; transition: width 0.2s; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid #2a2a3a; }
.sidebar-header h2 { font-size: 18px; color: #fff; }
.sidebar-actions { display: flex; gap: 8px; }
.btn-icon { background: none; border: 1px solid #333; color: #aaa; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: #2a2a3a; color: #fff; }
.sidebar-search { padding: 8px 12px; position: relative; }
.sidebar-search input { width: 100%; padding: 10px 12px 10px 36px; border: 2px solid #333; border-radius: 8px; background: #1e1e2e; color: #fff; font-size: 14px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
.sidebar-search input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.2); }
.sidebar-search input::placeholder { color: #666; }
.sidebar-search::before { content: '\1F50D'; position: absolute; left: 22px; top: 50%; transform: translateY(-50%); font-size: 14px; pointer-events: none; opacity: 0.5; }
.category-bar { display: flex; gap: 6px; padding: 0 12px 8px; flex-wrap: wrap; }
.cat-btn { padding: 4px 10px; border: 1px solid #333; border-radius: 12px; background: none; color: #aaa; font-size: 11px; cursor: pointer; white-space: nowrap; }
.cat-btn.active { background: #6366f1; border-color: #6366f1; color: #fff; }
.channel-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.channel-item { display: flex; align-items: center; padding: 8px 12px; border-radius: 6px; cursor: pointer; margin-bottom: 2px; transition: background 0.15s; font-size: 13px; }
.channel-item:hover { background: #1e1e2e; }
.channel-item.selected { background: #6366f1; color: #fff; }
.channel-item .ch-name { flex: 1; }
.channel-item .ch-cat { font-size: 10px; color: #666; margin-left: 8px; }
.channel-item.selected .ch-cat { color: rgba(255,255,255,0.7); }
.channel-item .ch-logo { height: 18px; width: 18px; object-fit: contain; margin-right: 6px; border-radius: 3px; }
.channel-item .ch-fav { margin-left: 4px; cursor: pointer; font-size: 14px; color: #555; }
.channel-item .ch-fav.active { color: #f59e0b; }
.channel-item .ch-fav:hover { color: #f59e0b; }
.sidebar-footer { padding: 12px; border-top: 1px solid #2a2a3a; display: flex; flex-direction: column; gap: 6px; }
.btn-sm { padding: 6px 12px; border: 1px solid #333; border-radius: 6px; background: none; color: #aaa; font-size: 12px; cursor: pointer; }
.btn-sm:hover { background: #2a2a3a; color: #fff; }
#selected-count { font-size: 12px; color: #666; }

/* LAYOUT PICKER */
.layout-picker { display: flex; gap: 3px; }
.layout-btn { width: 26px; height: 26px; border: 1px solid #333; border-radius: 4px; background: none; color: #666; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.layout-btn:hover { background: #2a2a3a; color: #fff; }
.layout-btn.active { background: #6366f1; border-color: #6366f1; color: #fff; }

/* FOCUS LAYOUT */
.video-grid.layout-focus { grid-template-columns: 1fr; }
.video-grid.layout-focus .video-cell:first-child { grid-column: 1 / -1; }

/* VIDEO GRID */
.video-grid { flex: 1; display: grid; gap: 2px; background: #000; overflow: hidden; }
.empty-state { display: flex; align-items: center; justify-content: center; color: #555; font-size: 16px; grid-column: 1 / -1; grid-row: 1 / -1; }

/* VIDEO CELL */
.video-cell { position: relative; background: #111; overflow: hidden; }
.video-cell video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-cell.fullscreen-cell { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 100; }

/* STREAM STATUS */
.stream-status { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(0,0,0,0.85); z-index: 5; pointer-events: none; }
.stream-status.status-loading .status-icon { font-size: 32px; animation: spin 1s linear infinite; }
.stream-status.status-error .status-icon { font-size: 32px; color: #ef4444; }
.stream-status .status-text { margin-top: 8px; font-size: 12px; color: #aaa; text-align: center; padding: 0 10px; }
.stream-status.status-error .status-text { color: #ef4444; }
.stream-status .status-retry { margin-top: 4px; font-size: 11px; color: #666; }
.stream-status.status-paused { background: rgba(0,0,0,0.7); }
.stream-status.status-paused .status-icon { font-size: 32px; color: #6366f1; animation: none; }
.stream-status.status-paused .status-text { color: #888; }
.stream-status .status-retry-btn { margin-top: 10px; padding: 6px 16px; border: 1px solid #6366f1; border-radius: 6px; background: none; color: #6366f1; font-size: 12px; cursor: pointer; pointer-events: auto; }
.stream-status .status-retry-btn:hover { background: #6366f1; color: #fff; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* TEST RESULTS */
.test-ok { color: #22c55e; }
.test-fail { color: #ef4444; }
.test-row { padding: 3px 0; }

/* BANDWIDTH BANNER */
.bw-banner { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 160; border-radius: 10px; padding: 12px 20px; display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,0.4); animation: bannerSlide 0.3s ease; }
.bw-banner-yellow { background: rgba(245,158,11,0.95); color: #000; }
.bw-banner-red { background: rgba(239,68,68,0.95); color: #fff; }
@keyframes bannerSlide { from { transform: translateX(-50%) translateY(-30px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }

/* TOKEN ALERT */
.token-alert { position: fixed; top: 12px; right: 12px; z-index: 150; background: rgba(239,68,68,0.9); backdrop-filter: blur(4px); border-radius: 10px; padding: 8px 14px; cursor: pointer; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 16px rgba(239,68,68,0.4); transition: transform 0.2s, box-shadow 0.2s; animation: pulse-alert 2s infinite; }
.token-alert:hover { transform: scale(1.05); box-shadow: 0 6px 24px rgba(239,68,68,0.6); }
.token-alert-icon { font-size: 20px; color: #fff; }
.token-alert-count { font-size: 13px; font-weight: 700; color: #fff; }
@keyframes pulse-alert { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
.token-alert.refreshing { animation: none; background: rgba(99,102,241,0.9); box-shadow: 0 4px 16px rgba(99,102,241,0.4); }

/* HOVER OVERLAY */
.video-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; opacity: 0; transition: opacity 0.25s; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; z-index: 10; }
.video-cell:hover .video-overlay { opacity: 1; pointer-events: auto; }

.overlay-top { background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; }
.overlay-channel-name { color: #fff; font-size: 13px; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,0.8); }

.overlay-bottom { background: linear-gradient(0deg, rgba(0,0,0,0.7) 0%, transparent 100%); padding: 10px 14px; display: flex; align-items: center; justify-content: center; gap: 12px; position: relative; z-index: 11; }

.overlay-btn { background: rgba(255,255,255,0.15); backdrop-filter: blur(4px); border: none; color: #fff; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; transition: background 0.2s; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
.overlay-btn:hover { background: rgba(255,255,255,0.3); }
.overlay-btn.active { background: #6366f1; }

.volume-wrap { position: relative; display: flex; align-items: center; }
.volume-wrap .volume-slider { width: 0; opacity: 0; transition: width 0.2s, opacity 0.2s; -webkit-appearance: none; appearance: none; height: 4px; background: rgba(255,255,255,0.3); border-radius: 2px; outline: none; cursor: pointer; margin-left: 0; }
.volume-wrap:hover .volume-slider { width: 70px; opacity: 1; margin-left: 6px; }
.volume-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,0.5); }
.volume-slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; cursor: pointer; border: none; }

.overlay-close { position: absolute; top: 8px; right: 8px; }

/* MODAL */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-content { background: #1e1e2e; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.6); width: 90vw; max-width: 1000px; max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-large { max-width: 1100px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid #2a2a3a; }
.modal-header h2 { font-size: 18px; color: #fff; }
.btn-close { background: none; border: none; color: #aaa; font-size: 24px; cursor: pointer; }
.btn-close:hover { color: #fff; }

/* ADMIN */
.admin-tabs { display: flex; border-bottom: 1px solid #2a2a3a; padding: 0 20px; }
.tab { padding: 10px 16px; border: none; background: none; color: #888; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: #6366f1; border-bottom-color: #6366f1; }
.tab:hover { color: #fff; }
.admin-body { padding: 20px; overflow-y: auto; flex: 1; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat-card { background: #2a2a3a; border-radius: 10px; padding: 20px; text-align: center; }
.stat-card .stat-num { font-size: 32px; font-weight: 700; color: #6366f1; }
.stat-card .stat-label { font-size: 12px; color: #888; margin-top: 4px; }
.admin-toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.admin-toolbar input, .admin-toolbar select { padding: 6px 10px; border: 1px solid #333; border-radius: 6px; background: #2a2a3a; color: #fff; font-size: 13px; outline: none; }
.btn-primary { padding: 6px 14px; border: none; border-radius: 6px; background: #6366f1; color: #fff; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn-primary:hover { background: #5558e6; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.admin-table th { text-align: left; padding: 8px 10px; border-bottom: 1px solid #333; color: #888; font-weight: 600; }
.admin-table td { padding: 8px 10px; border-bottom: 1px solid #1a1a2a; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-table tr:hover { background: #2a2a3a; }
.btn-danger { padding: 4px 8px; border: 1px solid #ef4444; border-radius: 4px; background: none; color: #ef4444; font-size: 11px; cursor: pointer; }
.btn-danger:hover { background: #ef4444; color: #fff; }
.btn-edit { padding: 4px 8px; border: 1px solid #6366f1; border-radius: 4px; background: none; color: #6366f1; font-size: 11px; cursor: pointer; margin-right: 4px; }
.btn-edit:hover { background: #6366f1; color: #fff; }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.inline-form input { padding: 6px 10px; border: 1px solid #333; border-radius: 6px; background: #2a2a3a; color: #fff; font-size: 13px; outline: none; }
.pagination { display: flex; gap: 6px; margin-top: 12px; justify-content: center; }
.page-btn { padding: 4px 10px; border: 1px solid #333; border-radius: 4px; background: none; color: #aaa; font-size: 12px; cursor: pointer; }
.page-btn.active { background: #6366f1; border-color: #6366f1; color: #fff; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ========== MOBILE (max-width: 768px) ========== */
@media (max-width: 768px) {
  /* Sidebar: hidden by default on mobile, full overlay when open */
  .app { flex-direction: column; }
  .sidebar { position: fixed; left: -100%; top: 0; width: 85vw; max-width: 320px; height: 100vh; z-index: 200; transition: left 0.25s; }
  .sidebar.mobile-open { left: 0; }
  .sidebar-backdrop { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 199; }
  .sidebar-backdrop.active { display: block; }

  /* Mobile hamburger always visible */
  .sidebar-toggle { display: flex !important; left: 0; top: 8px; transform: none; z-index: 50; width: 36px; height: 36px; border-radius: 0 8px 8px 0; font-size: 16px; }
  .sidebar-collapsed .sidebar-toggle { display: flex !important; }
  .sidebar-collapsed .sidebar { left: -100%; display: flex; }

  /* Login box responsive */
  .login-box { width: 90vw; max-width: 360px; padding: 30px 24px; }
  .login-box h1 { font-size: 22px; }

  /* Video grid: single column on portrait */
  .video-grid { min-height: 0; }

  /* Overlay: always partially visible on mobile (no hover) */
  .video-overlay { opacity: 1; }
  .overlay-top { padding: 6px 10px; }
  .overlay-bottom { padding: 6px 10px; gap: 8px; }
  .overlay-btn { width: 30px; height: 30px; font-size: 13px; }
  .overlay-channel-name { font-size: 11px; }

  /* Modal full screen on mobile */
  .modal-content { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; }
  .modal-large { max-width: 100vw; }

  /* Admin table scroll */
  .admin-body { padding: 12px; }
  .admin-table { display: block; overflow-x: auto; white-space: nowrap; }
  .admin-toolbar { flex-direction: column; }
  .admin-toolbar input, .admin-toolbar select { width: 100%; }

  /* Token alert position */
  .token-alert { top: 8px; right: 44px; }

  /* Sidebar footer */
  .sidebar-footer { padding: 8px; }
  .layout-picker { gap: 2px; }
  .layout-btn { width: 24px; height: 24px; font-size: 12px; }
}

/* Landscape mobile: 2 columns */
@media (max-width: 768px) and (orientation: landscape) {
  .video-grid { grid-template-columns: 1fr 1fr !important; }
}
