/* ========== RESET & BASE ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-hover: #f3f4f6;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --info: #3b82f6;
  --info-bg: #dbeafe;
  --critical: #dc2626;
  --critical-bg: #fecaca;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --sidebar-w: 240px;
}

.hidden { display: none !important; }

/* ========== LOGIN ========== */
.login-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: linear-gradient(135deg, #eff6ff 0%, #f5f3ff 100%);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  font-size: 12px; font-weight: 600; letter-spacing: 0.1em;
  color: var(--primary); margin-bottom: 16px;
}
.login-card h1 {
  font-size: 24px; font-weight: 600; margin-bottom: 8px;
}
.login-subtitle {
  color: var(--text-secondary); margin-bottom: 32px;
}
#login-form input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; margin-bottom: 12px;
  transition: border 0.15s;
}
#login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
#login-form button {
  width: 100%; margin-top: 4px;
}
.login-error {
  margin-top: 12px; color: var(--danger);
  font-size: 13px; min-height: 20px;
}

/* ========== APP LAYOUT ========== */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 18px 20px;
  font-weight: 600; font-size: 15px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.logo-mark {
  width: 24px; height: 24px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 6px;
  display: inline-block;
}

.sidebar-nav {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active { background: var(--info-bg); color: var(--primary); }
.nav-icon { font-size: 14px; }

.sidebar-sites {
  flex: 1; overflow-y: auto;
  padding: 12px 10px;
}
.sidebar-section-title {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  padding: 4px 12px 8px;
}
.site-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 2px;
}
.site-link:hover { background: var(--surface-hover); color: var(--text); }
.site-link.active { background: var(--info-bg); color: var(--primary); font-weight: 500; }
.site-link-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-link-badge {
  font-size: 11px; padding: 2px 6px;
  border-radius: 10px;
  background: var(--border);
  color: var(--text-secondary);
}
.site-link-badge.critical { background: var(--critical-bg); color: var(--critical); }
.site-link-badge.warning { background: var(--warning-bg); color: var(--warning); }

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

/* ========== MAIN ========== */
.main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 56px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.breadcrumb {
  font-size: 13px; color: var(--text-secondary);
}
.breadcrumb .crumb { color: var(--text); font-weight: 500; }
.breadcrumb .sep { margin: 0 8px; color: var(--text-tertiary); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.refresh-indicator {
  font-size: 12px; color: var(--text-tertiary);
}

.content {
  flex: 1; overflow-y: auto;
  padding: 24px 32px;
}

/* ========== BUTTONS ========== */
.btn, .btn-ghost {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn:hover { background: var(--surface-hover); }
.btn-primary {
  background: var(--primary); color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { filter: brightness(0.95); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(0.95); }
.btn-ghost {
  background: transparent; border: none;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== PORTFOLIO ========== */
.page-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 20px;
}
.page-title {
  font-size: 22px; font-weight: 600;
}
.page-subtitle { color: var(--text-secondary); font-size: 13px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-tertiary);
  font-weight: 600; margin-bottom: 6px;
}
.stat-value {
  font-size: 24px; font-weight: 600; color: var(--text);
}
.stat-value-small { font-size: 18px; }

.portfolio-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%; border-collapse: collapse;
}
th, td {
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
}
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--surface-hover); }

.site-name-cell {
  display: flex; flex-direction: column; gap: 2px;
}
.site-name-cell .name { font-weight: 500; color: var(--text); }
.site-name-cell .domain { font-size: 12px; color: var(--text-tertiary); }

.score-cell {
  display: flex; align-items: center; gap: 8px;
}
.score-value { font-weight: 600; font-size: 15px; }
.score-delta {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
}
.score-delta.up { background: var(--success-bg); color: var(--success); }
.score-delta.down { background: var(--danger-bg); color: var(--danger); }
.score-delta.stable { background: var(--border); color: var(--text-secondary); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 11px; font-weight: 500;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-performant { background: var(--success-bg); color: var(--success); }
.badge-degraded { background: var(--warning-bg); color: var(--warning); }
.badge-critical { background: var(--critical-bg); color: var(--critical); }
.badge-unknown { background: var(--border); color: var(--text-secondary); }

.badge-priority-critical { background: var(--critical-bg); color: var(--critical); }
.badge-priority-high { background: var(--warning-bg); color: var(--warning); }
.badge-priority-medium { background: var(--info-bg); color: var(--info); }
.badge-priority-low { background: var(--border); color: var(--text-secondary); }

.badge-status-pending { background: var(--warning-bg); color: var(--warning); }
.badge-status-approved { background: var(--info-bg); color: var(--info); }
.badge-status-executed { background: var(--success-bg); color: var(--success); }
.badge-status-failed { background: var(--critical-bg); color: var(--critical); }
.badge-status-rejected { background: var(--border); color: var(--text-secondary); }

.alerts-cell { display: flex; gap: 4px; align-items: center; }
.alert-dot {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 500;
}
.alert-dot.critical { background: var(--critical-bg); color: var(--critical); }
.alert-dot.warning { background: var(--warning-bg); color: var(--warning); }
.alert-dot.info { background: var(--info-bg); color: var(--info); }

.running-indicator {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--primary); font-size: 12px; font-weight: 500;
}
.running-indicator::before {
  content: ''; width: 6px; height: 6px;
  background: var(--primary); border-radius: 50%;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ========== SITE DETAIL ========== */
.site-header {
  margin-bottom: 24px;
}
.site-header h1 {
  font-size: 22px; margin-bottom: 4px;
}
.site-header .meta {
  font-size: 13px; color: var(--text-secondary);
  display: flex; gap: 12px;
}
.site-header .meta a { color: var(--primary); text-decoration: none; }
.site-header .meta a:hover { text-decoration: underline; }

.site-actions {
  display: flex; gap: 8px; margin-bottom: 20px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.kpi-label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-tertiary);
  font-weight: 600; margin-bottom: 8px;
}
.kpi-value {
  font-size: 28px; font-weight: 600;
}
.kpi-sub {
  margin-top: 4px;
  font-size: 12px; color: var(--text-secondary);
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.chart-card h3 {
  font-size: 15px; font-weight: 600; margin-bottom: 16px;
}
.chart-container {
  position: relative; height: 240px;
}

.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px; font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-count {
  display: inline-block; margin-left: 6px;
  padding: 1px 7px;
  background: var(--border);
  color: var(--text-secondary);
  border-radius: 10px;
  font-size: 11px;
}
.tab.active .tab-count {
  background: var(--info-bg); color: var(--primary);
}

.filters-row {
  display: flex; gap: 8px; margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px; font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.filter-chip:hover { border-color: var(--border-strong); }
.filter-chip.active {
  background: var(--info-bg);
  color: var(--primary);
  border-color: var(--primary);
}

.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
}
.action-card-header {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.action-type {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--surface-hover);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--text);
}
.action-target {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11px; color: var(--text-tertiary);
  margin-left: auto;
}
.action-field {
  margin-bottom: 8px;
}
.action-field-label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-tertiary);
  font-weight: 600; margin-bottom: 3px;
}
.action-field-value {
  font-size: 13px; color: var(--text);
  line-height: 1.5;
}
.action-field-value.current {
  padding: 8px 10px;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--text-tertiary);
}
.action-field-value.proposed {
  padding: 8px 10px;
  background: var(--info-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}
.action-buttons {
  display: flex; gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state-icon {
  font-size: 40px; margin-bottom: 12px;
  opacity: 0.4;
}
.empty-state-title {
  font-size: 16px; font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.report-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.report-row-main { flex: 1; }
.report-row-date { font-weight: 500; font-size: 13px; }
.report-row-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.alert-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
}
.alert-row.critical { border-left-color: var(--critical); }
.alert-row.warning { border-left-color: var(--warning); }
.alert-row.info { border-left-color: var(--info); }
.alert-row-header {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 4px;
}
.alert-row-type { font-weight: 500; font-size: 13px; }
.alert-row-msg { font-size: 13px; color: var(--text); }
.alert-row-date { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }

/* ========== MODAL ========== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close {
  background: transparent; border: none;
  font-size: 24px; line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-body textarea, .modal-body select, .modal-body input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  margin-bottom: 12px;
  resize: vertical;
}
.modal-body textarea:focus, .modal-body select:focus, .modal-body input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.modal-body label {
  display: block; font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px; font-weight: 500;
}
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ========== TOAST ========== */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease-out;
  min-width: 200px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ========== LOADING ========== */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 40px; color: var(--text-secondary);
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== UTILITIES ========== */
.text-muted { color: var(--text-secondary); }
.text-small { font-size: 12px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
