/* ================================================================
   Process Zero Command Center — Base Styles
   Dark theme, system fonts, CSS custom properties
   ================================================================ */

/* ── Custom Properties ── */
:root {
  /* Persona colors */
  --color-donna:   #6366f1;
  --color-marcus:  #10b981;
  --color-selene:  #f59e0b;
  --color-victor:  #3b82f6;
  --color-evelyn:  #8b5cf6;
  --color-nia:     #ec4899;
  --color-dante:   #ef4444;

  /* Theme colors */
  --bg-primary:    #0f172a;
  --bg-secondary:  #1e293b;
  --bg-card:       #1e293b;
  --bg-input:      #0f172a;
  --border-color:  #334155;
  --border-subtle: #1e293b;

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;

  /* Status colors */
  --status-healthy:  #10b981;
  --status-degraded: #f59e0b;
  --status-critical: #ef4444;

  /* Action colors */
  --btn-primary:   #3b82f6;
  --btn-primary-hover: #2563eb;
  --btn-approve:   #10b981;
  --btn-approve-hover: #059669;
  --btn-danger:    #ef4444;
  --btn-danger-hover:  #dc2626;
  --btn-secondary: #475569;
  --btn-secondary-hover: #64748b;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Typography ── */
h1 { font-size: 1.875rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.5rem; font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.4; }
h4 { font-size: 1.125rem; font-weight: 500; line-height: 1.4; }

a { color: var(--btn-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
  font-size: 0.875rem;
}

pre {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  overflow-x: auto;
}

/* ── Navigation ── */
.top-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 var(--space-lg);
  height: 3.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.nav-logo {
  font-weight: 800;
  font-size: 1rem;
  color: var(--btn-primary);
  background: rgba(59, 130, 246, 0.15);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.nav-title {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex: 1;
  overflow-x: auto;
}

.nav-link {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-link.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--btn-primary);
}

.nav-actions {
  flex-shrink: 0;
}

.nav-logout {
  color: var(--text-muted);
}

/* ── Layout ── */
.page-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-lg);
}

.page-header {
  margin-bottom: var(--space-xl);
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: var(--space-xs);
}

/* ── Grid ── */
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .top-nav { flex-wrap: wrap; height: auto; padding: var(--space-sm); gap: var(--space-sm); }
  .nav-links { order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-link { min-height: 44px; display: inline-flex; align-items: center; }
  .page-container { padding: var(--space-md); }
  .page-title { font-size: 1.25rem; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-color: var(--text-muted);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
}

/* Persona-colored card borders */
.card--donna  { border-left: 3px solid var(--color-donna); }
.card--marcus { border-left: 3px solid var(--color-marcus); }
.card--selene { border-left: 3px solid var(--color-selene); }
.card--victor { border-left: 3px solid var(--color-victor); }
.card--evelyn { border-left: 3px solid var(--color-evelyn); }
.card--nia    { border-left: 3px solid var(--color-nia); }
.card--dante  { border-left: 3px solid var(--color-dante); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  line-height: 1.5;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--btn-primary);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--btn-primary-hover); }

.btn-approve {
  background: var(--btn-approve);
  color: white;
}
.btn-approve:hover:not(:disabled) { background: var(--btn-approve-hover); }

.btn-danger {
  background: var(--btn-danger);
  color: white;
}
.btn-danger:hover:not(:disabled) { background: var(--btn-danger-hover); }

.btn-secondary {
  background: var(--btn-secondary);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) { background: var(--btn-secondary-hover); }

.btn-full { width: 100%; }

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.8125rem;
}

/* ── Forms ── */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--btn-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-textarea { resize: vertical; min-height: 5rem; }

/* ── Alerts ── */
.alert {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  margin-bottom: var(--space-md);
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-success {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.alert-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ── Status Indicators ── */
.status-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}

.status-dot--healthy  { background: var(--status-healthy); }
.status-dot--degraded { background: var(--status-degraded); }
.status-dot--critical { background: var(--status-critical); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-badge--healthy {
  background: rgba(16, 185, 129, 0.15);
  color: var(--status-healthy);
}

.status-badge--degraded {
  background: rgba(245, 158, 11, 0.15);
  color: var(--status-degraded);
}

.status-badge--critical {
  background: rgba(239, 68, 68, 0.15);
  color: var(--status-critical);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: rgba(59, 130, 246, 0.15);
  color: var(--btn-primary);
}

.badge--pending {
  background: rgba(245, 158, 11, 0.15);
  color: var(--status-degraded);
}

.badge--approved {
  background: rgba(16, 185, 129, 0.15);
  color: var(--status-healthy);
}

.badge--rejected {
  background: rgba(239, 68, 68, 0.15);
  color: var(--status-critical);
}

/* ── Persona Badges ── */
.persona-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.persona-badge--donna  { background: rgba(99, 102, 241, 0.15); color: var(--color-donna); }
.persona-badge--marcus { background: rgba(16, 185, 129, 0.15); color: var(--color-marcus); }
.persona-badge--selene { background: rgba(245, 158, 11, 0.15); color: var(--color-selene); }
.persona-badge--victor { background: rgba(59, 130, 246, 0.15); color: var(--color-victor); }
.persona-badge--evelyn { background: rgba(139, 92, 246, 0.15); color: var(--color-evelyn); }
.persona-badge--nia    { background: rgba(236, 72, 153, 0.15); color: var(--color-nia); }
.persona-badge--dante  { background: rgba(239, 68, 68, 0.15); color: var(--color-dante); }

/* ── Tables ── */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border-subtle);
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* ── Login Page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-lg);
}

.login-container {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.login-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
}

.login-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.login-form .btn {
  margin-top: var(--space-sm);
}

/* ── Utilities ── */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-mono { font-family: 'SF Mono', 'Fira Code', Consolas, monospace; }
.font-bold { font-weight: 700; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }

.m-0 { margin: 0; }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }

.hidden { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Loading spinner ── */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border-color);
  border-top-color: var(--btn-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Empty states ── */
.empty-state {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2rem;
  margin-bottom: var(--space-md);
}

/* ================================================================
   Responsive Polish — Desktop, Tablet, Mobile
   ================================================================ */

/* ── Tablet (768px - 1023px) ── */
@media (max-width: 1023px) and (min-width: 769px) {
  /* Dashboard: 2-column grid already handled by .grid-3 rule at 1024px */

  /* Health page: single column */
  .health-grid { grid-template-columns: 1fr; }

  /* Budget charts: full width */
  .chart-container { width: 100%; max-width: 100%; }

  /* Tables: horizontal scroll */
  .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Cards: slightly less padding */
  .card { padding: var(--space-md); }
}

/* ── Mobile (< 768px) ── */
@media (max-width: 768px) {
  /* Touch targets: minimum 44x44px */
  .btn { min-height: 44px; min-width: 44px; }
  .btn-sm { min-height: 36px; min-width: 36px; }

  /* Cards: compact on mobile */
  .card { padding: var(--space-md); }
  .card-value { font-size: 1.5rem; }

  /* Tables: allow horizontal scroll, prevent text wrap */
  .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 500px; }

  /* Login: less padding */
  .login-card { padding: var(--space-lg); }

  /* Prevent horizontal scrollbar on body */
  body { overflow-x: hidden; }

  /* Approval action buttons: full width row */
  .approval-actions { flex-wrap: wrap; }
  .approval-actions .btn { flex: 1; min-width: 80px; }

  /* Chart containers responsive */
  canvas { max-width: 100%; height: auto !important; }

  /* Breadcrumb wrapping */
  .breadcrumb { flex-wrap: wrap; }
}

/* ── No horizontal overflow on any viewport ── */
html { overflow-x: hidden; }

/* ── Chart responsive containers ── */
.chart-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
}

.chart-wrapper canvas {
  max-width: 100%;
}
