/* HomeKeeper Pro — senior-friendly, offline-first home maintenance scheduler */

:root {
  --accent: #1a5f7a;
  --accent-hover: #144a60;
  --accent-soft: #e6f2f7;
  --accent-mid: #2a7a9a;
  --danger: #a32020;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #1d6b45;
  --ok-soft: #e6f5ed;
  --pro: #5c3d8a;
  --pro-soft: #f0eaf8;
  --text: #1a2228;
  --text-muted: #4a5560;
  --border: #c5ced6;
  --surface: #ffffff;
  --bg: #f0f4f7;
  --shadow: 0 2px 10px rgba(26, 34, 40, 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.5;
  display: flex;
  flex-direction: column;
}

img {
  max-width: 100%;
}

.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;
  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: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

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

.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.35rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.65rem 1.1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

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

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

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

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

.btn-text {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  min-width: auto;
  padding: 0.5rem 0.75rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
}

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

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

.btn-danger:hover {
  background: #8a1a1a;
}

.btn-danger-outline {
  background: var(--surface);
  color: var(--danger);
  border-color: #e0a0a0;
}

.btn-danger-outline:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

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

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

.btn-sm {
  min-height: var(--touch);
  padding: 0.5rem 0.85rem;
  font-size: 0.95rem;
}

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

.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;
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
}

/* 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 tabs below header on short screens: use scroll container */
.app-header + .tab-nav {
  top: auto;
  position: sticky;
  top: 0;
  z-index: 45;
  background: var(--bg);
}

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

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

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

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

/* 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;
  letter-spacing: -0.02em;
}

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

/* Cards */
.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;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.card-head h3 {
  margin: 0;
}

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

.profile-banner {
  border-left: 4px solid var(--accent);
}

.profile-summary {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

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

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 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 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

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

.stat-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.stat-link {
  margin-top: 0.35rem;
  align-self: flex-start;
  background: none;
  border: none;
  padding: 0.35rem 0;
  min-height: auto;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

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

.stat-link:focus-visible {
  outline: 3px solid var(--accent-mid);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Forms */
.field {
  margin-bottom: 0.85rem;
  flex: 1;
  min-width: 0;
}

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

.checkbox-field label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-weight: 500;
  cursor: pointer;
  min-height: var(--touch);
  align-items: center;
}

.checkbox-field input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
  min-width: 1.35rem;
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

.req {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field input[type="text"],
.field input[type="search"],
.field input[type="number"],
.field input[type="date"],
.field select,
.field textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: auto;
}

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

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26, 95, 122, 0.2);
}

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

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

.settings-inline {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 0.75rem;
}

@media (min-width: 520px) {
  .settings-inline {
    grid-template-columns: 1fr 1fr;
  }
  .settings-inline .field:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

.systems-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem 1rem;
  margin: 0.5rem 0 0.25rem;
}

.systems-fieldset legend {
  font-weight: 700;
  padding: 0 0.35rem;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: var(--touch);
  padding: 0.4rem 0.85rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 999px;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
}

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

.chip input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

.form-error {
  color: var(--danger);
  font-weight: 600;
  margin: 0.5rem 0 0;
}

.status-msg {
  margin: 0.65rem 0 0;
  font-weight: 600;
  color: var(--ok);
  min-height: 1.4em;
}

.status-msg.is-error {
  color: var(--danger);
}

/* Filters */
.filters {
  margin-bottom: 0.85rem;
}

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

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

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

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

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

.detail-list .item-card {
  border-left: 4px solid var(--border);
}

.item-card.who-diy {
  border-left-color: var(--ok);
}

.item-card.who-pro {
  border-left-color: var(--pro);
}

.item-card.who-either {
  border-left-color: var(--accent);
}

.item-card.is-overdue {
  background: #fffaf8;
  border-color: #e8b8b0;
}

.item-card.is-due-soon {
  background: #fffdf5;
  border-color: #e8d09a;
}

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

.item-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
  min-width: 10rem;
}

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

.item-meta strong {
  color: var(--text);
  font-weight: 600;
}

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

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

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

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

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

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

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

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

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

.pill-muted {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

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

.empty-msg.muted {
  background: transparent;
  border-style: solid;
}

/* Schedule */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.month-label {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  flex: 1;
}

/* Tips & bars */
.tip-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.tip-item {
  padding: 0.85rem 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
}

.tip-item strong {
  display: block;
  margin-bottom: 0.25rem;
}

.tip-item p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

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

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

.bar-label {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

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

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(560px, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 12px 40px rgba(26, 34, 40, 0.25);
  color: var(--text);
  background: var(--surface);
}

.modal.modal-sm {
  max-width: min(420px, calc(100vw - 1.5rem));
}

.modal::backdrop {
  background: rgba(20, 30, 40, 0.55);
}

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

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

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

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

.inline-form {
  margin-top: 0.75rem;
  padding: 0.85rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

/* Footer */
.app-footer {
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  border-top: 1px solid var(--border);
}

.app-footer p {
  margin: 0;
}

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

/* Reminder done state */
.item-card.is-done .item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

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