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

:root {
  --navy:   #0f1f3d;
  --navy2:  #1a3260;
  --navy3:  #243d72;
  --white:  #ffffff;
  --off:    #f5f6fa;
  --border: #dde2ee;
  --text:   #1a1f36;
  --muted:  #6b7a99;

  --green:  #16a34a;
  --green-bg: #dcfce7;
  --blue:   #2563eb;
  --blue-bg: #dbeafe;
  --yellow: #b45309;
  --yellow-bg: #fef3c7;
  --orange: #c2410c;
  --orange-bg: #ffedd5;
  --red:    #dc2626;
  --red-bg: #fee2e2;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;

  --radius: 10px;
  --shadow: 0 2px 12px rgba(15,31,61,0.10);
  --shadow-lg: 0 4px 24px rgba(15,31,61,0.16);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--off);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy3) 100%);
  padding: 24px;
}

.login-container {
  background: var(--white);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  margin-bottom: 36px;
}

.logo-icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 12px;
}

.login-logo h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 15px;
  color: var(--muted);
  margin-top: 2px;
}

.login-tagline {
  font-size: 13px;
  color: var(--blue);
  font-weight: 600;
  margin-top: 8px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.login-form {
  text-align: left;
}

.login-footer {
  margin-top: 32px;
  font-size: 12px;
  color: var(--muted);
}

.alert.alert-error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}

.form-group input,
.form-input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--navy);
  color: var(--white);
  border-color: var(--navy);
}
.btn-primary:hover, .btn-primary:active {
  background: var(--navy2);
  border-color: var(--navy2);
}

.btn-outline {
  background: transparent;
  color: var(--navy);
  border-color: var(--border);
}
.btn-outline:hover, .btn-outline:active {
  background: var(--off);
}

.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: var(--red);   color: #fff; border-color: var(--red); }
.btn-danger:hover  { background: #b91c1c; }
.btn-warning { background: #d97706; color: #fff; border-color: #d97706; }
.btn-warning:hover { background: var(--yellow); }

.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn-lg { padding: 14px 22px; font-size: 16px; }
.btn-full { width: 100%; }

/* ── Dashboard Layout ─────────────────────────────────────────────────────── */
.site-header {
  background: var(--navy);
  color: var(--white);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon { font-size: 28px; line-height: 1; }

.header-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.header-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 500;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
}

/* ── Stats Bar ────────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 14px;
  padding: 18px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-wrap: nowrap;
}

.stat-card {
  flex: 0 0 auto;
  text-align: center;
  background: var(--off);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 22px;
  min-width: 110px;
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
}
.stat-value.green  { color: var(--green); }
.stat-value.blue   { color: var(--blue); }
.stat-value.yellow { color: var(--yellow); }
.stat-value.red    { color: var(--red); }
.stat-value.purple { color: var(--purple); }

.stat-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}

.section-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}

.section-month {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.badge-green    { background: var(--green-bg);  color: var(--green); }
.badge-blue     { background: var(--blue-bg);   color: var(--blue); }
.badge-yellow   { background: var(--yellow-bg); color: var(--yellow); }
.badge-orange   { background: var(--orange-bg); color: var(--orange); }
.badge-red      { background: var(--red-bg);    color: var(--red); }
.badge-purple   { background: var(--purple-bg); color: var(--purple); }
.badge-gray     { background: #f1f5f9; color: #64748b; }

/* ── Escalation Cards ─────────────────────────────────────────────────────── */
.escalation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  padding: 20px;
}

.esc-card {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  background: var(--white);
  transition: box-shadow 0.15s;
}
.esc-card:hover { box-shadow: var(--shadow); }
.esc-card.resolved { opacity: 0.55; }

.esc-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.esc-client {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.3;
}

.esc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.esc-vendor {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.esc-amount {
  font-size: 20px;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 6px;
}

.esc-description {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 12px;
  line-height: 1.5;
}

.esc-suggestion {
  background: var(--off);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.esc-suggestion-label { color: var(--muted); font-weight: 600; }
.esc-suggestion-value { color: var(--navy); font-weight: 700; }
.esc-confidence { margin-left: auto; }

.confidence-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}
.conf-high   { background: var(--green-bg);  color: var(--green); }
.conf-medium { background: var(--yellow-bg); color: var(--yellow); }
.conf-low    { background: var(--red-bg);    color: var(--red); }

.esc-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.esc-resolved-banner {
  background: var(--green-bg);
  color: var(--green);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}
.esc-resolved-banner.rejected {
  background: var(--red-bg);
  color: var(--red);
}
.esc-resolved-banner.corrected {
  background: var(--blue-bg);
  color: var(--blue);
}

.esc-age {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  text-align: right;
}

/* ── Jobs Table ───────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}

.jobs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.jobs-table th {
  background: var(--off);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.jobs-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.jobs-table tr:last-child td { border-bottom: none; }
.jobs-table tr:hover td { background: var(--off); }

.job-client { font-weight: 600; color: var(--navy); }
.job-worker { color: var(--muted); font-weight: 500; }

.progress-cell {
  min-width: 140px;
}
.progress-bar-track {
  background: var(--border);
  border-radius: 4px;
  height: 6px;
  margin-top: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--green);
  transition: width 0.3s;
}

/* ── Worker Cards ─────────────────────────────────────────────────────────── */
.worker-grid {
  display: flex;
  gap: 16px;
  padding: 20px;
  flex-wrap: wrap;
}

.worker-card {
  flex: 0 0 auto;
  min-width: 200px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  background: var(--white);
}

.worker-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
}

.worker-status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.dot-online { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.dot-idle   { background: #94a3b8; box-shadow: 0 0 0 3px #f1f5f9; }

.worker-status-text {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}
.worker-status-text.online { color: var(--green); }
.worker-status-text.idle   { color: #94a3b8; }

.worker-current {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.4;
}
.worker-current strong { color: var(--navy); }

.worker-completed {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,31,61,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--white);
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--off); }

.modal-body {
  padding: 22px;
}

.modal-desc {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
}

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.loading-msg {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.no-items {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.type-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--off);
  color: var(--muted);
  white-space: nowrap;
}
.type-ambiguous  { background: var(--yellow-bg); color: var(--yellow); }
.type-new_vendor { background: var(--blue-bg);   color: var(--blue); }
.type-threshold  { background: var(--red-bg);    color: var(--red); }
.type-personal   { background: var(--orange-bg); color: var(--orange); }

/* ── Responsive / iPad ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-bar { gap: 10px; padding: 14px 16px; }
  .stat-card { padding: 12px 16px; min-width: 90px; }
  .stat-value { font-size: 22px; }
  .main-content { padding: 16px; gap: 20px; }
  .escalation-grid { grid-template-columns: 1fr; padding: 14px; }
  .worker-grid { flex-direction: column; }
  .worker-card { min-width: unset; width: 100%; }
}

@media (max-width: 600px) {
  .header-title { font-size: 14px; }
  .header-sub { display: none; }
  .site-header { padding: 12px 16px; }
  .section-header { padding: 14px 16px; }
  .jobs-table th, .jobs-table td { padding: 10px 12px; }
}

/* ── Tab Navigation ───────────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 4px;
  padding: 12px 24px 0;
  background: var(--white);
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  flex: 0 0 auto;
  padding: 10px 18px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  transition: all 0.15s;
  white-space: nowrap;
  margin-bottom: -2px;
}
.tab-btn:hover { color: var(--navy); background: var(--off); }
.tab-btn.active {
  color: var(--navy);
  border-bottom-color: var(--navy);
  background: var(--off);
}

/* ── System Health Panel ─────────────────────────────────────────────────── */
.health-alert-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--red-bg);
  border: 1.5px solid #fca5a5;
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--red);
}
.health-alert-icon { font-size: 18px; }

.health-server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  padding: 20px;
}

.server-card {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  background: var(--white);
  position: relative;
  transition: box-shadow 0.15s;
}
.server-card:hover { box-shadow: var(--shadow); }
.server-card.card-critical { border-color: #fca5a5; background: #fff8f8; }
.server-card.card-warning  { border-color: #fde68a; background: #fffef0; }
.server-card.card-not-provisioned { opacity: 0.65; background: #f8fafc; }

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

.server-name {
  font-size: 17px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.2;
}
.server-role-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--blue-bg);
  color: var(--blue);
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
  margin-top: 3px;
}
.server-ip {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-family: monospace;
}

.server-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 16px;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online   { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.status-dot.warning  { background: #d97706; box-shadow: 0 0 0 3px var(--yellow-bg); }
.status-dot.critical { background: var(--red); box-shadow: 0 0 0 3px var(--red-bg); }
.status-dot.not-provisioned { background: #94a3b8; box-shadow: 0 0 0 3px #f1f5f9; }
.status-label.online   { color: var(--green); }
.status-label.warning  { color: #d97706; }
.status-label.critical { color: var(--red); }
.status-label.not-provisioned { color: #94a3b8; }

.metric-row {
  margin-bottom: 12px;
}
.metric-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}
.metric-label-row span:last-child {
  font-weight: 700;
  color: var(--text);
}
.gauge-track {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.gauge-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}
.gauge-fill.green  { background: var(--green); }
.gauge-fill.yellow { background: #d97706; }
.gauge-fill.red    { background: var(--red); }

.pm2-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.pm2-label { color: var(--muted); font-weight: 600; }
.pm2-value { font-weight: 800; color: var(--navy); font-size: 16px; }

.server-updated {
  font-size: 11px;
  color: var(--muted);
  margin-top: 12px;
  text-align: right;
}

.not-provisioned-msg {
  text-align: center;
  padding: 20px 0 10px;
  color: var(--muted);
  font-size: 14px;
}
.not-provisioned-msg .np-icon { font-size: 32px; margin-bottom: 8px; }
.not-provisioned-msg .np-text { font-weight: 600; }
.not-provisioned-msg .np-sub  { font-size: 12px; margin-top: 4px; }

.server-note {
  font-size: 12px;
  color: var(--muted);
  background: var(--off);
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 12px;
  font-style: italic;
}

@media (max-width: 900px) {
  .tab-nav { padding: 10px 16px 0; gap: 2px; }
  .tab-btn { padding: 8px 12px; font-size: 13px; }
  .health-server-grid { grid-template-columns: 1fr; padding: 14px; }
}
