:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --panel-2: #1a2340;
  --border: #253156;
  --text: #e6ecff;
  --muted: #93a1c8;
  --primary: #4f7cff;
  --primary-hover: #3c69ec;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Login */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 250px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.main {
  flex: 1;
  padding: 26px 32px;
  max-width: 1400px;
  width: 100%;
  overflow-x: hidden;
}

.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #ff3b5c, #ff6b35);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: #fff;
}
.brand-title { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-btn:hover { background: var(--panel-2); color: var(--text); }
.nav-btn.active {
  background: rgba(79, 124, 255, 0.16);
  border-color: rgba(79, 124, 255, 0.4);
  color: #fff;
}
.sidebar-footer { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }

/* Tabs */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-header h2 { margin: 0 0 4px 0; font-size: 24px; }
.page-header p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards & Grids */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.card-header h3, .card h3 { margin: 0; font-size: 16px; }
.card h4 { margin: 4px 0; font-size: 15px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}
.channel-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.channel-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.channel-meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.monitor-box {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { max-width: 240px; }

/* Form controls */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field span { color: var(--muted); font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], input[type="file"], select, textarea {
  width: 100%;
  background: #0d1326;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.code-input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.checkbox-row input { width: auto; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--primary); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.28); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-green { background: rgba(34, 197, 94, 0.15); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.35); }
.badge-blue { background: rgba(79, 124, 255, 0.16); color: #93c5fd; border: 1px solid rgba(79, 124, 255, 0.4); }
.badge-yellow { background: rgba(245, 158, 11, 0.16); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.4); }
.badge-red { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); }
.badge-gray { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.3); }

.status-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.hint-box {
  background: #0d1326; border: 1px dashed var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 12px; overflow-x: auto;
}
.divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
code { background: rgba(255,255,255,0.06); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
a { color: #93c5fd; }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: rgba(239,68,68,0.16); border: 1px solid rgba(239,68,68,0.4); color: #fecaca; }

/* Modals */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 8, 18, 0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 18px; z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%; max-width: 600px;
  max-height: 92vh; overflow-y: auto;
  padding: 20px;
}
.modal-lg { max-width: 720px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Toasts */
#toast-container {
  position: fixed; top: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  padding: 12px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.4);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 18px; }
}
