:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --border: #c8ccd4;
  --text: #1a1d24;
  --muted: #5c6370;
  --header-bg: #e6e8ed;
  --focus: #1a5fb4;
}

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

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  z-index: 100;
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

.site-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

.site-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.control-label {
  font-weight: 500;
}

select {
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text);
}

select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.header-meta {
  max-width: 1400px;
  margin: 0.5rem auto 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100dvh - 120px);
}

.layout-single {
  display: block;
  max-width: 1400px;
  margin: 0 auto;
}

.main-tabs {
  padding: 1rem;
  min-width: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.panel-overview {
  padding: 0;
  border: none;
  background: transparent;
}

.tabs {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
}

.tabs-list-wrap {
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.tabs-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 0.25rem;
}

.tab {
  min-height: 44px;
  padding: 0.5rem 0.85rem;
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.5);
}

.tab[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--focus);
  background: var(--surface);
}

.tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.filters-bar {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

.filters-heading {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  width: 100%;
  margin: 0 0 0.25rem;
}

@media (min-width: 720px) {
  .filters-heading {
    width: auto;
    margin: 0 0.5rem 0 0;
  }
}

.control-inline {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.control-inline .control-label {
  font-weight: 500;
}

input[type="datetime-local"] {
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text);
}

input[type="datetime-local"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn-secondary {
  min-height: 44px;
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.filters-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
  max-width: 52rem;
}

.tab-panel {
  padding: 1rem;
}

.tab-panel-section {
  margin-bottom: 1.75rem;
}

.tab-panel-section:last-child {
  margin-bottom: 0;
}

.tab-section-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.tab-panel-hidden[hidden] {
  display: none;
}

.main {
  flex: 1;
  padding: 1rem;
  min-width: 0;
}

.panel {
  margin-bottom: 2rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.75rem;
  font-size: 0.9375rem;
}

.overview-item {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  background: var(--bg);
}

.overview-item dt {
  margin: 0;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.overview-item dd {
  margin: 0.25rem 0 0;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.table-filter {
  flex: 1;
  max-width: 20rem;
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 2px;
}

.table-filter:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: var(--header-bg);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.data-table th:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.data-table tbody tr:nth-child(even) {
  background: #fafbfc;
}

.empty-row td {
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 768px) {
  .tabs-list {
    flex-direction: column;
    align-items: stretch;
  }

  .tab {
    text-align: left;
    border-bottom: 1px solid var(--border);
    border-left: 3px solid transparent;
  }

  .tab[aria-selected="true"] {
    border-bottom: 1px solid var(--border);
    border-left-color: var(--focus);
  }
}

/* Long specimen descriptions and source fields wrap within plain EHR tables. */
#table-microbiology td { min-width: 7rem; overflow-wrap: anywhere; }
#table-microbiology td:nth-child(3) { min-width: 15rem; max-width: 28rem; }
.record-details { min-width: 15rem; max-width: 32rem; overflow-wrap: anywhere; }
