/* Daily Devotion Companion — senior-friendly, offline-first UI */

:root {
  --accent: #3d5a4c;
  --accent-hover: #2f463b;
  --accent-soft: #e8f0ec;
  --accent-mid: #4f7362;
  --danger: #9b2c2c;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #1f6b4a;
  --ok-soft: #e6f4ed;
  --text: #1c2420;
  --text-muted: #4a554f;
  --border: #c8d2cc;
  --surface: #ffffff;
  --bg: #f4f7f5;
  --scripture-bg: #faf8f4;
  --shadow: 0 2px 10px rgba(28, 36, 32, 0.08);
  --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.55;
  display: flex;
  flex-direction: column;
}

.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;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.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;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.35rem;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}

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

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

/* Tabs */
.tab-nav {
  display: flex;
  gap: 0.25rem;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.5rem 0.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

/* stick under header: header is sticky; tabs also sticky for mobile scroll */
.app-header + .tab-nav {
  top: 0;
  /* re-sticky relative to viewport after header — allow natural flow */
  position: sticky;
  top: 0;
  z-index: 49;
  background: var(--bg);
}

.tab {
  flex: 1 0 auto;
  min-height: var(--touch);
  min-width: 4.5rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}

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

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

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

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

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-title {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
}

.panel-lead {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 1rem;
}

.panel-actions {
  margin-bottom: 1rem;
}

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

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

.card-head h3 {
  margin: 0;
  font-size: 1.15rem;
}

.card h3 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.verse-ref {
  margin: 0.25rem 0 0;
  font-weight: 600;
  color: var(--accent-mid);
  font-size: 1rem;
}

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

@media (min-width: 540px) {
  .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;
  box-shadow: var(--shadow);
}

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

.stat-value {
  margin: 0.25rem 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-link {
  margin-top: 0.4rem;
  padding: 0;
  min-height: auto;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* Devotion steps */
.step-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0 1rem;
}

.step-btn {
  min-height: 44px;
  padding: 0.4rem 0.7rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.step-btn.active,
.step-btn[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

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

.step-panel {
  display: none;
  margin-bottom: 1rem;
}

.step-panel.active {
  display: block;
}

.step-title {
  margin: 0.75rem 0 0.4rem;
  font-size: 1.05rem;
  color: var(--accent);
}

.scripture {
  margin: 0;
  padding: 1.1rem 1.15rem;
  background: var(--scripture-bg);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 1.1rem;
  line-height: 1.65;
  color: var(--text);
  font-style: italic;
}

.prayer-text {
  font-size: 1.05rem;
  line-height: 1.7;
}

.devotion-actions {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

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

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

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

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

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.55rem 1.1rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

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

.btn:disabled {
  opacity: 0.45;
  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);
  border-color: var(--accent);
}

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

.btn-text {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  min-width: auto;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

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

.btn-danger:hover:not(:disabled) {
  background: #7f2222;
}

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

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

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.75rem;
}

.btn-row:first-child {
  margin-top: 0;
}

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

/* Forms */
.field {
  margin-bottom: 0.9rem;
}

.field label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  color: var(--text);
}

.field input[type="text"],
.field input[type="search"],
.field input[type="date"],
.field input[type="time"],
.field select,
.field textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  background: var(--surface);
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.5;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.checkbox-field input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.2rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.checkbox-field label {
  margin: 0;
  font-weight: 500;
}

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

.form-error {
  margin: 0.5rem 0 0;
  padding: 0.6rem 0.75rem;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.filters {
  margin-bottom: 1rem;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 540px) {
  .filter-row {
    grid-template-columns: repeat(3, 1fr);
  }
}

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

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

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

.item-card h3,
.item-card h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

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

.item-body {
  margin: 0.5rem 0 0;
  color: var(--text);
}

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

.item-actions .btn {
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
}

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

.body-text {
  margin: 0 0 0.75rem;
}

.body-text:last-child {
  margin-bottom: 0;
}

.muted {
  color: var(--text-muted);
}

.status-msg {
  margin: 0.6rem 0 0;
  min-height: 1.3em;
  font-size: 0.95rem;
  color: var(--ok);
  font-weight: 600;
}

.sample-card {
  border-style: dashed;
  background: var(--accent-soft);
}

/* Insights */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.week-day {
  text-align: center;
  padding: 0.55rem 0.2rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg);
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}

.week-day.done {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.week-day.missed {
  background: var(--surface);
}

.week-day.today {
  box-shadow: 0 0 0 2px var(--accent);
}

.week-day .wd-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.week-day .wd-mark {
  font-size: 1.1rem;
  font-weight: 700;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 6.5rem 1fr 2.5rem;
  gap: 0.5rem;
  align-items: center;
}

.bar-label {
  font-weight: 600;
  font-size: 0.95rem;
}

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

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 0;
}

.bar-count {
  text-align: right;
  font-weight: 700;
  color: var(--accent);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid var(--border);
}

.plain-list {
  margin: 0;
  padding-left: 1.25rem;
}

.plain-list li {
  margin-bottom: 0.4rem;
}

/* Modals */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(520px, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 12px 40px rgba(28, 36, 32, 0.2);
  color: var(--text);
  background: var(--surface);
}

.modal::backdrop {
  background: rgba(28, 36, 32, 0.55);
}

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

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

.modal-body {
  padding: 1rem;
  max-height: min(60vh, 480px);
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

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

.app-footer p {
  margin: 0;
  max-width: var(--max);
  margin-inline: auto;
  font-size: 0.95rem;
  color: var(--text-muted);
}

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

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
