/* Appliance Sage — senior-friendly, offline-first, single accent */

:root {
  --accent: #1a5f4a;
  --accent-hover: #144a3a;
  --accent-soft: #e6f2ee;
  --accent-mid: #2d8a6e;
  --danger: #a33b2c;
  --danger-hover: #8a3125;
  --danger-soft: #fce8e8;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --ok: #1a5f4a;
  --ok-soft: #e6f2ee;

  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #ebe7e0;
  --text: #1c1b19;
  --text-muted: #5c5852;
  --border: #d4cfc6;
  --shadow: 0 2px 8px rgba(28, 27, 25, 0.08);
  --shadow-lg: 0 12px 40px rgba(28, 27, 25, 0.16);

  --radius: 12px;
  --radius-sm: 8px;
  --space: 16px;
  --space-lg: 24px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-base: 18px;
  --text-sm: 16px;
  --text-lg: 22px;
  --text-xl: 28px;
  --touch: 48px;
  --header-h: 72px;
  --tab-h: 64px;
  --footer-h: 52px;
  --max-w: 720px;
}

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

html {
  font-size: var(--text-base);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--footer-h) + var(--tab-h) + 16px);
}

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

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 12px var(--space);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  min-height: var(--header-h);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  flex-shrink: 0;
}
.brand-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}
.brand-tagline {
  margin: 2px 0 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.3;
}

/* Tab nav — bottom on mobile, sticky */
.tab-nav {
  position: fixed;
  bottom: var(--footer-h);
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(28, 27, 25, 0.06);
  max-width: var(--max-w);
  margin: 0 auto;
  height: var(--tab-h);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--touch);
  min-width: 0;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-top: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tab-btn:hover,
.tab-btn:focus-visible {
  color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.tab-btn.is-active {
  color: var(--accent);
  border-top-color: var(--accent);
  background: var(--accent-soft);
}
.tab-icon {
  font-size: 20px;
  line-height: 1;
}

/* Main */
.main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: var(--space-lg) var(--space);
  outline: none;
}
.view[hidden] {
  display: none !important;
}
.view-title {
  margin: 0 0 var(--space);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: var(--space);
}
.view-header .view-title {
  margin-bottom: 0;
}
.lead {
  margin: -8px 0 var(--space-lg);
  color: var(--text-muted);
  font-size: var(--text-base);
}
.back-btn {
  margin-bottom: var(--space);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-lg);
  margin-bottom: var(--space);
  box-shadow: var(--shadow);
}
.card-flat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space);
  margin-bottom: var(--space);
}
.card-title {
  margin: 0 0 12px;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
}
.card-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-header-row .card-title {
  margin: 0;
}
.subhead {
  margin: 0 0 6px;
  font-size: var(--text-base);
  font-weight: 700;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.muted {
  color: var(--text-muted);
  margin: 0;
}
.hint {
  margin: 6px 0 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.big-number {
  margin: 0 0 8px;
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: var(--space);
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-height: 88px;
}
.stat-card .stat-value {
  display: block;
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.stat-card .stat-label {
  display: block;
  margin-top: 4px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-weight: 600;
}
.stat-card.is-warn .stat-value {
  color: var(--warn);
}
.stat-card.is-danger .stat-value {
  color: var(--danger);
}

/* Progress */
.progress-track {
  height: 12px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 8px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
  min-width: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}
.btn:active {
  transform: scale(0.98);
}
.btn:focus-visible {
  outline: 3px solid var(--accent-mid);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--accent);
  color: #ffffff;
  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(--accent);
}
.btn-secondary:hover {
  background: var(--accent-soft);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--surface-2);
}
.btn-danger {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}
.btn-icon {
  padding: 0;
  width: var(--touch);
  height: var(--touch);
  font-size: 24px;
  line-height: 1;
}
.btn-sm {
  min-height: 44px;
  padding: 8px 14px;
  font-size: var(--text-sm);
}
.btn-block {
  width: 100%;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

/* Forms */
.field {
  margin-bottom: 16px;
  flex: 1;
  min-width: 0;
}
.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--text);
}
.req {
  font-weight: 600;
  color: var(--danger);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 12px 14px;
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%235c5852' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}
.field textarea {
  min-height: 96px;
  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 var(--accent-soft);
}
.field input:user-invalid,
.field select:user-invalid {
  border-color: var(--danger);
}
.field-error {
  margin: 6px 0 0;
  color: var(--danger);
  font-size: var(--text-sm);
  font-weight: 600;
}
.filters .field {
  margin-bottom: 12px;
}
.filters .field:last-child {
  margin-bottom: 0;
}

/* Appliance list */
.result-count {
  margin: 0 0 10px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
}
.appliance-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.appliance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.appliance-card:hover,
.appliance-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}
.appliance-card-inner {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.appliance-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.appliance-name {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.25;
}
.appliance-meta {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
}
.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge-danger {
  background: #fce8e8;
  color: var(--danger);
}
.badge-neutral {
  background: var(--accent-soft);
  color: var(--accent);
}

/* List rows (attention, plan, reminders) */
.list-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  min-height: var(--touch);
  transition: border-color 0.15s, background 0.15s;
}
.list-item:hover,
.list-item:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.list-item.is-static {
  cursor: default;
}
.list-item.is-static:hover {
  border-color: var(--border);
  background: var(--bg);
}
.list-item-body {
  flex: 1;
  min-width: 0;
}
.list-item-title {
  margin: 0;
  font-weight: 700;
  font-size: var(--text-base);
}
.list-item-sub {
  margin: 2px 0 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.list-item-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--accent-soft);
}
.list-item-icon.warn {
  background: var(--warn-soft);
}
.list-item-icon.danger {
  background: #fce8e8;
}
.list-item-action {
  flex-shrink: 0;
}
.year-group {
  margin-bottom: 4px;
}
.year-label {
  margin: 8px 0 6px;
  font-size: var(--text-sm);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

/* Empty */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}
.empty-title {
  margin: 0 0 8px;
  font-size: var(--text-lg);
  font-weight: 700;
}
.empty-inline {
  padding: 8px 0;
}

/* Detail */
.detail-hero {
  margin-bottom: var(--space);
}
.detail-name {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child {
  border-bottom: none;
}
.detail-label {
  font-weight: 700;
  color: var(--text-muted);
  font-size: var(--text-sm);
  flex-shrink: 0;
}
.detail-value {
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: var(--space);
}

/* Room bar */
.room-row {
  display: grid;
  grid-template-columns: 100px 1fr 36px;
  align-items: center;
  gap: 10px;
  font-size: var(--text-sm);
}
.room-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-bar-track {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.room-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.room-count {
  font-weight: 700;
  text-align: right;
  color: var(--text-muted);
}

/* Modal */
.modal[hidden] {
  display: none !important;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 27, 25, 0.45);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--max-w);
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.modal-panel-sm {
  max-height: 85vh;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px var(--space);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
.modal-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
}
.modal-body {
  padding: var(--space) var(--space) calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 8px;
}

@keyframes slideUp {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-h) + var(--tab-h) + 16px);
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(480px, calc(100% - 32px));
  padding: 14px 20px;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.toast[hidden] {
  display: none !important;
}

/* Footer */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0 var(--space);
}
.app-footer p {
  margin: 0;
  font-size: 15px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.3;
}

/* Checkbox for reminders */
.reminder-check {
  width: 28px;
  height: 28px;
  min-width: 28px;
  margin-top: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Wider screens */
@media (min-width: 640px) {
  body {
    padding-bottom: calc(var(--footer-h) + 24px);
  }
  .tab-nav {
    position: sticky;
    top: var(--header-h);
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
  }
  .tab-btn {
    flex-direction: row;
    gap: 8px;
    font-size: var(--text-sm);
    border-top: none;
    border-bottom: 3px solid transparent;
  }
  .tab-btn.is-active {
    border-top-color: transparent;
    border-bottom-color: var(--accent);
  }
  .main {
    padding-top: var(--space-lg);
  }
  .modal {
    align-items: center;
    padding: 24px;
  }
  .modal-panel {
    border-radius: var(--radius);
    max-height: 90vh;
  }
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .detail-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
  }
  .room-row {
    grid-template-columns: 140px 1fr 40px;
  }
  .toast {
    bottom: calc(var(--footer-h) + 24px);
  }
}

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

/* Print */
@media print {
  .tab-nav,
  .app-footer,
  .btn,
  .skip-link {
    display: none !important;
  }
  body {
    padding: 0;
    background: #fff;
  }
}
