/* Breathe Easy — senior-friendly, offline-first UI */

:root {
  --accent: #0E7490;
  --accent-hover: #0B5F75;
  --accent-soft: #E0F4F8;
  --accent-mid: #155E75;
  --accent-ink: #164E63;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --ok: #166534;
  --ok-soft: #DCFCE7;
  --text: #1C1917;
  --text-muted: #57534E;
  --border: #D6D3D1;
  --surface: #FFFFFF;
  --surface-2: #F5F3F0;
  --bg: #F4F7F8;
  --shadow: 0 2px 10px rgba(28, 25, 23, 0.08);
  --shadow-lg: 0 8px 28px rgba(28, 25, 23, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 720px;
  --space: 1rem;
}

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

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

img {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

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

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 1000;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
}

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

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent-ink);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #991b1b;
}

.btn-text {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  min-width: auto;
  padding: 0.5rem 0.65rem;
}

.btn-text:hover:not(:disabled) {
  background: var(--accent-soft);
}

.btn-danger-text {
  color: var(--danger);
}

.btn-danger-text:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-icon {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.35rem;
  min-width: var(--touch);
  min-height: var(--touch);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-lg {
  min-height: 56px;
  padding: 0.85rem 1.4rem;
  font-size: 1.05rem;
}

.btn-sm {
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  font-size: 0.95rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Tabs */
.tab-nav {
  display: flex;
  gap: 0.25rem;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.65rem 0.75rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 1 1 auto;
  min-height: var(--touch);
  min-width: 5.5rem;
  padding: 0.6rem 0.75rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.tab:hover {
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.tab.active,
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Main */
main {
  flex: 1;
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.panel[hidden] {
  display: none !important;
}

.panel-title {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  color: var(--accent-ink);
}

.panel-lead {
  margin: 0 0 1.1rem;
  color: var(--text-muted);
}

.panel-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.panel-head-row .panel-title {
  margin-bottom: 0.25rem;
}

.panel-head-row .panel-lead {
  margin-bottom: 0;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}

@media (min-width: 560px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 0.85rem;
  box-shadow: var(--shadow);
}

.stat-card.stat-accent {
  background: var(--accent-soft);
  border-color: #A5D8E2;
}

.stat-label {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  margin: 0.2rem 0 0.45rem;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent-ink);
}

.stat-unit {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0.25rem 0;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stat-link:hover {
  color: var(--accent-hover);
}

/* Goal bar */
.goal-bar-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow);
}

.goal-bar-label {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.goal-bar-label span:last-child {
  color: var(--text-muted);
  font-weight: 500;
}

.goal-bar {
  height: 14px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.goal-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-mid), var(--accent));
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-muted {
  background: var(--surface-2);
}

.card-soft {
  background: var(--accent-soft);
  border-color: #A5D8E2;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.card h3 {
  margin: 0 0 0.65rem;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.card-head h3 {
  margin: 0;
}

.help-text {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Filters / forms */
.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (min-width: 560px) {
  .filters {
    grid-template-columns: 1.4fr 1fr 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field label,
.feeling-fieldset legend {
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select,
.field textarea,
.inline-field input {
  min-height: var(--touch);
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}

.field textarea {
  min-height: 5rem;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.inline-field input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.2);
}

.field .error,
.form-error {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0.25rem 0 0;
}

.inline-field {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.inline-field input {
  max-width: 8rem;
}

.settings-inline {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.settings-inline > label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  min-height: var(--touch);
  padding: 0.35rem 0;
}

.checkbox-row input {
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.2rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 480px) {
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Lists */
.item-list,
.exercise-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.item-card,
.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.exercise-list.compact .exercise-card {
  box-shadow: none;
  background: var(--surface-2);
}

.item-card-head,
.exercise-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.item-card h4,
.exercise-card h4 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

.item-meta,
.exercise-meta {
  margin: 0.3rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.item-notes {
  margin: 0.45rem 0 0;
  color: var(--text);
}

.item-actions,
.exercise-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-ink);
  white-space: nowrap;
}

.pill-sample {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill-fav {
  background: #FEF9C3;
  color: #854D0E;
}

.pill-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill-muted {
  background: var(--surface-2);
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state strong {
  display: block;
  color: var(--text);
  margin-bottom: 0.35rem;
  font-size: 1.05rem;
}

.list-summary {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Insights */
.insights-list {
  margin: 0;
  padding-left: 1.2rem;
}

.insights-list li {
  margin-bottom: 0.55rem;
}

.insights-list li:last-child {
  margin-bottom: 0;
}

.edu-list {
  margin: 0;
  padding-left: 1.2rem;
}

.edu-list li {
  margin-bottom: 0.65rem;
}

.edu-list li:last-child {
  margin-bottom: 0;
}

/* Week chart */
.week-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.45rem;
  align-items: end;
  min-height: 160px;
  padding-top: 0.5rem;
}

.week-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  height: 150px;
  justify-content: flex-end;
}

.week-bar {
  width: 100%;
  max-width: 42px;
  min-height: 4px;
  background: var(--accent);
  border-radius: 6px 6px 4px 4px;
  transition: height 0.3s ease;
}

.week-bar.is-zero {
  background: var(--border);
  min-height: 6px;
}

.week-bar-val {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.week-bar-day {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Feeling summary */
.feeling-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

@media (min-width: 480px) {
  .feeling-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.feeling-stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  text-align: center;
}

.feeling-stat strong {
  display: block;
  font-size: 1.4rem;
  color: var(--accent-ink);
}

.feeling-stat span {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.feeling-fieldset {
  border: none;
  margin: 0 0 1rem;
  padding: 0;
}

.feeling-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.feeling-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--touch);
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}

.feeling-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.feeling-option input {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--accent);
}

/* Practice UI */
.practice-body {
  text-align: center;
}

.practice-sub {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-weight: 600;
}

.breath-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.25rem;
}

.breath-circle {
  width: min(220px, 70vw);
  height: min(220px, 70vw);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  border: 4px solid var(--accent);
  box-shadow: var(--shadow-lg);
  transition: transform 0.9s ease-in-out, background 0.4s ease, border-color 0.4s ease;
  margin-bottom: 1rem;
}

.breath-circle[data-phase="inhale"] {
  transform: scale(1.12);
  background: #CFFAFE;
  border-color: var(--accent);
}

.breath-circle[data-phase="hold"],
.breath-circle[data-phase="holdOut"] {
  transform: scale(1.08);
  background: #E0F2FE;
  border-color: #0284C7;
}

.breath-circle[data-phase="exhale"] {
  transform: scale(0.88);
  background: #ECFDF5;
  border-color: #0F766E;
}

.breath-circle[data-phase="ready"],
.breath-circle[data-phase="paused"],
.breath-circle[data-phase="done"] {
  transform: scale(1);
}

.breath-phase {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.breath-count {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  margin-top: 0.15rem;
}

.breath-instruction {
  margin: 0;
  max-width: 28rem;
  color: var(--text);
  font-size: 1.05rem;
}

.practice-meta {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  font-size: 1rem;
}

.meta-label {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 0.25rem;
}

.practice-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

/* Dialogs */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(96vw, 520px);
  max-height: min(92vh, 900px);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  background: var(--surface);
}

.modal::backdrop {
  background: rgba(28, 25, 23, 0.5);
}

.modal-sm {
  width: min(96vw, 420px);
}

.modal-practice {
  width: min(96vw, 480px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--accent-ink);
}

.modal-body {
  padding: 1rem;
  overflow-y: auto;
  max-height: calc(92vh - 9rem);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--accent-ink);
  color: #fff;
  padding: 0.85rem 1.2rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  max-width: min(92vw, 420px);
  text-align: center;
}

.toast[hidden] {
  display: none;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.25rem 1rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  margin: 0;
  max-width: var(--max);
  margin-inline: auto;
}

/* Detail content */
.detail-block {
  margin-bottom: 0.85rem;
}

.detail-block h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  color: var(--accent-ink);
}

.detail-block p {
  margin: 0;
  color: var(--text);
}

.timing-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.timing-chip {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
  text-align: center;
}

.timing-chip strong {
  display: block;
  font-size: 1.2rem;
  color: var(--accent);
}

.timing-chip span {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.reminder-due {
  border-left: 4px solid var(--accent);
}

.reminder-done-today {
  opacity: 0.85;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .breath-circle,
  .goal-bar-fill,
  .week-bar,
  .btn {
    transition: none;
  }
}
