@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --blue-900: #0f1e3d;
  --blue-800: #1e3a5f;
  --blue-600: #2563eb;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;
  --blue-50:  #eff6ff;
  --green-600: #16a34a;
  --green-100: #dcfce7;
  --yellow-500: #eab308;
  --yellow-100: #fef9c3;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --gray-900: #111827;
  --gray-700: #374151;
  --gray-500: #6b7280;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50:  #f9fafb;
  --white: #ffffff;
  --sidebar-w: 240px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: 'Inter', sans-serif; background: var(--gray-50); color: var(--gray-900); line-height: 1.5; }
a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

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

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--blue-900);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: var(--blue-600);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.sidebar-logo .lab-name { font-size: 13px; font-weight: 600; line-height: 1.2; opacity: .9; }
.sidebar-logo .lab-name small { display: block; font-weight: 400; opacity: .6; font-size: 11px; }

.sidebar-section { padding: 12px 0; }
.sidebar-section-label { padding: 4px 20px 6px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; opacity: .4; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.75);
  font-size: 14px; font-weight: 500;
  border-left: 3px solid transparent;
  transition: all .15s;
}
.sidebar nav a:hover { color: var(--white); background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { color: var(--white); background: rgba(255,255,255,.1); border-left-color: var(--blue-500); }
.sidebar nav a .icon { width: 18px; opacity: .7; }
.sidebar nav a.active .icon { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 13px;
}
.sidebar-footer .user-name { font-weight: 600; opacity: .9; }
.sidebar-footer .user-role { font-size: 11px; opacity: .5; text-transform: capitalize; }
.sidebar-footer form { margin-top: 10px; }
.sidebar-footer .btn-logout {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.7);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  transition: all .15s;
}
.sidebar-footer .btn-logout:hover { background: rgba(255,255,255,.15); color: var(--white); }

/* ── Main Content ─────────────────────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 32px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 18px; font-weight: 600; color: var(--gray-900); }
.page-body { padding: 28px 32px; flex: 1; }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── Stat Cards ───────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; font-weight: 500; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 32px; font-weight: 700; color: var(--gray-900); line-height: 1.1; margin-top: 4px; }
.stat-card .stat-sub { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.stat-card.accent { background: var(--blue-800); border-color: var(--blue-800); }
.stat-card.accent .stat-label, .stat-card.accent .stat-value, .stat-card.accent .stat-sub { color: var(--white); }
.stat-card.accent .stat-label { opacity: .7; }

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: var(--gray-50); padding: 10px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--gray-200); }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--gray-50); }

/* ── Badges ───────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-green  { background: var(--green-100); color: var(--green-600); }
.badge-red    { background: var(--red-100);   color: var(--red-600); }
.badge-yellow { background: var(--yellow-100); color: #92400e; }
.badge-blue   { background: var(--blue-100);  color: var(--blue-800); }
.badge-gray   { background: var(--gray-200);  color: var(--gray-700); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; border: none; transition: all .15s; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue-600); color: var(--white); }
.btn-primary:hover { background: #1d4ed8; color: var(--white); }
.btn-secondary { background: var(--white); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-danger  { background: var(--red-600); color: var(--white); }
.btn-danger:hover { background: #b91c1c; color: var(--white); }
.btn-success { background: var(--green-600); color: var(--white); }
.btn-success:hover { background: #15803d; color: var(--white); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }
.form-label.required::after { content: ' *'; color: var(--red-600); }
.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.form-control::placeholder { color: var(--gray-300); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--gray-500); 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; }

/* ── Alerts ───────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 8px; }
.alert-success { background: var(--green-100); color: var(--green-600); border: 1px solid #bbf7d0; }
.alert-error   { background: var(--red-100); color: var(--red-600); border: 1px solid #fecaca; }
.alert-info    { background: var(--blue-50); color: var(--blue-800); border: 1px solid var(--blue-100); }

/* ── Fixed actions panel (fill page) ─────────────────────────── */
.fixed-actions-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
  padding: 16px;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Save button states */
.btn-save {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--gray-100); color: var(--gray-700);
  border: 1px solid var(--gray-300); border-radius: 8px;
  padding: 10px 16px; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.btn-save:hover:not(:disabled) { background: var(--gray-200); }
.btn-save:disabled { opacity: .6; cursor: not-allowed; }
.btn-save.btn-save-ok { background: var(--green-100); color: var(--green-600); border-color: #bbf7d0; }
.btn-save.btn-save-err { background: var(--red-100); color: var(--red-600); border-color: #fecaca; }

/* Spinner inside save button */
.save-spinner {
  display: inline-block; width: 13px; height: 13px; flex-shrink: 0;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast notification */
.save-toast {
  position: fixed; bottom: 24px; left: 24px; z-index: 300;
  padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.save-toast.save-toast-show { opacity: 1; transform: translateY(0); }
.save-toast-success { background: var(--green-600); color: #fff; }
.save-toast-error   { background: var(--red-600); color: #fff; }

/* ── Parameter cards (fill page) ─────────────────────────────── */
.param-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: border-color .2s;
}
.param-card.param-acceptable  { border-left: 4px solid var(--green-600); }
.param-card.param-unacceptable { border-left: 4px solid var(--red-600); }
.param-card.param-pending      { border-left: 4px solid var(--gray-300); }
.param-card-header { padding: 14px 18px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.param-card-header h3 { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.param-meta { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.param-card-body { padding: 16px 18px; }
.samples-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.sample-input-wrap { display: flex; flex-direction: column; gap: 4px; }
.sample-label-row { display: flex; align-items: center; gap: 6px; }
.sample-label { font-size: 12px; font-weight: 500; color: var(--gray-500); }
.sample-input { width: 100%; padding: 7px 10px; border: 1px solid var(--gray-300); border-radius: 6px; font-size: 14px; transition: border-color .15s, box-shadow .15s; }
.sample-input:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.sample-input.zone-green  { border-color: var(--green-600); box-shadow: 0 0 0 2px rgba(22,163,74,.15); }
.sample-input.zone-yellow { border-color: var(--yellow-500); box-shadow: 0 0 0 2px rgba(234,179,8,.15); }
.sample-input.zone-red    { border-color: var(--red-600); box-shadow: 0 0 0 2px rgba(220,38,38,.15); }
.zone-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--gray-200); transition: background .2s; }
.zone-dot.green  { background: var(--green-600); }
.zone-dot.yellow { background: var(--yellow-500); }
.zone-dot.red    { background: var(--red-600); }

.param-status { margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 13px; font-weight: 500; }
.param-status.pending      { background: var(--gray-100); color: var(--gray-500); }
.param-status.acceptable   { background: var(--green-100); color: var(--green-600); }
.param-status.unacceptable { background: var(--red-100); color: var(--red-600); }

/* ── Result section ───────────────────────────────────────────── */
.result-section { background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 24px; margin-top: 24px; }
.result-suggestion { font-size: 15px; font-weight: 500; margin-bottom: 16px; }
.result-radios { display: flex; gap: 16px; margin-bottom: 20px; }
.result-radio-label {
  flex: 1; padding: 14px 18px; border-radius: 8px;
  border: 2px solid var(--gray-200); cursor: pointer;
  transition: all .15s; display: flex; align-items: center; gap: 10px;
  font-weight: 500; font-size: 14px;
}
.result-radio-label:has(input:checked).green-option { border-color: var(--green-600); background: var(--green-100); color: var(--green-600); }
.result-radio-label:has(input:checked).red-option { border-color: var(--red-600); background: var(--red-100); color: var(--red-600); }
.result-radio-label input[type="radio"] { accent-color: var(--blue-600); }

/* ── Login page ───────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--blue-900); }
.login-card { background: var(--white); border-radius: 16px; padding: 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon-wrap svg { width: 40px; height: 40px; color: var(--blue-800); }
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--blue-900); margin-top: 8px; }
.login-logo p { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ── Report page ──────────────────────────────────────────────── */
.report-page { max-width: 820px; margin: 0 auto; padding: 40px 24px; font-family: 'Inter', sans-serif; }
.report-header { text-align: center; padding-bottom: 24px; border-bottom: 2px solid var(--blue-800); margin-bottom: 28px; }
.report-header h1 { font-size: 22px; color: var(--blue-900); text-transform: uppercase; letter-spacing: 1px; }
.report-number { display: inline-block; background: var(--blue-800); color: var(--white); padding: 4px 16px; border-radius: 4px; font-size: 13px; margin-top: 6px; }
.report-section { margin-bottom: 24px; }
.report-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--gray-500); background: var(--gray-100); padding: 6px 12px; border-radius: 4px; margin-bottom: 12px; }
.report-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; }
.report-info-item { font-size: 13px; padding: 4px 0; }
.report-info-item strong { color: var(--gray-700); }
.report-param { border: 1px solid var(--gray-200); border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
.report-param h3 { font-size: 15px; color: var(--blue-900); margin-bottom: 4px; }
.report-param-meta { font-size: 12px; color: var(--gray-500); margin-bottom: 10px; }
.report-samples-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-samples-table th, .report-samples-table td { padding: 6px 10px; border: 1px solid var(--gray-200); text-align: center; }
.report-samples-table th { background: var(--gray-50); font-weight: 600; }
.report-conclusion { border: 2px solid var(--gray-300); border-radius: 10px; padding: 24px; text-align: center; margin: 24px 0; }
.report-conclusion .conclusion-label { font-size: 12px; color: var(--gray-500); text-transform: uppercase; letter-spacing: 1px; }
.report-conclusion .conclusion-result { font-size: 28px; font-weight: 700; margin-top: 6px; }
.conclusion-acceptable   { color: var(--green-600); }
.conclusion-unacceptable { color: var(--red-600); }

/* ── Section header ───────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-header h1 { font-size: 22px; font-weight: 700; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--gray-500); }
.empty-state .empty-icon { margin-bottom: 12px; line-height: 1; }
.empty-state .empty-icon svg { width: 40px; height: 40px; color: var(--gray-300); }
.empty-state p { font-size: 15px; }

/* ── Model parameters editor ──────────────────────────────────── */
.param-editor-row {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  position: relative;
}
.param-editor-row .form-row-5 { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr 1fr 40px; gap: 10px; align-items: end; }
.btn-remove-param { background: var(--red-100); color: var(--red-600); border: none; border-radius: 6px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background .15s; font-size: 16px; }
.btn-remove-param:hover { background: var(--red-600); color: white; }

/* ── Lucide icons ─────────────────────────────────────────────── */
[data-lucide] { display: inline-block; }
.sidebar nav a .icon svg { width: 18px; height: 18px; }
.logo-icon svg { width: 20px; height: 20px; stroke: white; }
.alert svg { width: 16px; height: 16px; vertical-align: -0.2em; flex-shrink: 0; }
.card-header h2 svg { width: 18px; height: 18px; vertical-align: -0.2em; }
.btn svg { width: 14px; height: 14px; vertical-align: -0.1em; }
.param-status svg { width: 16px; height: 16px; vertical-align: -0.15em; }
.autosave-check svg { width: 14px; height: 14px; vertical-align: -0.1em; }

/* ── Misc ─────────────────────────────────────────────────────── */
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 13px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.align-center { align-items: center; }
.actions { display: flex; gap: 6px; }
.divider { border: none; border-top: 1px solid var(--gray-200); margin: 20px 0; }
