:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #192235;
  --surface-hover: #1f2a40;
  --border: #263248;
  --text: #e6ecf5;
  --muted: #8b9bb4;
  --primary: #4f7cff;
  --primary-hover: #3b66e8;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.14);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.14);
  --blue-bg: rgba(79, 124, 255, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

/* Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px 22px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #ff3b5c, #ff7b00);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  box-shadow: 0 6px 18px rgba(255, 59, 92, 0.3);
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--blue-bg);
  color: #93b4ff;
  font-weight: 600;
}

.nav-label { flex: 1; }

.nav-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text);
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: #8fb0ff; }

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 6px;
}

.sidebar-footer {
  padding: 12px 10px 0;
  border-top: 1px solid var(--border);
}

.local-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
}

.dot-online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.footer-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px 28px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 22px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-hover); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 6px;
}

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

/* Cards & KPIs */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.card-header h3 { font-size: 15px; font-weight: 600; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
}

.list-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* Toolbar & Filters */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  flex: 1;
  min-width: 260px;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  width: 100%;
  font-size: 13px;
}

.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

select, input, textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
}

/* Data Table */
.table-wrap {
  padding: 0;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

.data-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

.ch-identity {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.ch-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}

.ch-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ch-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.ch-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.copy-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 3px;
}

.copy-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 1px 4px;
  border-radius: 4px;
}
.copy-btn:hover { background: var(--surface-2); color: var(--text); }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  margin: 2px 3px 2px 0;
}

/* Progress bars */
.prog-block { margin-bottom: 6px; min-width: 170px; }
.prog-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}
.prog-label strong { color: var(--text); }
.prog-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.3s ease;
}
.prog-fill.done { background: var(--green); }
.prog-fill.warn { background: var(--amber); }

.row-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 50px 20px;
}
.empty-icon { font-size: 38px; margin-bottom: 8px; }
.empty-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.empty-sub { font-size: 13px; color: var(--muted); }

/* AdSense Grid */
.adsense-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.adsense-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Settings Grid */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px;
}

.settings-grid h3 { margin-bottom: 8px; font-size: 16px; }
.settings-grid .muted { margin-bottom: 14px; display: block; }

.guide-list {
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.guide-list b { color: var(--text); }

.info-pill {
  background: var(--blue-bg);
  border: 1px solid rgba(79, 124, 255, 0.3);
  color: #a7c0ff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.modal-lg { max-width: 780px; }
.modal-sm { max-width: 460px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 17px; }

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.modal-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.modal-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 12px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.modal-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.mtab-panel { display: none; }
.mtab-panel.active { display: block; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-row.three-col {
  grid-template-columns: 1fr 1fr 1fr;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.inline-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .form-row, .form-row.three-col { grid-template-columns: 1fr; }
}
