:root {
  color-scheme: light;
  --background: #f5f4ef;
  --surface: #ffffff;
  --surface-muted: #ecebe5;
  --text: #1e2927;
  --muted: #64716e;
  --primary: #265d55;
  --primary-dark: #19473f;
  --primary-soft: #d9e9e5;
  --border: #d9dedb;
  --danger: #a63030;
  --danger-soft: #fbe2df;
  --shadow: 0 8px 28px rgb(30 41 39 / 8%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid #4f9c90;
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 7vw, 2.25rem);
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
}

.view {
  padding: 24px 16px calc(102px + env(safe-area-inset-bottom));
}

[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 24px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.muted,
.optional {
  color: var(--muted);
}

.optional {
  font-size: 0.84em;
  font-weight: 400;
}

.login-view {
  display: grid;
  min-height: 100vh;
  padding-bottom: 24px;
  place-items: center;
}

.login-card {
  width: min(100%, 390px);
  padding: 30px 22px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.app-mark {
  width: 68px;
  height: 68px;
  margin-bottom: 18px;
  border-radius: 20px;
  background: var(--primary-soft);
  font-size: 2.15rem;
  line-height: 68px;
  text-align: center;
}

.login-card h1 {
  margin-bottom: 8px;
}

.login-card form {
  margin-top: 24px;
}

label,
legend {
  color: #34423f;
  font-weight: 700;
}

input[type="password"],
input[type="date"],
input[type="time"],
textarea {
  width: 100%;
  min-height: 48px;
  margin-top: 7px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  background: var(--surface);
  font-size: 1rem;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.primary-button,
.secondary-button,
.compact-button,
.icon-button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  font-weight: 750;
}

.primary-button {
  padding: 0 18px;
  color: white;
  background: var(--primary);
}

.primary-button:active {
  background: var(--primary-dark);
}

.secondary-button {
  padding: 0 16px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
}

.compact-button {
  min-width: 92px;
  padding: 0 14px;
  color: var(--primary-dark);
  background: var(--surface);
}

.icon-button {
  width: 48px;
  flex: 0 0 48px;
  color: var(--text);
  background: var(--surface);
  font-size: 2rem;
  line-height: 1;
}

.full-width {
  width: 100%;
  margin-top: 12px;
}

.form-error {
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 650;
}

.pain-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -8px 0 18px;
  padding: 14px;
  border-radius: 15px;
  color: #3f2c08;
  background: #ffe6a5;
}

.pain-banner span {
  display: block;
  margin-top: 3px;
  font-size: 0.88rem;
}

.quick-actions {
  display: grid;
  gap: 11px;
}

.quick-button {
  display: flex;
  min-height: 70px;
  padding: 13px 17px;
  border: 0;
  border-radius: 16px;
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
  color: var(--text);
  font-size: 1.07rem;
  font-weight: 800;
  text-align: left;
}

.quick-button small {
  margin: 4px 0 0 29px;
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0.78;
}

.migtan-button {
  background: #dcebf6;
}

.flunarizina-button {
  background: #e5e1f7;
}

.flunarizina-button.taken {
  color: #35443f;
  background: #d9e8df;
}

.episode-button {
  color: #4d260e;
  background: #f8dcc7;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}

.count-badge {
  min-width: 27px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.record-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  padding: 24px 16px;
  border: 1px dashed #c9cfcc;
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}

.record-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.record-main {
  min-width: 0;
}

.record-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-weight: 800;
}

.record-time {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.record-detail,
.record-notes {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.record-notes {
  margin-top: 4px;
  color: #46534f;
}

.record-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.record-action {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 11px;
  background: var(--surface-muted);
  font-size: 1rem;
}

.record-action.delete {
  background: var(--danger-soft);
}

.form-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.episode-form {
  display: grid;
  gap: 24px;
}

.intensity-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}

.intensity-field > label {
  align-self: center;
  font-size: 1.12rem;
}

.intensity-field output {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  color: white;
  font-size: 1.65rem;
  font-weight: 850;
  line-height: 54px;
  text-align: center;
}

input[type="range"] {
  width: 100%;
  height: 32px;
  grid-column: 1 / -1;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

input[type="range"]::-webkit-slider-thumb {
  width: 30px;
  height: 30px;
}

.range-labels {
  display: flex;
  grid-column: 1 / -1;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 10px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 48px;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #3d4946;
  background: var(--surface);
  font-size: 0.9rem;
  font-weight: 650;
}

.chip.selected {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.two-column-fields,
.end-time-row {
  display: grid;
  gap: 16px;
}

.checkbox-label {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 650;
}

.checkbox-label input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--primary);
}

.form-actions,
.calendar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.month-nav h2 {
  font-size: 1.25rem;
}

.calendar-card {
  padding: 10px 7px 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.weekday-row {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
}

.calendar-grid-cell {
  min-width: 0;
  min-height: 65px;
  padding: 6px 3px 4px;
  border: 2px solid transparent;
  border-radius: 10px;
  color: #17211f;
  background: var(--surface-muted);
  text-align: left;
}

.calendar-grid-cell.empty {
  border: 0;
  background: transparent;
}

button.calendar-grid-cell:active {
  transform: scale(0.97);
}

.calendar-grid-cell.selected {
  border-color: var(--primary-dark);
}

.calendar-grid-cell.today .day-number {
  display: inline-grid;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  color: white;
  background: var(--primary-dark);
  place-items: center;
}

.day-number {
  display: block;
  margin-bottom: 5px;
  font-size: 0.79rem;
  font-weight: 850;
}

.day-icons {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
}

.day-detail {
  margin-top: 22px;
  padding-top: 1px;
  border-top: 1px solid var(--border);
}

.day-detail .section-heading {
  margin-top: 20px;
}

.day-add-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
}

.day-add-actions .secondary-button {
  padding: 0 6px;
  font-size: 0.78rem;
}

.month-summary {
  margin-top: 24px;
  padding: 18px;
  border: 1px solid #c9d9d5;
  border-radius: 16px;
  background: #e7f0ed;
}

.month-summary h2 {
  margin-bottom: 15px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.summary-grid p {
  margin: 0;
  text-align: center;
}

.summary-grid strong,
.summary-grid span {
  display: block;
}

.summary-grid strong {
  margin-bottom: 5px;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.summary-grid span {
  color: #52615d;
  font-size: 0.7rem;
  line-height: 1.25;
}

.warning {
  margin: 16px 0 0;
  padding: 12px;
  border-radius: 11px;
  color: #73251f;
  background: #ffd9d4;
  font-size: 0.86rem;
  font-weight: 750;
  line-height: 1.4;
}

.calendar-actions {
  margin-top: 14px;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 6px max(10px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: rgb(255 255 255 / 95%);
  box-shadow: 0 -8px 24px rgb(30 41 39 / 7%);
  backdrop-filter: blur(12px);
}

.bottom-nav button {
  display: flex;
  min-height: 58px;
  border: 0;
  border-radius: 12px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  background: transparent;
  font-size: 0.77rem;
  font-weight: 750;
}

.bottom-nav button span {
  font-size: 1.2rem;
}

.bottom-nav button[aria-current="page"] {
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.toast {
  position: fixed;
  z-index: 50;
  right: 16px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  left: 16px;
  width: min(calc(100% - 32px), 500px);
  margin: auto;
  padding: 13px 16px;
  border-radius: 12px;
  color: white;
  background: #26332f;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  text-align: center;
}

@media (min-width: 560px) {
  .view {
    padding-right: 24px;
    padding-left: 24px;
  }

  .two-column-fields,
  .end-time-row {
    grid-template-columns: 1fr 1fr;
    align-items: end;
  }

  .calendar-grid-cell {
    min-height: 76px;
    padding: 8px 6px;
  }

  .day-icons {
    font-size: 0.72rem;
  }
}

@page {
  size: Letter portrait;
  margin: 0.45in;
}

@media print {
  :root {
    --text: #111;
    --muted: #333;
    --border: #999;
  }

  html,
  body {
    min-height: auto;
    color: #111;
    background: #fff;
  }

  .app-shell {
    width: 100%;
    min-height: auto;
  }

  .view {
    display: none !important;
  }

  #view-calendar {
    display: block !important;
    padding: 0;
  }

  .calendar-header,
  .month-nav button,
  .day-detail,
  .calendar-actions,
  .bottom-nav,
  .toast {
    display: none !important;
  }

  .month-nav {
    justify-content: center;
    margin-bottom: 0.16in;
  }

  .month-nav h2 {
    font-size: 18pt;
  }

  .calendar-card,
  .month-summary {
    border-color: #777;
    background: #fff;
    box-shadow: none;
    break-inside: avoid;
  }

  .calendar-grid-cell {
    min-height: 0.72in;
    border: 1px solid #bbb;
    border-radius: 3px;
    color: #111 !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .calendar-grid-cell.empty {
    border: 0;
  }

  .month-summary {
    margin-top: 0.18in;
    padding: 0.14in;
  }

  .month-summary h2 {
    margin-bottom: 0.1in;
  }

  .warning {
    margin-top: 0.1in;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
