:root {
  --bg: #0c0f14;
  --bg-soft: #11151c;
  --card: #161b24;
  --card-hover: #1a2029;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e8ecf3;
  --text-dim: #9aa4b5;
  --text-faint: #66707f;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --ok: #34c98e;
  --ok-soft: rgba(52, 201, 142, 0.14);
  --warn: #f0b13c;
  --warn-soft: rgba(240, 177, 60, 0.14);
  --err: #f0564f;
  --err-soft: rgba(240, 86, 79, 0.14);
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(91, 140, 255, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; font-weight: 700; letter-spacing: 0.3px; }
.login-card h1 span { color: var(--accent); }
.login-sub { color: var(--text-dim); margin: 4px 0 22px; font-size: 13px; }
.login-card label {
  display: block;
  text-align: left;
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 14px;
}
.login-error { color: var(--err); font-size: 13px; margin-bottom: 12px; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-size: 16px; padding: 2px 10px 12px; border-bottom: 1px solid var(--border); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 9px;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav a:hover { background: var(--card); color: var(--text); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-footer { margin-top: auto; }

.main { flex: 1; padding: 26px 30px 60px; max-width: 1400px; min-width: 0; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h2 { font-size: 20px; font-weight: 700; }
.page-head .crumbs a { color: var(--text-dim); text-decoration: none; }
.page-head .crumbs a:hover { color: var(--accent); }

/* ---------- Cards / stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-card .k { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.stat-card .v { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-card .s { color: var(--text-faint); font-size: 12px; margin-top: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card h3 { font-size: 14px; margin-bottom: 12px; color: var(--text-dim); font-weight: 600; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--card-hover); }
tbody tr.clickable { cursor: pointer; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-url { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); font-size: 12px; }
.cell-main { font-weight: 600; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.badge-dim { background: rgba(255, 255, 255, 0.06); color: var(--text-dim); }

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  text-decoration: none;
}
.btn:hover { background: var(--card-hover); border-color: rgba(255, 255, 255, 0.22); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #6c99ff; border-color: #6c99ff; }
.btn-danger { color: var(--err); border-color: rgba(240, 86, 79, 0.4); }
.btn-danger:hover { background: var(--err-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: var(--card); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

input[type="text"], input[type="password"], input[type="url"], input[type="number"], select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13px;
  margin-top: 5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18); }

.search-input { max-width: 300px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Switch ---------- */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  transition: background 0.15s;
  cursor: pointer;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 6, 10, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px 16px;
  z-index: 50;
  animation: fadeIn 0.15s ease;
}
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: slideUp 0.18s ease;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 18px 20px; }
.modal-body label { display: block; color: var(--text-dim); font-size: 12px; margin-bottom: 13px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { color: var(--text-faint); font-size: 11px; margin-top: 3px; }
.check-line { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; margin-bottom: 13px; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 11px 16px;
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 360px;
  animation: slideUp 0.18s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }

/* ---------- Channels / programmes ---------- */
.split { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

.chan-list { max-height: 70vh; overflow-y: auto; }
.chan-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.chan-item:hover { background: var(--card-hover); }
.chan-item.active { background: var(--accent-soft); }
.chan-item .cid { font-weight: 600; font-size: 13px; }
.chan-item .cnames { color: var(--text-dim); font-size: 12px; margin-top: 1px; }
.chan-item .cmeta { color: var(--text-faint); font-size: 11px; margin-top: 2px; }

.prog-day-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.prog-day-nav .day-label { font-weight: 700; min-width: 150px; text-align: center; }
.prog-item { display: flex; gap: 14px; padding: 9px 6px; border-bottom: 1px solid var(--border); }
.prog-item:last-child { border-bottom: none; }
.prog-item.now { background: var(--accent-soft); border-radius: 8px; }
.prog-time { color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13px; padding-top: 1px; }
.prog-title { font-weight: 600; font-size: 13px; }
.prog-desc { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--text-dim); font-size: 12px; }

.empty {
  color: var(--text-faint);
  text-align: center;
  padding: 40px 20px;
  font-size: 13px;
}
.err-text { color: var(--err); font-size: 12px; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 14px; }
  .brand { border: none; padding: 0 10px; }
  .sidebar nav { flex-direction: row; }
  .sidebar-footer { margin: 0 0 0 auto; }
  .main { padding: 18px 14px 40px; }
}
