:root {
  --bg: #0f1117;
  --bg2: #1a1d2e;
  --bg3: #252840;
  --border: #2e3250;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --font: 'Inter', system-ui, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 { font-size: 16px; font-weight: 700; color: var(--accent); }
.sidebar-logo span { font-size: 11px; color: var(--text-muted); }

.sidebar-nav { flex: 1; padding: 12px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  transition: background .15s, color .15s;
  user-select: none;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-status {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.status-dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; background: var(--success);
  margin-right: 6px; vertical-align: middle;
}
.status-dot.offline { background: var(--danger); }

.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h2 { font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.content { padding: 24px; flex: 1; }

/* ── Components ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.kpi-card .kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.kpi-card .kpi-value { font-size: 24px; font-weight: 700; }
.kpi-card .kpi-value.green { color: var(--success); }
.kpi-card .kpi-value.blue { color: var(--accent); }
.kpi-card .kpi-value.orange { color: var(--warning); }

/* ── Table ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
th {
  background: var(--bg3);
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .5px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
th:hover { color: var(--text); }
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg3); }
.td-truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Filters ── */
.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

/* ── Forms ── */
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=url], input[type=password], textarea, select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  width: 100%;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg2); }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: .3px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-active { background: rgba(34,197,94,.15); color: var(--success); }
.badge-inactive { background: rgba(107,114,128,.15); color: var(--text-muted); }
.badge-high { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-medium { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-low { background: rgba(34,197,94,.15); color: var(--success); }
.badge-sent { background: rgba(59,130,246,.15); color: var(--accent); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%; max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  position: relative;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Detail Panel ── */
.detail-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  display: none;
}
.detail-panel.open { display: block; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.detail-item label { font-size: 11px; color: var(--text-muted); font-weight: 600; display: block; margin-bottom: 3px; }
.detail-item p { font-size: 14px; }

.analysis-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}
.analysis-box h4 { font-size: 13px; font-weight: 700; margin-bottom: 10px; color: var(--accent); }
.analysis-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.analysis-item label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 2px; }
.analysis-item span { font-size: 14px; font-weight: 600; }

/* ── Score Bar ── */
.score-bar { display: flex; align-items: center; gap: 8px; }
.score-track {
  height: 6px; background: var(--bg3); border-radius: 3px;
  flex: 1; overflow: hidden;
}
.score-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.score-fill.high { background: var(--success); }
.score-fill.medium { background: var(--warning); }
.score-fill.low { background: var(--danger); }

/* ── Warning Cards ── */
.warning-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
  background: var(--bg2);
  border-left-width: 4px;
}
.warning-card.active { border-left-color: var(--danger); }
.warning-card.inactive { border-left-color: var(--text-muted); opacity: .7; }
.warning-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.warning-card-title { font-weight: 600; font-size: 15px; }
.warning-card-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.warning-card-body { margin-top: 8px; font-size: 13px; color: var(--text-muted); }

/* ── News Cards ── */
.news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.news-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.news-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.news-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.news-card-title { font-weight: 600; font-size: 14px; line-height: 1.4; }
.news-card-source { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.news-card-excerpt { font-size: 12px; color: var(--text-muted); line-height: 1.4; margin-bottom: 10px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.news-card-footer { display: flex; justify-content: space-between; align-items: center; }

/* ── Toast ── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 240px;
  max-width: 360px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slide-in .2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slide-in { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Settings ── */
.settings-section { margin-bottom: 28px; }
.settings-section h3 { font-size: 14px; font-weight: 700; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.toggle-row label { font-size: 14px; }
.toggle {
  position: relative; width: 40px; height: 22px;
  background: var(--bg3); border-radius: 11px; cursor: pointer;
  transition: background .2s;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff; border-radius: 50%;
  transition: transform .2s;
}
.toggle.on::after { transform: translateX(18px); }

.color-input-wrap { display: flex; gap: 8px; align-items: center; }
.color-swatch {
  width: 36px; height: 36px; border-radius: var(--radius);
  border: 1px solid var(--border); cursor: pointer;
  overflow: hidden; padding: 0;
}
.color-swatch input[type=color] { width: 100%; height: 100%; border: none; cursor: pointer; padding: 0; }

/* ── Pagination ── */
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: flex-end; }
.page-btn {
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg2); color: var(--text);
  cursor: pointer; font-size: 13px;
}
.page-btn:hover { background: var(--bg3); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Empty State ── */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── Loading ── */
.loading { display: flex; justify-content: center; padding: 40px; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login Overlay ── */
#auth-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #0f1117 0%, #1a1d2e 100%);
  display: none;
  align-items: center; justify-content: center;
  z-index: 99999;
}
#auth-overlay.open { display: flex; }
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--accent);
}
.auth-card .auth-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}
.auth-card .auth-error {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.auth-card .auth-error.show { display: block; }
.auth-card button[type=submit] {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  font-size: 14px;
}
.auth-card .auth-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 14px;
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-logo h1, .sidebar-logo span, .nav-item span, .sidebar-status { display: none; }
  .main { margin-left: 60px; }
  .form-row, .form-row-3, .detail-grid, .analysis-grid { grid-template-columns: 1fr; }
  .news-grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
}
