/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #1a1d27;
  --bg3:       #22263a;
  --border:    #2e3250;
  --text:      #e2e8f0;
  --text-muted:#8892b0;
  --blue:      #3b82f6;
  --blue-dim:  #1d4ed8;
  --green:     #22c55e;
  --green-dim: #166534;
  --yellow:    #f59e0b;
  --yellow-dim:#78350f;
  --red:       #ef4444;
  --red-dim:   #7f1d1d;
  --radius:    10px;
  --sidebar:   220px;
  --trans:     0.18s ease;
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; background: var(--bg); color: var(--text); }

/* ── Layout ────────────────────────────────────────────────── */
body { display: flex; }

main {
  margin-left: var(--sidebar);
  flex: 1;
  padding: 32px 36px;
  min-height: 100vh;
  overflow-y: auto;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar);
  height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0 20px;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 28px;
  border-bottom: 1px solid var(--border);
}
.logo-text { font-size: 17px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }

.nav-links { list-style: none; padding: 16px 10px; flex: 1; }
.nav-links li { margin-bottom: 2px; }
.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: background var(--trans), color var(--trans);
}
.nav-links a:hover { background: var(--bg3); color: var(--text); }
.nav-links a.active { background: #1e3a5f; color: var(--blue); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px 12px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  margin: 0 10px 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.sidebar-user-info { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.sidebar-username { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-role { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.role-admin  { color: var(--blue); }
.role-viewer { color: var(--text-muted); }

.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color var(--trans), background var(--trans);
}
.btn-logout:hover { color: var(--red); background: var(--bg2); }
.live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.4s;
}
.live-dot.connected   { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.live-dot.error       { background: var(--red); }
.live-label { font-size: 11px; color: var(--text-muted); }

@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.4; }
}

/* ── Page ──────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-subtitle   { color: var(--text-muted); font-size: 13px; }

/* ── Stats ─────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  border-left: 4px solid var(--border);
  transition: transform var(--trans);
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card.ok      { border-left-color: var(--green); }
.stat-card.warning { border-left-color: var(--yellow); }
.stat-card.error   { border-left-color: var(--red); }
.stat-card.neutral { border-left-color: var(--blue); }

.stat-value { font-size: 32px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.stat-card.ok      .stat-value { color: var(--green); }
.stat-card.warning .stat-value { color: var(--yellow); }
.stat-card.error   .stat-value { color: var(--red); }
.stat-card.neutral .stat-value { color: var(--blue); }

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Section title ─────────────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ── URL Grid (dashboard cards) ────────────────────────────── */
.url-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.url-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  border-left: 4px solid var(--border);
  transition: border-color var(--trans), transform var(--trans);
}
.url-card:hover { transform: translateY(-1px); }
.url-card.ok      { border-left-color: var(--green); }
.url-card.warning { border-left-color: var(--yellow); }
.url-card.error   { border-left-color: var(--red); }
.url-card.pending { border-left-color: var(--text-muted); }

.url-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.url-card-name { font-weight: 600; font-size: 15px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.badge-ok      { background: #14532d; color: var(--green); }
.badge-warning { background: #451a03; color: var(--yellow); }
.badge-error   { background: var(--red-dim); color: #fca5a5; }
.badge-pending { background: var(--bg3); color: var(--text-muted); }
.badge-muted   { background: #1e1e2e; color: var(--text-muted); border: 1px solid var(--border); }

.url-card-url {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
  margin-bottom: 12px;
}
.url-card-url a { color: var(--blue); text-decoration: none; }
.url-card-url a:hover { text-decoration: underline; }

.url-card-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.url-card-meta span strong { color: var(--text); }

.url-card-checked {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.url-card-checked strong { color: var(--text); }

.url-card-errors {
  margin-top: 10px;
  font-size: 12px;
  color: #fca5a5;
  background: rgba(239,68,68,0.08);
  border-radius: 6px;
  padding: 8px 10px;
  line-height: 1.5;
}

.url-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ── Skeleton ─────────────────────────────────────────────── */
.skeleton-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 140px;
  animation: shimmer 1.5s infinite linear;
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Data Table ───────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--bg3);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  font-size: 13px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.td-loading { text-align: center; color: var(--text-muted); padding: 32px !important; }

.url-cell { max-width: 240px; }
.url-cell a { color: var(--blue); text-decoration: none; word-break: break-all; font-size: 12px; }
.url-cell a:hover { text-decoration: underline; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--trans), transform var(--trans);
  line-height: 1;
}
.btn:hover { opacity: 0.85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary   { background: var(--blue); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--red-dim); color: #fca5a5; border: 1px solid #7f1d1d; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-icon-only { padding: 6px 8px; }

.btn-check { background: #0d2d1f; color: var(--green); border: 1px solid var(--green-dim); }
.btn-check.loading { opacity: 0.5; pointer-events: none; }

/* ── Toggle ─────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px; height: 20px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg3);
  border-radius: 20px;
  border: 1px solid var(--border);
  transition: background var(--trans);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; top: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--trans), background var(--trans);
}
.toggle input:checked + .toggle-slider { background: #1e3a5f; border-color: var(--blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: var(--blue); }

/* Mute toggle — amber when ON (muted) */
.toggle input:checked + .toggle-slider-mute { background: #451a03; border-color: var(--yellow); }
.toggle input:checked + .toggle-slider-mute::before { transform: translateX(16px); background: var(--yellow); }

.toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: default;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 520px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 28px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 5px;
}
.modal-close:hover { background: var(--bg3); color: var(--text); }

.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-group .required { color: var(--red); }
.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color var(--trans);
}
.form-group input:focus,
.form-group select:focus { border-color: var(--blue); }
.form-group small { display: block; margin-top: 5px; font-size: 11px; color: var(--text-muted); }

.form-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--blue);
}
.form-divider::before,
.form-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ── Toast ───────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  animation: slideIn 0.25s ease;
  max-width: 320px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast.success { background: #166534; border: 1px solid var(--green); }
.toast.error   { background: var(--red-dim); border: 1px solid var(--red); }
.toast.info    { background: var(--blue-dim); border: 1px solid var(--blue); }
@keyframes slideIn { from { opacity:0; transform: translateX(30px); } to { opacity:1; transform: translateX(0); } }

/* ── Incident Popups ─────────────────────────────────────── */
#incident-popups {
  position: fixed;
  top: 20px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
  max-width: 380px;
  pointer-events: none;
}

.incident-popup {
  pointer-events: all;
  background: #1a0a0a;
  border: 1.5px solid var(--red);
  border-left: 5px solid var(--red);
  border-radius: 10px;
  padding: 14px 16px 14px 18px;
  box-shadow: 0 0 0 1px rgba(239,68,68,0.15), 0 8px 32px rgba(0,0,0,0.6);
  animation: popupSlideIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
  position: relative;
  overflow: hidden;
}

.incident-popup.warning {
  background: #1a1200;
  border-color: var(--yellow);
  border-left-color: var(--yellow);
  box-shadow: 0 0 0 1px rgba(245,158,11,0.15), 0 8px 32px rgba(0,0,0,0.6);
}

.incident-popup.recovery {
  background: #0a1a0e;
  border-color: var(--green);
  border-left-color: var(--green);
  box-shadow: 0 0 0 1px rgba(34,197,94,0.15), 0 8px 32px rgba(0,0,0,0.6);
}

.incident-popup::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--red) 0%, transparent 100%);
  animation: popupProgress 8s linear forwards;
}
.incident-popup.warning::before { background: linear-gradient(90deg, var(--yellow) 0%, transparent 100%); }
.incident-popup.recovery::before { background: linear-gradient(90deg, var(--green) 0%, transparent 100%); animation: none; }

@keyframes popupProgress {
  from { width: 100%; } to { width: 0%; }
}

.incident-popup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.incident-popup-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--red);
}
.incident-popup.warning .incident-popup-title { color: var(--yellow); }
.incident-popup.recovery .incident-popup-title { color: var(--green); }

.incident-popup-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  animation: popupIconPulse 1s ease-in-out infinite;
}
.incident-popup.recovery .incident-popup-icon { animation: none; }

@keyframes popupIconPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.7; transform: scale(1.15); }
}

.incident-popup-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
  transition: color var(--trans);
}
.incident-popup-close:hover { color: var(--text); }

.incident-popup-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.incident-popup-url {
  font-size: 11.5px;
  color: var(--text-muted);
  word-break: break-all;
  margin-bottom: 6px;
}

.incident-popup-errors {
  font-size: 12px;
  color: #fca5a5;
  background: rgba(239,68,68,0.08);
  border-radius: 5px;
  padding: 6px 8px;
  margin-top: 4px;
}
.incident-popup.warning .incident-popup-errors {
  color: #fde68a;
  background: rgba(245,158,11,0.08);
}

.incident-popup-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

@keyframes popupSlideIn {
  from { opacity: 0; transform: translateX(60px) scale(0.9); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes popupSlideOut {
  from { opacity: 1; transform: translateX(0) scale(1); max-height: 200px; margin-bottom: 0; }
  to   { opacity: 0; transform: translateX(60px) scale(0.9); max-height: 0; margin-bottom: -12px; }
}

.incident-popup.dismissing {
  animation: popupSlideOut 0.25s ease forwards;
}

/* ── Notification Permission Banner ─────────────────────── */
#notif-banner {
  position: fixed;
  bottom: 0;
  left: var(--sidebar);
  right: 0;
  background: #1a1d27;
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 8000;
  font-size: 13px;
  color: var(--text);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

#notif-banner span { flex: 1; }

#notif-allow-btn {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--trans);
}
#notif-allow-btn:hover { background: var(--blue-dim); }

#notif-deny-btn {
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--trans);
}
#notif-deny-btn:hover { color: var(--text); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  :root { --sidebar: 0px; }
  .sidebar { display: none; }
  main { padding: 20px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  #notif-banner { left: 0; flex-wrap: wrap; }
  #incident-popups { top: 12px; right: 12px; max-width: calc(100vw - 24px); }
}
