* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0d1117; color: #e1e4e8; display: flex; flex-direction: column; min-height: 100vh; }

/* ── Toast Notifications ── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 10px; font-size: 13px; font-weight: 500; color: #f0f6fc; background: #1c2128; border: 1px solid #30363d; box-shadow: 0 8px 24px rgba(0,0,0,0.4); pointer-events: all; animation: toastIn .25s ease; max-width: 320px; }
.toast.success { border-color: #238636; background: #0d2119; }
.toast.error { border-color: #da3633; background: #200e0e; }
.toast.info { border-color: #1f6feb; background: #0c1824; }
.toast .toast-icon { font-size: 16px; flex-shrink: 0; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ── Login ── */
.login-page { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 100vh; }
.login-box { background: #161b22; border: 1px solid #30363d; border-radius: 16px; padding: 48px 40px; width: 380px; text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.login-box h1 { font-size: 28px; color: #f0f6fc; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: #8b949e; margin-bottom: 28px; }
.login-box input { display: block; width: 100%; padding: 10px 14px; margin-bottom: 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; color: #e1e4e8; font-size: 14px; transition: border-color .2s; }
.login-box input:focus { outline: none; border-color: #58a6ff; box-shadow: 0 0 0 3px rgba(88,166,255,0.15); }
.btn-login { width: 100%; padding: 11px; background: linear-gradient(135deg,#238636,#2ea043); color: #fff; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(35,134,54,0.4); }
.login-error { color: #f85149; font-size: 13px; margin-top: 12px; min-height: 20px; }

/* ── Top Bar ── */
.topbar { display: flex; align-items: center; padding: 0 20px; height: 52px; background: #161b22; border-bottom: 1px solid #21262d; flex-shrink: 0; }
.topbar-brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; min-width: 140px; }
.brand-icon { font-size: 20px; color: #58a6ff; }
.brand-title { font-size: 15px; font-weight: 700; color: #f0f6fc; line-height: 1.2; }
.brand-sub { font-size: 9px; color: #8b949e; text-transform: uppercase; letter-spacing: 1px; }

.topbar-user { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }
.user-label { font-size: 13px; color: #8b949e; }
.sub-badge { font-size: 10px; padding: 2px 8px; border-radius: 4px; background: #1c2128; color: #8b949e; white-space: nowrap; border: 1px solid #30363d; }

/* ── Top Nav ── */
.topnav { flex: 1; display: flex; justify-content: center; min-width: 0; overflow: hidden; }
.nav-links { list-style: none; display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-links li a { display: block; padding: 0 16px; height: 52px; line-height: 52px; color: #8b949e; text-decoration: none; font-size: 13px; font-weight: 500; border-bottom: 2px solid transparent; transition: color .2s, border-color .2s; white-space: nowrap; }
.nav-links li a:hover { color: #e1e4e8; }
.nav-links li.active a { color: #f0f6fc; border-bottom-color: #58a6ff; }

/* ── Main ── */
.main-content { flex: 1; padding: 28px 32px; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-content > h2 { font-size: 20px; font-weight: 700; color: #f0f6fc; margin-bottom: 20px; }

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 32px; }
.stat-card { background: #161b22; border: 1px solid #21262d; border-radius: 12px; padding: 20px 16px; text-align: center; transition: transform .2s, border-color .2s, box-shadow .2s; cursor: default; }
.stat-card:hover { transform: translateY(-3px); border-color: #30363d; box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.stat-card .stat-value { font-size: 30px; font-weight: 700; color: #58a6ff; }
.stat-card .stat-label { font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: .5px; margin-top: 6px; }
.stat-card.loading .stat-value { color: #30363d; animation: pulse 1.2s ease infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ── Toolbar ── */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar input[type="text"],
.toolbar input[type="password"],
.toolbar input[type="number"],
.toolbar select {
  padding: 8px 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; color: #e1e4e8; font-size: 13px; transition: border-color .2s; height: 36px;
}
.toolbar input[type="text"]:focus,
.toolbar input[type="number"]:focus,
.toolbar select:focus { outline: none; border-color: #58a6ff; box-shadow: 0 0 0 3px rgba(88,166,255,0.12); }
.toolbar select { cursor: pointer; }
.toolbar input[type="file"] { color: #8b949e; font-size: 13px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 18px; height: 36px; background: linear-gradient(135deg,#238636,#2ea043); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; transition: transform .15s, box-shadow .15s, filter .15s, opacity .15s; white-space: nowrap; }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(35,134,54,0.35); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { background: linear-gradient(135deg,#da3633,#f85149); }
.btn-danger:hover:not(:disabled) { box-shadow: 0 4px 12px rgba(248,81,73,0.35); }
.btn-secondary { background: #21262d; color: #c9d1d9; border: 1px solid #30363d; }
.btn-secondary:hover:not(:disabled) { background: #30363d; box-shadow: none; transform: none; }
.btn-ghost { background: transparent; color: #8b949e; border: 1px solid transparent; padding: 0 12px; height: 32px; border-radius: 6px; font-size: 12px; transition: background .2s, color .2s; }
.btn-ghost:hover { background: #1c2128; color: #e1e4e8; box-shadow: none; transform: none; }
.btn-signout { color: #f85149; }
.btn-signout:hover { background: #2d1b1b; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn .spinner { width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Media Grid ── */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.media-card { background: #161b22; border: 1px solid #21262d; border-radius: 12px; overflow: hidden; position: relative; transition: transform .2s, border-color .2s, box-shadow .2s; display: flex; flex-direction: column; }
.media-card:hover { transform: translateY(-3px); border-color: #30363d; box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.media-card .media-preview-wrap { background: #0d1117; flex-shrink: 0; }
.media-card .media-preview { width: 100%; height: 140px; object-fit: cover; display: block; }
.media-card .media-info { padding: 10px 12px; flex: 1; }
.media-card .media-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-card .media-meta { font-size: 11px; color: #8b949e; margin-top: 2px; }
.media-card .media-actions { padding: 8px 12px; border-top: 1px solid #21262d; display: flex; gap: 6px; align-items: center; }
.media-card .media-type-badge { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,0.75); color: #e1e4e8; font-size: 10px; padding: 2px 8px; border-radius: 4px; text-transform: uppercase; backdrop-filter: blur(4px); }

/* ── Upload progress bar ── */
.upload-progress-wrap { width: 100%; margin-bottom: 8px; }
.upload-progress-bar { height: 3px; background: #21262d; border-radius: 2px; overflow: hidden; }
.upload-progress-fill { height: 100%; background: linear-gradient(90deg,#238636,#58a6ff); border-radius: 2px; transition: width .3s; }
.upload-progress-label { font-size: 11px; color: #8b949e; margin-top: 4px; }

/* ── List Cards ── */
#playlistList, #userList, #installerList { display: grid; gap: 10px; }
.list-card { background: #161b22; border: 1px solid #21262d; border-radius: 10px; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; transition: border-color .2s, box-shadow .2s; }
.list-card:hover { border-color: #30363d; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
.list-card .list-card-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.list-card .list-card-title { font-size: 15px; font-weight: 600; color: #f0f6fc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-card .list-card-meta { font-size: 12px; color: #8b949e; }
.list-card .list-card-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; flex-wrap: wrap; }

/* ── Screen Cards ── */
.screen-card { background: #161b22; border: 1px solid #21262d; border-radius: 12px; padding: 18px; margin-bottom: 10px; transition: border-color .2s, box-shadow .2s; }
.screen-card:hover { border-color: #30363d; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
.screen-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.screen-card-title { font-size: 15px; font-weight: 600; color: #f0f6fc; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.screen-card-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.screen-card-tag { font-size: 10px; padding: 2px 8px; border-radius: 4px; background: #1c2128; color: #8b949e; border: 1px solid #30363d; }
.screen-card-tag.group { border-color: #1f6feb; color: #79c0ff; }
.screen-card-tag.location { border-color: #238636; color: #3fb950; }
.screen-card-meta { font-size: 11px; color: #8b949e; white-space: nowrap; }
.screen-card-assign { font-size: 12px; color: #8b949e; margin-top: 6px; }

.screen-settings-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid #21262d; }
.screen-settings-row select { padding: 4px 10px; background: #0d1117; border: 1px solid #30363d; border-radius: 6px; color: #e1e4e8; font-size: 12px; height: 28px; cursor: pointer; transition: border-color .15s; }
.screen-settings-row select:focus { outline: none; border-color: #58a6ff; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.online { background: #3fb950; box-shadow: 0 0 0 2px rgba(63,185,80,0.25); }
.status-dot.offline { background: #484f58; }
.power-off-icon { font-size: 13px; color: #d29922; }

.toggle-label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; font-size: 12px; color: #8b949e; user-select: none; }
.toggle-label input[type="checkbox"] { width: 15px; height: 15px; accent-color: #238636; cursor: pointer; flex-shrink: 0; }
.sync-interval-input { width: 52px; padding: 3px 8px; background: #0d1117; border: 1px solid #30363d; border-radius: 6px; color: #e1e4e8; font-size: 12px; text-align: center; height: 28px; }

/* ── Modal ── */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal.open { display: flex; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content { background: #161b22; border: 1px solid #30363d; border-radius: 16px; width: 90%; max-width: 800px; max-height: 85vh; overflow-y: auto; padding: 28px; box-shadow: 0 16px 48px rgba(0,0,0,0.4); animation: modalSlide .2s ease; }
@keyframes modalSlide { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 17px; font-weight: 700; color: #f0f6fc; margin: 0; }
.close { font-size: 22px; cursor: pointer; color: #8b949e; transition: color .2s; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 6px; flex-shrink: 0; }
.close:hover { color: #f0f6fc; background: #21262d; }
.modal-body { display: flex; gap: 24px; }
.modal-media-list { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.modal-media-list .mini-card { width: 80px; height: 60px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 2px solid transparent; transition: border-color .15s, transform .15s, box-shadow .15s; }
.modal-media-list .mini-card:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.modal-media-list .mini-card.selected { border-color: #58a6ff; box-shadow: 0 0 0 2px rgba(88,166,255,0.2); }
.modal-playlist-items { flex: 1; min-width: 200px; }
.modal-playlist-items h4 { font-size: 14px; margin-bottom: 10px; color: #f0f6fc; }
.modal-playlist-items ul { list-style: none; }
.modal-playlist-items li { padding: 8px 0; border-bottom: 1px solid #21262d; font-size: 13px; color: #c9d1d9; }
.modal-empty { font-size: 13px; color: #8b949e; padding: 16px 0; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: #8b949e; margin-bottom: 5px; font-weight: 500; }
.form-group input, .form-group select { width: 100%; padding: 8px 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; color: #e1e4e8; font-size: 14px; transition: border-color .2s; height: 38px; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: #58a6ff; box-shadow: 0 0 0 3px rgba(88,166,255,0.12); }
.form-group select { cursor: pointer; }
.modal-footer { margin-top: 20px; display: flex; gap: 8px; justify-content: flex-end; }
.section-divider { margin: 18px 0; padding-top: 18px; border-top: 1px solid #30363d; }
.section-divider .form-group:first-child { margin-top: 0; }

/* ── Badges ── */
.badge-role { display: inline-block; font-size: 10px; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; font-weight: 700; letter-spacing: .3px; }
.badge-admin { background: #1f3a2e; color: #3fb950; }
.badge-viewer { background: #1c2541; color: #79c0ff; }

/* ── Location ── */
.location-group { margin-bottom: 28px; }
.location-group h3 { color: #f0f6fc; font-size: 16px; font-weight: 700; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid #21262d; }
.location-group h3 .loc-count { color: #8b949e; font-size: 13px; font-weight: 400; }
.location-subgroup { margin-left: 20px; margin-bottom: 14px; }
.location-subgroup h4 { color: #79c0ff; font-size: 14px; margin-bottom: 8px; }
.section-heading { font-size: 14px; font-weight: 600; color: #8b949e; text-transform: uppercase; letter-spacing: .6px; margin: 24px 0 12px; }

/* ── Empty / Loading states ── */
.highlight { background: rgba(31,111,235,0.15); border-radius: 4px; }
.no-results { text-align: center; color: #8b949e; padding: 48px 24px; font-size: 14px; }
.skeleton { background: linear-gradient(90deg, #161b22 25%, #1c2128 50%, #161b22 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* ── Device Cards ── */
.device-card { background: #161b22; border: 1px solid #30363d; border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
.device-card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: #1c2128; border-bottom: 1px solid #21262d; }
.device-card-name { font-size: 15px; font-weight: 600; color: #f0f6fc; }
.device-card-platform { font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 10px; }
.device-card-platform.android { background: rgba(60,175,100,0.15); color: #3caf64; }
.device-card-platform.webos { background: rgba(88,166,255,0.15); color: #58a6ff; }
.device-card-platform.tizen { background: rgba(210,153,34,0.15); color: #d29922; }
.device-card-platform.web { background: rgba(139,148,158,0.15); color: #8b949e; }
.device-card-body { padding: 14px 18px; }
.device-info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.device-info-item { display: flex; flex-direction: column; gap: 2px; }
.device-info-label { font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: .4px; }
.device-info-value { font-size: 14px; color: #e1e4e8; display: flex; align-items: center; gap: 6px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.status-on { background: #3fb950; box-shadow: 0 0 6px rgba(63,185,80,0.4); }
.status-dot.status-off { background: #484f58; }
.device-card-actions { display: flex; align-items: center; gap: 8px; padding: 10px 18px; border-top: 1px solid #21262d; }

/* ── Proof of Play ── */
.pop-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid #21262d; font-size: 13px; }
.pop-row:last-child { border-bottom: none; }
.pop-icon { font-size: 16px; width: 24px; text-align: center; }
.pop-media { flex: 1; font-weight: 500; color: #e1e4e8; }
.pop-event { font-size: 11px; padding: 2px 8px; border-radius: 6px; text-transform: uppercase; font-weight: 600; }
.pop-time { color: #8b949e; font-size: 12px; min-width: 140px; text-align: right; }
.pop-platform { color: #8b949e; font-size: 11px; min-width: 60px; text-align: right; }
.pop-started .pop-event { background: rgba(88,166,255,0.15); color: #58a6ff; }
.pop-completed .pop-event { background: rgba(63,185,80,0.15); color: #3fb950; }
.pop-error .pop-event { background: rgba(248,81,73,0.15); color: #f85149; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .topbar { padding: 0 12px; gap: 4px; height: 48px; }
  .topbar-brand .brand-sub { display: none; }
  .topbar-brand { min-width: unset; }
  .nav-links li a { padding: 0 10px; font-size: 12px; height: 48px; line-height: 48px; }
  .main-content { padding: 20px 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-body { flex-direction: column; }
  .topbar-user .btn-ghost { font-size: 11px; padding: 0 8px; height: 28px; }
  .sub-badge { display: none; }
  #toast-container { bottom: 16px; right: 16px; left: 16px; }
}