.page-journal {
  background: #f4f6fb;
  min-height: 100vh;
  font-family: 'Inter', system-ui, sans-serif;
  color: #1f2933;
  margin: 0;
}

.journal-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 5vw;
  font-size: 0.9rem;
}

.nav-spacer {
  flex: 1;
}

.nav-user {
  color: #64748b;
  font-size: 0.85rem;
}

.nav-logout {
  border: 1px solid #d1d5db;
  background: transparent;
  color: #64748b;
  padding: 0.25rem 0.6rem;
  border-radius: 0.4rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.nav-logout:hover {
  background: #f1f5f9;
}

.journal-nav a {
  color: #475569;
  text-decoration: none;
}

.journal-nav a:hover {
  color: #1f2933;
}

.journal-header {
  padding: 2rem 5vw 1rem;
}

.journal-header h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
}

.journal-subtitle {
  color: #475569;
  max-width: 600px;
  line-height: 1.6;
}

.journal-main {
  padding: 0 5vw 4rem;
}

.journal-filters {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 2rem;
}

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

.journal-filters input {
  padding: 0.6rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid #d1d5db;
  font-size: 0.95rem;
  width: 220px;
}

.journal-filters .primary {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 0.75rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* Timeline navigation */
.timeline-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.timeline-nav button {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: #475569;
  white-space: nowrap;
}

.timeline-nav button:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.timeline-nav input[type="date"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  color: #1e293b;
}

.nav-range {
  font-size: 0.85rem;
  color: #64748b;
  margin-left: auto;
}

.journal-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.summary-card {
  background: #fff;
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  text-align: center;
}

.summary-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: #2563eb;
}

.summary-label {
  font-size: 0.85rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.journal-empty {
  color: #94a3b8;
  text-align: center;
  padding: 3rem;
}

/* Timeline */
.journal-day {
  margin-bottom: 2rem;
}

.journal-day-header {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e293b;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 1rem;
}

.journal-entry {
  background: #fff;
  border-radius: 1rem;
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: start;
}

.entry-time {
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  padding-top: 2px;
  min-width: 50px;
}

.entry-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.entry-headline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.entry-substance {
  font-weight: 700;
  font-size: 1.05rem;
  color: #1e293b;
}

.entry-dose {
  background: #e0f2fe;
  color: #0369a1;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.entry-route {
  background: #f0fdf4;
  color: #15803d;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.entry-moment {
  background: #fef3c7;
  color: #92400e;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.entry-followup {
  font-size: 0.8rem;
  color: #94a3b8;
}

.entry-notes {
  font-size: 0.9rem;
  color: #475569;
  font-style: italic;
  line-height: 1.5;
}

.entry-ratings {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.rating-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: #475569;
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 6px;
}

.rating-bar {
  width: 40px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}

.rating-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.2s;
}

.rating-low { background: #22c55e; }
.rating-mid { background: #f59e0b; }
.rating-high { background: #ef4444; }

/* Test session entries */
.entry-test-badge {
  background: #ede9fe;
  color: #6d28d9;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.entry-test-quality {
  font-size: 0.85rem;
  font-weight: 600;
}

.quality-good { color: #16a34a; }
.quality-mixed { color: #f59e0b; }
.quality-poor { color: #dc2626; }

/* Entry actions */
.entry-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.entry-actions button {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
  color: #64748b;
}

.entry-actions button:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.entry-actions .btn-delete:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fca5a5;
}

/* Edit modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  background: #fff;
  border-radius: 1rem;
  padding: 1.5rem 2rem;
  width: 90vw;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.2);
}

.modal-panel h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.modal-field {
  margin-bottom: 0.75rem;
}

.modal-field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.25rem;
}

.modal-field input,
.modal-field select,
.modal-field textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  box-sizing: border-box;
}

.modal-field textarea {
  resize: vertical;
  min-height: 60px;
}

.modal-field input[type="range"] {
  padding: 0;
}

.modal-range-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-range-row input[type="range"] {
  flex: 1;
}

.modal-range-row .range-value {
  min-width: 2ch;
  text-align: right;
  font-weight: 600;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.modal-actions button {
  padding: 0.5rem 1.2rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #475569;
}

.modal-actions .btn-save {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
  font-weight: 600;
}

.modal-actions .btn-save:hover {
  background: #1d4ed8;
}

@media (max-width: 640px) {
  /* ── Journal nav: compact centered links ── */
  .journal-nav {
    flex-wrap: wrap;
    gap: 0.3rem 0.6rem;
    padding: 0.5rem 3vw;
    font-size: 0.78rem;
    justify-content: center;
  }

  .nav-spacer {
    display: none;
  }

  .journal-nav a {
    padding: 0.2rem 0.3rem;
    font-size: 0.75rem;
  }

  .nav-user {
    font-size: 0.72rem;
  }

  .nav-logout {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }

  /* ── Header: compact ── */
  .journal-header {
    padding: 0.85rem 3vw 0.5rem;
  }

  .journal-header h1 {
    font-size: 1.3rem;
    margin-bottom: 0.3rem;
  }

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

  /* ── Main content ── */
  .journal-main {
    padding: 0 3vw 1.5rem;
  }

  /* ── Timeline nav: grid layout for buttons ── */
  .timeline-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.35rem;
    align-items: center;
    margin-bottom: 1rem;
  }

  .timeline-nav button {
    padding: 0.45rem 0.5rem;
    font-size: 0.75rem;
    min-height: 38px;
    white-space: nowrap;
  }

  #nav-prev {
    grid-column: 1;
    grid-row: 1;
    justify-self: stretch;
    text-align: center;
  }

  #nav-today {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
  }

  #nav-next {
    grid-column: 3;
    grid-row: 1;
    justify-self: stretch;
    text-align: center;
  }

  #nav-date {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    min-height: 38px;
    font-size: 0.82rem;
    text-align: center;
  }

  .nav-range {
    grid-column: 1 / -1;
    grid-row: 3;
    width: 100%;
    text-align: center;
    margin-left: 0;
    font-size: 0.8rem;
    padding-top: 0.15rem;
  }

  /* ── Summary: 2x2 compact grid ── */
  .journal-summary {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
    margin-bottom: 1.25rem;
  }

  .summary-card {
    padding: 0.6rem;
    border-radius: 0.75rem;
  }

  .summary-value {
    font-size: 1.4rem;
  }

  .summary-label {
    font-size: 0.7rem;
  }

  /* ── Day headers ── */
  .journal-day {
    margin-bottom: 1.25rem;
  }

  .journal-day-header {
    font-size: 0.95rem;
    padding-bottom: 0.35rem;
    margin-bottom: 0.6rem;
  }

  /* ── Entry cards: single-column, compact ── */
  .journal-entry {
    grid-template-columns: 1fr;
    padding: 0.75rem;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
    border-radius: 0.75rem;
  }

  .entry-time {
    font-size: 0.72rem;
    font-weight: 700;
    color: #2563eb;
    padding: 0;
  }

  .entry-body {
    gap: 0.35rem;
  }

  .entry-headline {
    gap: 0.3rem;
  }

  .entry-substance {
    font-size: 0.92rem;
  }

  .entry-dose,
  .entry-route,
  .entry-moment,
  .entry-test-badge {
    font-size: 0.72rem;
    padding: 1px 7px;
  }

  .entry-followup {
    font-size: 0.7rem;
  }

  .entry-notes {
    font-size: 0.82rem;
    line-height: 1.4;
  }

  /* ── Rating chips: compact ── */
  .entry-ratings {
    gap: 0.3rem;
  }

  .rating-chip {
    font-size: 0.7rem;
    padding: 2px 5px;
    gap: 3px;
  }

  .rating-bar {
    width: 30px;
    height: 5px;
  }

  /* ── Entry actions: touch-friendly ── */
  .entry-actions {
    gap: 0.35rem;
  }

  .entry-actions button {
    padding: 0.4rem 0.65rem;
    font-size: 0.75rem;
    min-height: 36px;
    border-radius: 0.4rem;
  }

  /* ── Test sessions ── */
  .entry-test-quality {
    font-size: 0.78rem;
  }

  /* ── Modal: nearly full-screen on mobile ── */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-panel {
    padding: 1rem 1rem 1.5rem;
    width: 100vw;
    max-width: 100vw;
    max-height: 92vh;
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.25);
  }

  .modal-panel h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
  }

  .modal-field {
    margin-bottom: 0.5rem;
  }

  .modal-field label {
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
  }

  .modal-field input,
  .modal-field select,
  .modal-field textarea {
    font-size: 0.88rem;
    padding: 0.5rem;
    min-height: 40px;
  }

  .modal-range-row {
    gap: 0.35rem;
  }

  .modal-range-row .range-value {
    font-size: 0.82rem;
  }

  .modal-actions {
    margin-top: 0.75rem;
    gap: 0.5rem;
  }

  .modal-actions button {
    padding: 0.55rem 1rem;
    font-size: 0.88rem;
    min-height: 44px;
    flex: 1;
  }
}

/* ── Extra-small screens (≤380px) ── */
@media (max-width: 380px) {
  .journal-nav {
    font-size: 0.72rem;
    gap: 0.2rem 0.4rem;
  }

  .journal-header h1 {
    font-size: 1.15rem;
  }

  .timeline-nav button {
    font-size: 0.68rem;
    padding: 0.35rem 0.35rem;
  }

  .summary-value {
    font-size: 1.2rem;
  }

  .entry-substance {
    font-size: 0.85rem;
  }

  .entry-headline {
    gap: 0.2rem;
  }

  .rating-chip {
    font-size: 0.65rem;
  }
}
