/* MusterKey — Luton Labs Design System — Teal accent */
:root {
  --prod-teal: #0d9488;
  --prod-teal-dark: #0f766e;
  --prod-teal-light: #5eead4;
  --prod-teal-bg: #f0fdfa;
  --prod-teal-border: #99f6e4;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --info: #2563eb;
  --info-bg: #eff6ff;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,.08),0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,.06),0 2px 4px rgba(0,0,0,.04);
}

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

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background: var(--surface-2);
  line-height: 1.55;
}

a { color: var(--prod-teal); text-decoration: none; }
a:hover { color: var(--prod-teal-dark); text-decoration: underline; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #111827;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid #1f2937;
  text-decoration: none;
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: var(--prod-teal);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand .brand-name {
  font-size: 15px;
  font-weight: 700;
  color: #f9fafb;
  letter-spacing: .02em;
}

.sidebar-brand .brand-sub {
  font-size: 10px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section-label {
  padding: 10px 20px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6b7280;
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: #9ca3af;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: color .15s, background .15s;
}

.nav-link:hover {
  color: #f9fafb;
  background: #1f2937;
  text-decoration: none;
}

.nav-link.active {
  color: var(--prod-teal-light);
  background: rgba(13,148,136,.12);
  border-left-color: var(--prod-teal);
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  border-top: 1px solid #1f2937;
  padding: 14px 20px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--prod-teal);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-info .user-name {
  font-size: 13px;
  font-weight: 600;
  color: #f3f4f6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.sidebar-user-info .user-role {
  font-size: 11px;
  color: #6b7280;
  text-transform: capitalize;
}

/* ── Main content ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-body {
  flex: 1;
  padding: 28px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-body {
  padding: 20px;
}

/* ── Stat tiles ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-value.teal { color: var(--prod-teal); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--prod-teal);
  color: #fff;
  border-color: var(--prod-teal);
}

.btn-primary:hover {
  background: var(--prod-teal-dark);
  border-color: var(--prod-teal-dark);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #b91c1c;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-3);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 11px 24px;
  font-size: 15px;
}

.btn[disabled], .btn.disabled {
  opacity: .5;
  cursor: not-allowed;
}

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

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 5px;
}

.form-control {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
}

.form-control:focus {
  outline: none;
  border-color: var(--prod-teal);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}

select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 34px; -webkit-appearance: none; appearance: none; }

textarea.form-control { resize: vertical; min-height: 100px; }

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

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

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

.table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}

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

.table tbody tr:hover { background: var(--surface-2); }

.table tbody tr:last-child td { border-bottom: none; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-teal { background: var(--prod-teal-bg); color: var(--prod-teal-dark); }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-yellow { background: var(--warning-bg); color: var(--warning); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-gray { background: var(--surface-3); color: var(--text-secondary); }
.badge-blue { background: var(--info-bg); color: var(--info); }

/* ── Alerts ── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-success { background: var(--success-bg); color: #15803d; border-color: #bbf7d0; }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }
.alert-error { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--info-bg); color: #1e40af; border-color: #bfdbfe; }

/* ── Tabs ── */
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.tab-link {
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  text-decoration: none;
  transition: color .15s;
}

.tab-link:hover {
  color: var(--prod-teal);
  text-decoration: none;
}

.tab-link.active {
  color: var(--prod-teal);
  border-bottom-color: var(--prod-teal);
}

/* ── Search bar ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input-wrap {
  position: relative;
  flex: 1;
}

.search-input-wrap .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
}

.search-input:focus {
  outline: none;
  border-color: var(--prod-teal);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .4;
}

.empty-state h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 380px;
  margin: 0 auto 20px;
}

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

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  font-size: 20px;
  line-height: 1;
}

.modal-close:hover { background: var(--surface-3); color: var(--text-primary); }

.modal-body {
  padding: 22px;
}

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

/* ── Progress bar ── */
.progress-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--prod-teal);
  border-radius: 999px;
  transition: width .3s;
}

/* ── Status pills specific to MusterKey ── */
.status-active { background: var(--success-bg); color: var(--success); }
.status-inactive { background: var(--surface-3); color: var(--text-secondary); }
.status-pending_review { background: var(--warning-bg); color: var(--warning); }
.status-update_pending { background: var(--info-bg); color: var(--info); }
.status-ready_for_export { background: var(--prod-teal-bg); color: var(--prod-teal-dark); }
.status-exported { background: #ede9fe; color: #6d28d9; }
.status-blocked { background: var(--danger-bg); color: var(--danger); }
.status-archived { background: var(--surface-3); color: var(--text-muted); }

.quality-verified { background: var(--success-bg); color: var(--success); }
.quality-unverified { background: var(--surface-3); color: var(--text-secondary); }
.quality-flagged { background: var(--warning-bg); color: var(--warning); }
.quality-conflict { background: var(--danger-bg); color: var(--danger); }
.quality-pending { background: var(--info-bg); color: var(--info); }

/* ── Onboarding steps ── */
.onboard-steps {
  display: flex;
  gap: 0;
  margin-bottom: 32px;
  counter-reset: step;
}

.onboard-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  text-align: center;
}

.onboard-step::before {
  counter-increment: step;
  content: counter(step);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.onboard-step.done::before {
  background: var(--prod-teal);
  color: #fff;
  content: '✓';
}

.onboard-step.active::before {
  background: var(--prod-teal);
  color: #fff;
  box-shadow: 0 0 0 4px var(--prod-teal-bg);
}

.onboard-step + .onboard-step::after {
  content: '';
  position: absolute;
  top: 16px;
  right: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.onboard-step.done + .onboard-step::after {
  background: var(--prod-teal);
}

.onboard-label {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.onboard-step.active .onboard-label,
.onboard-step.done .onboard-label {
  color: var(--prod-teal-dark);
}

/* ── Personnel record header ── */
.personnel-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.personnel-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--prod-teal);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.personnel-meta h1 {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}

.personnel-meta .meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Utilities ── */
.text-muted { color: var(--text-muted); }
.text-small { font-size: 12px; }
.font-mono { font-family: 'Courier New', Courier, monospace; font-size: 12px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex-1 { flex: 1; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nowrap { white-space: nowrap; }

/* ── API key reveal ── */
.api-key-reveal {
  font-family: 'Courier New', monospace;
  font-size: 13px;
  background: #111827;
  color: var(--prod-teal-light);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  word-break: break-all;
  margin-bottom: 12px;
  border: 1px solid #1f2937;
}

/* ── Source connection type badges ── */
.conn-mysql { background: #fff7ed; color: #c2410c; }
.conn-mssql { background: #eff6ff; color: #1d4ed8; }
.conn-rest_api { background: #f5f3ff; color: #6d28d9; }
.conn-csv { background: #f0fdf4; color: #15803d; }

/* ── Timeline / audit log ── */
.timeline {
  position: relative;
  padding-left: 28px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  margin-bottom: 18px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--prod-teal);
  border: 2px solid var(--surface);
}

.timeline-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.timeline-text {
  font-size: 13.5px;
  color: var(--text-primary);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
