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

:root {
  --bg:        #f8f9fa;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1a202c;
  --text-muted:#64748b;
  --primary:   #4f46e5;
  --primary-h: #4338ca;
  --green:     #16a34a;
  --yellow:    #ca8a04;
  --red:       #dc2626;
  --green-bg:  #dcfce7;
  --yellow-bg: #fef9c3;
  --red-bg:    #fee2e2;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.08);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}

.nav-links { display: flex; gap: 8px; flex: 1; }
.nav-links a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-links a:hover { background: var(--bg); color: var(--text); }

.nav-user { display: flex; align-items: center; gap: 12px; }
.user-email { color: var(--text-muted); font-size: 13px; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.main-content { max-width: 1280px; margin: 0 auto; padding: 24px; }

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

.back-link { color: var(--primary); text-decoration: none; font-size: 13px; display: block; margin-bottom: 4px; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── KPI Grid ──────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.rag-border-green { border-left: 4px solid var(--green); }
.rag-border-yellow { border-left: 4px solid var(--yellow); }
.rag-border-red { border-left: 4px solid var(--red); }

/* ── RAG badges ────────────────────────────────────────────────────────────── */
.rag-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.rag-green  { background: var(--green-bg);  color: var(--green); }
.rag-yellow { background: var(--yellow-bg); color: var(--yellow); }
.rag-red    { background: var(--red-bg);    color: var(--red); }
.rag-large  { font-size: 14px; padding: 6px 16px; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.fleet-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.fleet-table th, .fleet-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.fleet-table th {
  background: var(--bg);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  white-space: nowrap;
}
.fleet-table tr:last-child td { border-bottom: none; }
.fleet-table tbody tr:hover { background: #f1f5f9; }
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--text); }

.account-name { display: block; font-weight: 600; }
.account-id { display: block; font-size: 11px; color: var(--text-muted); }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.status-enabled  { background: var(--green-bg); color: var(--green); }
.status-paused   { background: var(--yellow-bg); color: var(--yellow); }
.status-removed  { background: var(--red-bg); color: var(--red); }

/* ── Filter bar ────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-input, .filter-select, .inline-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.filter-input:focus, .filter-select:focus, .inline-input:focus { border-color: var(--primary); }
.filter-input { min-width: 220px; }
.inline-input { width: 100%; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-outline   { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-sm        { padding: 4px 10px; font-size: 12px; }
.btn-full      { width: 100%; justify-content: center; }

/* ── Login ──────────────────────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,.08);
}
.login-title { font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); text-align: center; margin-bottom: 28px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { font-weight: 600; font-size: 13px; }
.login-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-weight: 500;
}
.alert-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid #fca5a5; }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #86efac; }

/* ── Diagnosis ──────────────────────────────────────────────────────────────── */
.diagnosis-panel { display: flex; flex-direction: column; gap: 20px; }
 
.diagnosis-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.diagnosis-time { font-size: 12px; color: var(--text-muted); }
.diagnosis-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
 
/* Cohort quality badge */
.cohort-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.cohort-exact    { background: var(--green-bg); color: var(--green); }
.cohort-relaxed-1 { background: var(--yellow-bg); color: var(--yellow); }
.cohort-relaxed-2 { background: var(--red-bg); color: var(--red); }
 
.model-badge {
  font-size: 11px;
  color: var(--text-muted);
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: monospace;
}
 
.diagnosis-section h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.diagnosis-section p { line-height: 1.8; color: var(--text); }
 
/* Recommendation bullet list */
.recommendation-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0;
  margin: 0;
}
.recommendation-list li {
  display: flex;
  gap: 10px;
  line-height: 1.7;
}
.recommendation-list li::before {
  content: "→";
  color: var(--primary);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}
 

/* ── Connection page ────────────────────────────────────────────────────────── */
.connection-card { max-width: 600px; }
.connection-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.connection-status-row:last-child { border-bottom: none; }
.conn-label { font-weight: 600; }
.conn-value { color: var(--text-muted); }
.error-text { color: var(--red); }
.connection-actions { margin-top: 20px; }
.sync-status-note { margin-top: 12px; color: var(--text-muted); font-size: 13px; }

/* ── Tag form ───────────────────────────────────────────────────────────────── */
.tag-form { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.tag-form label { font-weight: 600; font-size: 13px; }
.tag-form select { display: block; margin-top: 4px; min-width: 180px; }

/* ── HTMX spinner ───────────────────────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ── Refresh button spin animation ─────────────────────────────────────────── */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.refresh-icon {
  display: inline-block;
  font-style: normal;
  transition: transform 0.2s;
}
.refresh-btn.htmx-request .refresh-icon {
  animation: spin 0.7s linear infinite;
}
.refresh-btn.htmx-request {
  opacity: 0.75;
  cursor: wait;
}

/* ── Peer chips ─────────────────────────────────────────────────────────────── */
.peer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.peer-chip {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #4f46e5;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.peer-chip:hover {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
}
.no-peers-note {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}
.no-peers-note a { color: var(--primary); }

/* ── Comparison criteria grid ───────────────────────────────────────────────── */
.criteria-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.criteria-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.criteria-label {
  width: 120px;
  flex-shrink: 0;
  font-weight: 600;
  color: var(--text-muted);
}
.criteria-matched {
  color: var(--green, #16a34a);
  font-weight: 500;
}
.criteria-relaxed {
  color: var(--yellow, #ca8a04);
  font-weight: 500;
}
.criteria-missing {
  color: var(--text-muted);
}

/* ── Misc ───────────────────────────────────────────────────────────────────── */
.loading-text { color: var(--text-muted); font-style: italic; }
.empty-state   { color: var(--text-muted); text-align: center; padding: 32px !important; }

#trend-chart { min-height: 300px; }

/* ── Auth switch link (login ↔ signup) ──────────────────────────────────────── */
.auth-switch {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-switch a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ── Field hint (e.g. "min 8 chars", password match message) ────────────────── */
.field-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 6px;
}

/* ── Role badges ────────────────────────────────────────────────────────────── */
.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-admin  { background: #ede9fe; color: #6d28d9; }
.role-viewer { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Self badge ─────────────────────────────────────────────────────────────── */
.self-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Danger button ──────────────────────────────────────────────────────────── */
.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #fca5a5;
}
.btn-danger:hover { background: #fca5a5; }

/* ── Action row (role toggle + delete side by side) ────────────────────────── */
.action-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Create user form row ───────────────────────────────────────────────────── */
.create-user-form { width: 100%; }
.form-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 160px; }
.form-group label { font-weight: 600; font-size: 13px; }
.form-group-btn { flex: 0 0 auto; }

/* ── Misc helpers ───────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); font-size: 13px; }
