/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0d0f14;
  --bg2: #13161e;
  --bg3: #1a1e2a;
  --surface: #1e2330;
  --surface2: #252a3a;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --text: #e8eaf0;
  --text2: #8b90a4;
  --text3: #555b70;
  --accent: #4f7fff;
  --accent2: #6c8fff;
  --red: #ff4b4b;
  --green: #22c55e;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --sidebar-w: 230px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --trans: 0.2s ease;
}
html { scroll-behavior: smooth; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; font-size: 14px; line-height: 1.5; }

/* ===== LOADING ===== */
.loading-overlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 9999; transition: opacity 0.3s; }
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loader-ring { width: 44px; height: 44px; border: 3px solid var(--surface2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 8888; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border2); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: 12px 16px; min-width: 260px; max-width: 340px; color: var(--text); font-size: 13px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; animation: slideIn 0.3s ease; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--yellow); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-msg { flex: 1; }
.toast-close { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 16px; padding: 0; line-height: 1; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== PAGES ===== */
.page { display: none; min-height: 100vh; }
.page.active { display: flex; }

/* ===== LOGIN ===== */
#page-login { flex-direction: column; align-items: center; justify-content: center; position: relative; overflow: hidden; background: var(--bg); }
.login-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.login-blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.15; }
.blob1 { width: 500px; height: 500px; background: radial-gradient(circle, #4f7fff, transparent); top: -100px; left: -100px; animation: blobMove 8s ease-in-out infinite alternate; }
.blob2 { width: 400px; height: 400px; background: radial-gradient(circle, #ff4444, transparent); bottom: -80px; right: -80px; animation: blobMove 10s ease-in-out infinite alternate-reverse; }
.blob3 { width: 300px; height: 300px; background: radial-gradient(circle, #a855f7, transparent); top: 50%; left: 50%; transform: translate(-50%,-50%); animation: blobMove 12s ease-in-out infinite alternate; }
@keyframes blobMove { 0% { transform: scale(1) translate(0,0); } 100% { transform: scale(1.1) translate(20px, -20px); } }
.login-card { position: relative; background: var(--surface); border: 1px solid var(--border2); border-radius: 20px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 24px 64px rgba(0,0,0,0.5); backdrop-filter: blur(20px); }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.logo-icon { width: 40px; height: 40px; background: rgba(255,68,68,0.15); border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.logo-icon svg { width: 28px; height: 28px; }
.logo-icon.sm { width: 32px; height: 32px; border-radius: 8px; }
.logo-icon.sm svg { width: 22px; height: 22px; }
.logo-text { font-size: 22px; font-weight: 700; color: var(--text); }
.logo-accent { color: var(--red); }
.login-title { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.login-sub { color: var(--text2); font-size: 13px; margin-bottom: 28px; }
.login-form { display: flex; flex-direction: column; gap: 18px; }

/* ===== FORMS ===== */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text2); }
.required { color: var(--red); }
.input-wrap { position: relative; }
.input-wrap .input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text3); pointer-events: none; }
.input-wrap input, .input-wrap select { width: 100%; }
input[type="text"], input[type="password"], input[type="url"], input[type="datetime-local"], input[type="email"], select, textarea {
  width: 100%; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius-sm); color: var(--text); font-family: inherit; font-size: 14px; padding: 10px 12px; transition: border-color var(--trans), box-shadow var(--trans); outline: none;
}
.input-wrap input { padding-left: 38px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,127,255,0.15); }
input::placeholder { color: var(--text3); }
.eye-toggle { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--text3); padding: 4px; display: flex; }
.eye-toggle svg { width: 16px; height: 16px; }
.form-hint { font-size: 11px; color: var(--text3); margin-top: 2px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .col-full { grid-column: 1 / -1; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 18px; border: none; border-radius: var(--radius-sm); font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--trans); text-decoration: none; white-space: nowrap; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #6c8fff); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(79,127,255,0.35); }
.btn-danger { background: linear-gradient(135deg, var(--red), #ff7070); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-success { background: linear-gradient(135deg, #22c55e, #4ade80); color: #fff; }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border2); }
.btn-ghost:hover { background: var(--bg3); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.btn-icon { padding: 7px; background: var(--surface2); border: 1px solid var(--border2); border-radius: var(--radius-sm); color: var(--text2); cursor: pointer; transition: all var(--trans); display: inline-flex; }
.btn-icon:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-icon svg { width: 14px; height: 14px; }

/* ===== SIDEBAR ===== */
.sidebar { width: var(--sidebar-w); min-height: 100vh; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; left: 0; top: 0; bottom: 0; z-index: 200; transition: transform var(--trans); }
.sidebar-header { padding: 20px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.sidebar-logo { display: flex; align-items: center; gap: 8px; }
.sidebar-close { display: none; background: none; border: none; color: var(--text3); cursor: pointer; }
.sidebar-close svg { width: 18px; height: 18px; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text2); text-decoration: none; font-size: 13px; font-weight: 500; transition: all var(--trans); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: rgba(79,127,255,0.15); color: var(--accent); }
.nav-item.active svg { color: var(--accent); }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar { width: 32px; height: 32px; background: linear-gradient(135deg, var(--accent), #a855f7); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; }
.user-details { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text3); text-transform: capitalize; }
.btn-logout { background: none; border: none; color: var(--text3); cursor: pointer; padding: 6px; border-radius: var(--radius-sm); transition: all var(--trans); display: flex; }
.btn-logout:hover { background: rgba(255,75,75,0.15); color: var(--red); }
.btn-logout svg { width: 16px; height: 16px; }

/* ===== MAIN CONTENT ===== */
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 58px; background: var(--bg2); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 100; }
.menu-toggle { display: none; background: none; border: none; color: var(--text2); cursor: pointer; }
.menu-toggle svg { width: 20px; height: 20px; }
.topbar-title { font-size: 16px; font-weight: 700; flex: 1; }
.server-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text3); }
.status-dot { width: 8px; height: 8px; background: var(--text3); border-radius: 50%; }
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.status-dot.offline { background: var(--red); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ===== VIEWS ===== */
.view { display: none; padding: 24px; }
.view.active { display: block; }

/* ===== STATS ===== */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; align-items: center; gap: 14px; transition: transform var(--trans); }
.stat-card:hover { transform: translateY(-2px); }
.stat-icon { width: 42px; height: 42px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.blue { background: rgba(59,130,246,0.15); color: var(--blue); }
.stat-icon.green { background: rgba(34,197,94,0.15); color: var(--green); }
.stat-icon.yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.stat-icon.red { background: rgba(255,75,75,0.15); color: var(--red); }
.stat-info { display: flex; flex-direction: column; }
.stat-num { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text3); margin-top: 3px; }

/* ===== TABLE SECTION ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.section-title { font-size: 17px; font-weight: 700; }
.section-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text3); }
.search-box input { padding: 8px 12px 8px 32px; font-size: 13px; background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-sm); color: var(--text); width: 200px; }
.filter-select { padding: 8px 12px; font-size: 13px; background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-sm); color: var(--text); cursor: pointer; }

/* ===== DATA TABLE ===== */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 800px; }
.data-table th { padding: 12px 14px; font-size: 12px; font-weight: 600; color: var(--text3); text-align: left; border-bottom: 1px solid var(--border); background: var(--bg2); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.data-table td { padding: 13px 14px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.actions-cell { display: flex; gap: 6px; flex-wrap: nowrap; }
.stream-key-cell { font-family: 'Courier New', monospace; font-size: 11px; color: var(--text3); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-cell { max-width: 200px; }
.file-name { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.file-size { font-size: 11px; color: var(--text3); }
.empty-state { text-align: center; padding: 50px 20px !important; }
.empty-icon { font-size: 36px; margin-bottom: 8px; }
.empty-state p { color: var(--text3); font-size: 13px; }
.time-cell { white-space: nowrap; }
.time-date { font-size: 13px; color: var(--text); }
.time-repeat { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ===== STATUS BADGES ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.badge-running { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-running::before { background: var(--green); animation: pulse 2s infinite; }
.badge-scheduled { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-scheduled::before { background: var(--yellow); }
.badge-stopped { background: rgba(139,144,164,0.15); color: var(--text3); }
.badge-stopped::before { background: var(--text3); }
.badge-downloading { background: rgba(79,127,255,0.15); color: var(--accent); }
.badge-downloading::before { background: var(--accent); animation: pulse 1s infinite; }
.badge-error { background: rgba(255,75,75,0.15); color: var(--red); }
.badge-error::before { background: var(--red); }

/* ===== MODALS ===== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(4px); padding: 20px; }
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box { background: var(--surface); border: 1px solid var(--border2); border-radius: 16px; width: 100%; max-width: 580px; box-shadow: 0 32px 80px rgba(0,0,0,0.5); animation: slideUp 0.25s ease; max-height: 90vh; overflow-y: auto; }
.modal-box.modal-sm { max-width: 420px; }
.modal-box.modal-xs { max-width: 340px; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { padding: 20px 24px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text3); cursor: pointer; border-radius: var(--radius-sm); padding: 4px; transition: all var(--trans); display: flex; }
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-close svg { width: 18px; height: 18px; }
.modal-form { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-body { padding: 20px 24px; text-align: center; }
.confirm-icon { font-size: 40px; margin-bottom: 12px; }
.modal-footer { padding: 0 24px 20px; display: flex; justify-content: flex-end; gap: 10px; }

/* ===== SETTINGS ===== */
.settings-wrap { max-width: 640px; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.settings-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.settings-title svg { width: 18px; height: 18px; color: var(--accent); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .view { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .col-full { grid-column: 1; }
  .section-actions { flex-direction: column; align-items: stretch; }
  .search-box input { width: 100%; }
}
@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-num { font-size: 22px; }
  .login-card { padding: 28px 20px; }
}

/* ===== SYSTEM STATS BAR ===== */
.sys-stats-bar {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  flex-wrap: wrap;
}
.sys-stat-item {
  display: flex; flex-direction: column; align-items: center;
  padding: 0 8px; border-right: 1px solid var(--border);
  line-height: 1.3;
}
.sys-stat-item:last-child { border-right: none; }
.sys-stat-label {
  font-size: 9px; font-weight: 600; letter-spacing: 0.5px;
  color: var(--text3); text-transform: uppercase;
}
.sys-stat-val {
  font-size: 11px; font-weight: 700; color: var(--accent2);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 900px) { .sys-stats-bar { display: none; } }
