:root {
  color-scheme: light;
  font-family: 'Inter', system-ui, sans-serif;
  background: #f4f6fb;
  color: #1f2933;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

/* Top navigation bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 5vw;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 0.9rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.topbar-left a {
  color: #94a3b8;
  text-decoration: none;
}

.topbar-left a:hover {
  color: #fff;
}

.topbar-urgence {
  color: #fca5a5 !important;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#user-name {
  color: #94a3b8;
}

.topbar-logout {
  border: 1px solid #475569;
  background: transparent;
  color: #94a3b8;
  padding: 0.3rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.topbar-logout:hover {
  background: #334155;
  color: #fff;
}

/* Form header with submit button */
.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.form-header h2 {
  margin: 0;
}

.hero {
  display: grid;
  gap: 2rem;
  padding: 3rem 5vw;
  background: radial-gradient(circle at top left, #e0f2fe, #f4f6fb 45%);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-items: center;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: #2563eb;
  margin-bottom: 0.5rem;
}

.hero h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 4vw, 3rem);
}

.subtitle {
  font-size: 1.05rem;
  line-height: 1.6;
  max-width: 540px;
}

.hero-card {
  background: #fff;
  padding: 1.5rem;
  border-radius: 1.5rem;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.1);
}

.meta-list {
  padding-left: 1rem;
  margin: 1rem 0 0;
}

.hero-cta {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cta-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

.cta-link:hover {
  background: #1d4ed8;
}

.cta-secondary {
  background: transparent;
  border: 2px solid #2563eb;
  color: #2563eb;
}

.cta-secondary:hover {
  background: #eff6ff;
}

.cta-urgence {
  background: #dc2626;
  color: #fff;
}

.cta-urgence:hover {
  background: #b91c1c;
}

.hero-links {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.cta-note {
  margin: 0;
  font-size: 0.9rem;
  color: #475569;
}

.layout {
  display: grid;
  gap: 2rem;
  padding: 2rem 5vw;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
}

.panel {
  background: #fff;
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
}

.panel.full {
  margin: 0 5vw 2rem;
}

.tabs {
  margin: 0 5vw 2rem;
}

.tabs-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: #e2e8f0;
  border-radius: 999px;
  width: fit-content;
  margin: 1.5rem 0;
}

.tab-button {
  border: none;
  background: transparent;
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  color: #475569;
}

.tab-button.is-active {
  background: #2563eb;
  color: #fff;
}

.tab-panel {
  display: block;
}

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

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 1rem 0;
}

.grid.sliders label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.95rem;
}

input,
select,
textarea {
  padding: 0.6rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #d1d5db;
  font-size: 0.95rem;
}

button.primary {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 0.75rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  cursor: pointer;
}

button.primary:hover {
  background: #1d4ed8;
}

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
  border: 1px solid #2563eb;
  padding: 0.7rem 1.25rem;
  color: #1d4ed8;
  font-weight: 600;
  text-decoration: none;
}

.secondary:hover {
  background: #eff6ff;
}

.psychotech-block {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 1rem;
  border: 1px dashed #cbd5f5;
  background: #f8fafc;
  margin-bottom: 1rem;
}

.status {
  min-height: 1.5rem;
  margin-top: 0.5rem;
  color: #16a34a;
}

.card {
  background: #f8fafc;
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid #e2e8f0;
  min-height: 120px;
}

.entries {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.entry-item {
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
}

.cards {
  margin-top: 1rem;
}

.card-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  padding: 1rem;
}

.search-row {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.badge {
  background: #e0e7ff;
  color: #3730a3;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.mixtures-list {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 1rem 0 1.5rem;
}

.mixtures-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 0.9rem;
}

.mixtures-item input {
  margin: 0;
}

.matrix {
  overflow-x: auto;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  padding: 1rem;
  background: #fff;
}

.matrix table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.matrix th,
.matrix td {
  border: 1px solid #e2e8f0;
  padding: 0.5rem;
  text-align: center;
  min-width: 120px;
}

.matrix th {
  background: #f1f5f9;
  position: sticky;
  top: 0;
}

.matrix-cell {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}

.risk-0 { background: #16a34a; }
.risk-1 { background: #4ade80; }
.risk-2 { background: #f59e0b; }
.risk-3 { background: #ef4444; }
.risk-4 { background: #7f1d1d; }

.helper {
  font-size: 0.85rem;
  color: #6b7280;
}

.footer {
  padding: 2rem 5vw;
  text-align: center;
  color: #6b7280;
}

.chart-controls {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}

.chart-controls label {
  flex: 1;
  max-width: 300px;
}

.chart-container {
  position: relative;
  width: 100%;
  max-height: 420px;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  /* ── Topbar: two-row compact layout ── */
  .topbar {
    flex-wrap: wrap;
    gap: 0.3rem;
    padding: 0.4rem 3vw;
    font-size: 0.78rem;
  }

  .topbar-left {
    gap: 0.4rem;
    flex-wrap: wrap;
    width: 100%;
    order: 2;
    justify-content: center;
  }

  .topbar-left strong {
    width: 100%;
    text-align: center;
    order: -1;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid #334155;
    margin-bottom: 0.15rem;
    font-size: 0.82rem;
  }

  .topbar-left a {
    padding: 0.2rem 0.4rem;
    border-radius: 0.3rem;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .topbar-left a:hover,
  .topbar-left a:active {
    background: #334155;
  }

  .topbar-right {
    width: 100%;
    justify-content: center;
    gap: 0.5rem;
    order: 1;
    padding-bottom: 0.25rem;
  }

  #user-name {
    font-size: 0.75rem;
  }

  .topbar-logout {
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
  }

  /* ── Hero: compact ── */
  .hero {
    padding: 1rem 4vw;
    gap: 1rem;
  }

  .hero h1 {
    font-size: 1.35rem;
    line-height: 1.2;
  }

  .subtitle {
    font-size: 0.85rem;
    line-height: 1.4;
  }

  .hero-card {
    padding: 1rem;
  }

  .hero-cta {
    margin-top: 1rem;
  }

  .cta-link {
    padding: 0.55rem 1rem;
    font-size: 0.88rem;
  }

  /* ── Tabs: scrollable pill bar ── */
  .tabs {
    margin: 0 3vw 1rem;
  }

  .tabs-header {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    width: 100%;
    gap: 0.2rem;
    padding: 0.3rem;
    margin: 0.75rem 0;
    scrollbar-width: none;
  }

  .tabs-header::-webkit-scrollbar {
    display: none;
  }

  .tab-button {
    padding: 0.45rem 0.8rem;
    font-size: 0.78rem;
    flex-shrink: 0;
    min-height: 36px;
  }

  /* ── Layout: single column ── */
  .layout {
    padding: 0.75rem 3vw;
    gap: 0.75rem;
  }

  .panel {
    padding: 0.85rem;
    border-radius: 0.85rem;
  }

  .panel.full {
    margin: 0 3vw 1rem;
    padding: 1rem;
  }

  /* ── Form: sticky submit bar at bottom ── */
  .form-header {
    margin-bottom: 0.25rem;
  }

  .form-header h2 {
    font-size: 1.1rem;
  }

  .form-header button.primary {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    border-radius: 0;
    padding: 0.9rem 1rem;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.15);
    min-height: 48px;
  }

  #tab-observations {
    padding-bottom: 3.5rem;
  }

  /* ── Form grid: single-column fields ── */
  .grid {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .span-2 {
    grid-column: auto;
  }

  label {
    gap: 0.25rem;
    font-size: 0.88rem;
  }

  input,
  select,
  textarea {
    padding: 0.55rem 0.65rem;
    font-size: 0.9rem;
    min-height: 40px;
  }

  /* ── Sliders: 2-column compact grid ── */
  .grid.sliders {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.35rem 0.5rem;
  }

  .grid.sliders label {
    font-size: 0.72rem;
    gap: 0.1rem;
    color: #334155;
  }

  .grid.sliders input[type="range"] {
    height: 24px;
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
  }

  .grid.sliders input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  /* Visible section heading for sliders */
  .panel h3 {
    font-size: 0.95rem;
    margin: 0.75rem 0 0.35rem;
  }

  /* ── Charts: smaller, touch-friendly ── */
  .chart-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .chart-controls label {
    max-width: none;
  }

  .chart-container {
    max-height: 220px;
    min-height: 160px;
  }

  .chart-container h3 {
    font-size: 0.9rem;
  }

  /* ── Search row ── */
  .search-row {
    flex-direction: column;
    gap: 0.5rem;
  }

  .search-row input[type="search"] {
    width: 100%;
  }

  /* ── Matrix: compact scrollable table ── */
  .matrix {
    padding: 0.5rem;
    border-radius: 0.75rem;
  }

  .matrix table {
    font-size: 0.75rem;
  }

  .matrix th,
  .matrix td {
    padding: 0.3rem;
    min-width: 80px;
  }

  .risk-badge {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
  }

  /* ── Mixtures list: single column ── */
  .mixtures-list {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .mixtures-item {
    padding: 0.45rem 0.6rem;
    font-size: 0.82rem;
    min-height: 40px;
  }

  /* ── Substance grid ── */
  .grid.cards {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .card-item {
    padding: 0.75rem;
  }

  .card-item h4 {
    font-size: 0.95rem;
    margin: 0 0 0.3rem;
  }

  .card-item p {
    font-size: 0.82rem;
    margin: 0.15rem 0;
  }

  /* ── Entries sidebar ── */
  .entries {
    gap: 0.5rem;
  }

  .entry-item {
    padding: 0.6rem;
    font-size: 0.82rem;
  }

  /* ── Button touch targets ── */
  button.primary {
    min-height: 44px;
    padding: 0.7rem 1.25rem;
  }

  .secondary {
    min-height: 44px;
    padding: 0.6rem 1rem;
  }

  /* ── Status ── */
  .status {
    font-size: 0.85rem;
  }

  /* ── Footer ── */
  .footer {
    padding: 1.25rem 3vw;
    font-size: 0.82rem;
  }
}

/* ── Extra-small screens (≤380px) ── */
@media (max-width: 380px) {
  .topbar-left a {
    font-size: 0.68rem;
    padding: 0.15rem 0.3rem;
  }

  .hero h1 {
    font-size: 1.15rem;
  }

  .tab-button {
    padding: 0.35rem 0.65rem;
    font-size: 0.72rem;
  }

  .grid.sliders {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .grid.sliders label {
    font-size: 0.78rem;
  }

  .chart-container {
    max-height: 180px;
    min-height: 140px;
  }
}
