/* Daybright Routines — senior-friendly, offline-first UI */

:root {
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-soft: #fff7ed;
  --accent-mid: #ea580c;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warn: #a16207;
  --warn-soft: #fefce8;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --text: #1c1917;
  --text-muted: #57534e;
  --border: #d6d3d1;
  --surface: #ffffff;
  --bg: #fafaf9;
  --shadow: 0 2px 12px rgba(28, 25, 23, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 720px;
}

*,
*::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;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

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

/* 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);
}

.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 {
  font-size: 1.85rem;
  line-height: 1;
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

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

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

.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(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

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

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

.tab:hover {
  color: var(--text);
  background: var(--surface);
}

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

.tab.is-active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  margin-bottom: -2px;
  box-shadow: 0 2px 0 var(--surface);
}

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

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

.view-header {
  margin-bottom: 1rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  color: var(--text);
}

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

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

.req {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: lowercase;
}

/* 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 1rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.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(--text);
  border-color: var(--border);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: transparent;
}

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

.btn-ghost[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

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

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

.btn-sm {
  min-height: 40px;
  min-width: 40px;
  padding: 0.35rem 0.7rem;
  font-size: 0.95rem;
}

.btn-icon {
  min-width: var(--touch);
  padding-left: 0.65rem;
  padding-right: 0.65rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

/* Panels & cards */
.panel {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.panel-danger {
  border-color: #fecaca;
  background: var(--danger-soft);
}

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

.panel-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

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

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

.routine-meta {
  margin: 0.2rem 0 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.period-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
}

.period-pill.evening {
  background: #eef2ff;
  color: #4338ca;
}

.period-pill.custom {
  background: #f5f5f4;
  color: var(--text-muted);
}

/* Stats */
.stat-row,
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  text-align: center;
}

.stat-card .stat-value {
  display: block;
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.2;
}

.stat-card .stat-label {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-card.is-ok .stat-value {
  color: var(--ok);
}

.stat-card.is-warn .stat-value {
  color: var(--warn);
}

/* Period switch */
.period-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.period-btn {
  min-height: var(--touch);
  padding: 0.65rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
}

.period-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.period-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Progress */
.progress-block {
  margin-bottom: 1rem;
}

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

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

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

/* Task list (Today) */
.task-list,
.simple-list,
.nested-task-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.task-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.task-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.task-item:first-child {
  padding-top: 0;
}

.task-check {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  margin-top: 0.1rem;
  border: 3px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.task-check:hover {
  border-color: var(--accent);
}

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

.task-check[aria-pressed="true"],
.task-check.is-done {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}

.task-visual {
  flex-shrink: 0;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  overflow: hidden;
}

.task-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.task-body {
  flex: 1;
  min-width: 0;
}

.task-body h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.task-item.is-complete .task-body h4 {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-body p {
  margin: 0.2rem 0 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.task-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Nested tasks in routine cards */
.nested-task-list .task-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0;
  border-top: 1px solid var(--border);
}

.nested-task-list .task-row:first-child {
  border-top: none;
  padding-top: 0;
}

.nested-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.nested-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nested-info {
  flex: 1;
  min-width: 8rem;
}

.nested-info strong {
  display: block;
}

.nested-info span {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.nested-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* Lists in reminders / insights */
.simple-list > li {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.simple-list > li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.list-main {
  flex: 1;
  min-width: 10rem;
}

.list-main strong {
  display: block;
  font-size: 1.05rem;
}

.list-main span {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.due-tag {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.85rem;
  font-weight: 700;
}

.due-tag.is-due {
  background: var(--danger-soft);
  color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--text-muted);
}

.empty-state p {
  margin: 0 0 0.85rem;
}

.empty-inline {
  margin: 0;
  padding: 0.25rem 0;
}

.completion-banner {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--ok-soft);
  border: 2px solid #86efac;
  text-align: center;
}

.completion-banner p {
  margin: 0 0 0.75rem;
}

/* Week chart */
.week-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}

.week-day {
  text-align: center;
  padding: 0.5rem 0.25rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg);
}

.week-day .day-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.week-day .day-pct {
  display: block;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.week-day.is-today {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.week-day.is-good {
  background: var(--ok-soft);
  border-color: #86efac;
}

.week-day.is-good .day-pct {
  color: var(--ok);
}

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

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

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

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

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

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

.check-label {
  display: flex !important;
  align-items: flex-start;
  gap: 0.65rem;
  font-weight: 500 !important;
  cursor: pointer;
  min-height: var(--touch);
  padding: 0.4rem 0;
}

.check-label input[type="checkbox"] {
  width: 1.4rem;
  height: 1.4rem;
  min-width: 1.4rem;
  margin-top: 0.15rem;
  accent-color: var(--accent);
  cursor: pointer;
}

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

.photo-preview img {
  width: 5.5rem;
  height: 5.5rem;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid var(--border);
}

/* Dialogs */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(32rem, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 16px 48px rgba(28, 25, 23, 0.22);
  background: transparent;
}

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

.modal-wide {
  max-width: min(28rem, calc(100vw - 1.5rem));
}

.modal-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem 1.2rem;
}

.modal-card h2 {
  margin: 0 0 0.85rem;
  font-size: 1.3rem;
  color: var(--accent);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 1rem;
}

/* Guided mode */
.guided-card {
  text-align: center;
}

.guided-body {
  padding: 0.5rem 0 0.25rem;
}

.guided-visual {
  width: 7rem;
  height: 7rem;
  margin: 0 auto 1rem;
  border-radius: 20px;
  background: var(--accent-soft);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  overflow: hidden;
}

.guided-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.guided-body h3 {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
}

.guided-detail {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.guided-done .celebrate {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ok);
  margin: 1rem 0;
}

.guided-actions {
  justify-content: center;
}

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

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

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

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

/* Utility */
[hidden] {
  display: none !important;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* Larger screens */
@media (min-width: 640px) {
  .brand h1 {
    font-size: 1.4rem;
  }

  .period-switch {
    max-width: 22rem;
  }
}
