:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface2: #f9f7f4;
  --text: #1c1917;
  --text-sec: #78716c;
  --text-hint: #a8a29e;
  --accent: #2d6a4f;
  --accent-light: #d8f3dc;
  --warn: #c77a3c;
  --warn-light: #fef3e2;
  --danger: #9b2335;
  --danger-light: #fde8eb;
  --border: #e7e3dc;
  --radius: 18px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121410;
    --surface: #1c1f1a;
    --surface2: #242822;
    --text: #f0ede8;
    --text-sec: #9e9b96;
    --text-hint: #6b6864;
    --border: #2e3129;
    --accent-light: rgba(45, 106, 79, 0.18);
    --warn-light: rgba(199, 122, 60, 0.15);
    --danger-light: rgba(155, 35, 53, 0.15);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 560px;
  padding: 24px 20px 60px;
}

.app-main {
  display: block;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 28px;
}

.app-header-left h1,
#setupScreen h2,
.card-title,
.modal h3,
.report-block h4 {
  font-family: Georgia, "Times New Roman", serif;
}

.app-header-left h1 {
  font-size: 28px;
  line-height: 1.1;
}

.subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-sec);
}

.streak-badge {
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid rgba(45, 106, 79, 0.15);
}

#setupScreen,
.card,
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
}

#setupScreen {
  padding: 32px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.setup-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

#setupScreen h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

#setupScreen p,
.modal p {
  color: var(--text-sec);
  font-size: 14px;
  line-height: 1.6;
}

.card {
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 19px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 8px;
  padding: 3px 8px;
  text-transform: uppercase;
}

.med-bar,
.saved-today-banner,
.weekly-banner {
  display: flex;
  align-items: center;
}

.med-bar {
  background: var(--accent-light);
  border: 1px solid rgba(45, 106, 79, 0.2);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 16px;
  justify-content: space-between;
  gap: 12px;
}

.med-bar-info strong {
  display: block;
  font-size: 15px;
  color: var(--accent);
}

.med-bar-info span {
  font-size: 13px;
  color: var(--text-sec);
}

.med-bar-edit {
  background: none;
  border: 1px solid rgba(45, 106, 79, 0.3);
  border-radius: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

input[type="text"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 13px 15px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface2);
  color: var(--text);
  outline: none;
}

textarea {
  height: 72px;
  resize: none;
}

.field-hint,
.helper-text {
  line-height: 1.5;
}

.field-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-hint);
}

.helper-text {
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-sec);
}

.helper-text strong {
  color: var(--text);
}

.slider-group {
  margin-bottom: 20px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.slider-label {
  font-size: 14px;
  font-weight: 500;
}

.slider-value {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  color: var(--accent);
  min-width: 28px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  background: transparent;
  height: 32px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 24px;
  width: 24px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -8px;
  box-shadow: 0 2px 8px rgba(45, 106, 79, 0.3);
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-hint);
}

.nw-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.nw-item {
  position: relative;
}

.nw-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
}

.nw-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.nw-item label::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}

.nw-item input:checked + label {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

.nw-item input:checked + label::before {
  background: var(--danger);
  border-color: var(--danger);
}

.nw-custom-add,
.chip-row,
.nw-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.nw-custom-add {
  margin-top: 8px;
}

.nw-custom-add input {
  flex: 1;
}

.btn,
.btn-add,
.btn-chip,
.weekly-banner-btn,
.modal-close {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 16px rgba(45, 106, 79, 0.25);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-warn {
  background: var(--warn-light);
  color: var(--warn);
  border: 1.5px solid rgba(199, 122, 60, 0.2);
}

.btn-danger {
  background: none;
  color: var(--text-hint);
  border: 1px solid var(--border);
  font-size: 13px;
  margin-top: 8px;
}

.btn-add,
.weekly-banner-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
}

.btn-add {
  background: var(--accent);
  color: white;
}

.chip-row {
  margin-bottom: 14px;
}

.btn-chip {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
}

.btn-chip.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(45, 106, 79, 0.25);
}

.btn-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.saved-today-banner {
  gap: 12px;
  background: var(--accent-light);
  border: 1px solid rgba(45, 106, 79, 0.2);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

#historySection {
  margin-top: 18px;
}

.history-range-row,
.utility-row {
  margin-top: 12px;
}

.chart-wrap {
  height: 220px;
  margin-bottom: 16px;
  position: relative;
}

.history-list {
  margin-top: 8px;
}

.history-entry {
  padding: 14px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.history-entry-date {
  font-weight: 600;
  color: var(--text-sec);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.history-entry-metrics {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.metric-pill {
  background: var(--surface2);
  border-radius: 8px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-sec);
  border: 1px solid var(--border);
}

.nw-pill {
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
}

.report-section {
  margin-top: 16px;
}

.report-block {
  background: var(--surface2);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.report-block h4 {
  font-size: 16px;
  margin-bottom: 10px;
}

.report-stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-sec);
}

.report-stat:last-child {
  border-bottom: none;
}

.report-stat strong {
  color: var(--text);
}

.weekly-banner {
  background: linear-gradient(135deg, var(--warn-light), var(--surface));
  border: 1.5px solid rgba(199, 122, 60, 0.3);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  gap: 14px;
}

.weekly-banner-icon {
  font-size: 32px;
}

.weekly-banner-text strong {
  display: block;
  font-size: 15px;
  margin-bottom: 3px;
}

.weekly-banner-text span {
  font-size: 13px;
  color: var(--text-sec);
}

.weekly-banner-btn {
  margin-left: auto;
  background: var(--warn);
  color: white;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal {
  border-radius: 24px 24px 0 0;
  padding: 20px 24px 40px;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal h3 {
  font-size: 22px;
  margin-bottom: 6px;
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

.modal-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-sec);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--surface);
  padding: 11px 22px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}

#toast.show {
  transform: translateX(-50%) translateY(0);
}

.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;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(45, 106, 79, 0.28);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

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

  #toast,
  .btn,
  .btn-chip {
    transition: none;
  }
}

@media print {
  .no-print {
    display: none !important;
  }

  body {
    background: white;
  }

  .card,
  .report-block {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

@media (max-width: 520px) {
  .btn-row {
    grid-template-columns: 1fr;
  }

  .weekly-banner {
    flex-wrap: wrap;
  }

  .weekly-banner-btn {
    margin-left: 0;
  }

  .nw-grid {
    grid-template-columns: 1fr;
  }
}
