:root {
  --bg: #eef3f4;
  --panel: #ffffff;
  --ink: #172126;
  --muted: #637179;
  --line: #d9e2e5;
  --navy: #103846;
  --teal: #0e8b8f;
  --green: #3b8b5c;
  --amber: #b8731e;
  --red: #b7473f;
  --shadow: 0 14px 32px rgba(18, 42, 49, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 16px 24px;
  color: white;
  background: linear-gradient(90deg, #0f3442, #17636a 58%, #4f6f3d);
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: clamp(20px, 2.1vw, 32px);
  letter-spacing: 0;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-title { min-width: 0; }
.condition-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.eyebrow { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #7d9098; font-weight: 700; }
.topbar .eyebrow { color: #c9e7e5; }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  color: #eaf8f7;
  white-space: nowrap;
}

.btn {
  border: 0;
  border-radius: 7px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
}
.btn.primary { background: #f2b94d; color: #172126; }
.btn.secondary { background: #e8f0f1; color: #12313a; border: 1px solid #cbdadd; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 22px;
  padding: 22px;
}

.sidebar {
  position: sticky;
  top: 92px;
  align-self: start;
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #f8fbfb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sidebar a {
  color: #25434c;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 6px;
  font-weight: 700;
}
.sidebar a:hover { background: #e6f2f2; }

.content { display: grid; gap: 22px; }
.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 8px 18px rgba(18, 42, 49, 0.05);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}
.section h2 { margin: 3px 0 0; font-size: 22px; letter-spacing: 0; }
.section h3 { margin: 0 0 12px; font-size: 17px; }
.trial-number {
  padding: 10px 12px;
  border-radius: 7px;
  color: #06333b;
  background: #dff1ef;
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #51636b;
  font-size: 13px;
  font-weight: 700;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #cfdcde;
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  background: #fbfdfd;
}
textarea { resize: vertical; }

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 10px;
}
.check-item, .checkline {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfd;
}
.check-item input, .checkline input { width: 16px; margin-top: 2px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.photo-grid.empty {
  display: block;
  padding: 22px;
  color: var(--muted);
  border: 1px dashed #b9c8cb;
  border-radius: 8px;
}
.photo-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfdfd;
}
.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}
.photo-meta { padding: 10px; display: grid; gap: 8px; }
.photo-meta small { color: var(--muted); line-height: 1.35; }
.photo-delete {
  justify-self: start;
  border: 1px solid #e2b4b0;
  border-radius: 6px;
  background: #fff7f6;
  color: var(--red);
  cursor: pointer;
  font-weight: 700;
  padding: 8px 10px;
}
.photo-delete:hover { background: #ffe8e5; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1160px; }
th, td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; }
th { color: #50646b; font-size: 12px; text-transform: uppercase; }
td input, td select { min-width: 86px; padding: 8px; }
.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid #d8e2e4;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  padding: 14px;
  border-radius: 8px;
  background: #f7faf9;
  border: 1px solid var(--line);
}
.kpi span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.kpi strong { display: block; margin-top: 8px; font-size: 24px; }

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 14px;
}
.chart {
  min-height: 310px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
}
.fallback-chart {
  height: 100%;
  min-height: 310px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  padding: 14px;
}
.fallback-chart strong { font-size: 15px; }
.fallback-chart span { color: var(--muted); }
.fallback-chart svg { width: 100%; height: 250px; }

.map-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #dce9e8;
}
.map-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #f7fbfb;
  border-bottom: 1px solid var(--line);
}
.map-header span { color: var(--muted); }
#trackSvg { width: 100%; height: 280px; display: block; }

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 18px;
  margin-bottom: 16px;
}
.suggestions { margin: 0; padding-left: 20px; display: grid; gap: 9px; }
.suggestions li::marker { color: var(--teal); }
.checklist { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 8px; }

/* Screen-reader only */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Focus visibility for keyboard navigation */
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-color: var(--teal); border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14, 139, 143, 0.15); }
.btn:focus-visible { outline-color: var(--navy); box-shadow: 0 0 0 3px rgba(16, 56, 70, 0.2); }
.sidebar a:focus-visible { background: #e6f2f2; outline-color: var(--navy); }
.icon-btn:focus-visible, .photo-delete:focus-visible { outline-color: var(--red); }

/* Print styles */
@media print {
  .topbar, .sidebar, .topbar-actions, .condition-actions, .btn, .file-btn, .icon-btn, .photo-delete { display: none !important; }
  body { background: white; color: #000; font-size: 11pt; }
  .app-shell { display: block; padding: 0; }
  .content { display: block; gap: 0; }
  .section { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; margin-bottom: 12px; }
  .table-wrap { overflow-x: visible; }
  table { min-width: auto; font-size: 9pt; }
  .chart, .map-panel { break-inside: avoid; }
  .kpi-grid { grid-template-columns: repeat(5, 1fr); }
  .analysis-grid { grid-template-columns: 1fr 1fr; }
  #trackSvg { max-height: 200px; }
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; grid-template-columns: repeat(4, 1fr); }
  .form-grid, .check-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .topbar {
    gap: 8px;
    align-items: stretch;
    flex-direction: column;
    padding: 8px 10px;
  }

  .topbar h1 {
    margin-top: 1px;
    font-size: 17px;
    line-height: 1.18;
  }

  .topbar .eyebrow {
    font-size: 9px;
    line-height: 1;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }

  .topbar-actions .btn,
  .topbar-actions .status-pill {
    width: 100%;
    min-height: 32px;
    padding: 6px 7px;
    border-radius: 8px;
    justify-content: center;
    text-align: center;
    font-size: 12px;
    line-height: 1.15;
  }

  .topbar.is-compact {
    padding: 6px 8px;
  }

  .topbar.is-compact .topbar-title {
    display: none;
  }

  .section-head, .map-header { align-items: stretch; flex-direction: column; }
  .condition-actions { justify-content: stretch; }
  .condition-actions .btn { width: 100%; }
  .app-shell { padding: 12px; }
  .sidebar { grid-template-columns: repeat(2, 1fr); }
  .form-grid, .check-grid, .analysis-grid, .report-grid, .checklist { grid-template-columns: 1fr; }
}
