/* Downsize Advisor — senior-friendly, offline-first */

:root {
  --accent: #0F766E;
  --accent-hover: #0D5F59;
  --accent-soft: #CCFBF1;
  --accent-ink: #134E4A;
  --bg: #F3F6F5;
  --surface: #FFFFFF;
  --surface-2: #E8EEEC;
  --text: #0F172A;
  --text-muted: #475569;
  --border: #C5D0CC;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --info: #1E3A8A;
  --info-soft: #DBEAFE;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --space: 1rem;
  --touch: 48px;
  --max: 920px;
}

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

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 {
  position: absolute;
  left: 0.5rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
}

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

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

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.25;
  color: var(--accent-ink);
}

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

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-bottom: 0.65rem;
}

.nav-btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.55rem 0.9rem;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

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

.nav-btn.is-active {
  background: var(--accent);
  color: #fff;
}

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

.nav-btn.is-active .badge {
  background: #fff;
  color: var(--accent);
}

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

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

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

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

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

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

.stat-card .stat-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-card .stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-ink);
  line-height: 1.2;
  word-break: break-word;
}

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

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

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

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

.panel-danger {
  border-color: #FECACA;
  background: #FFFBFB;
}

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

.panel h3 {
  margin: 0 0 0.65rem;
  font-size: 1.1rem;
  color: var(--text);
}

.panel-head h3 {
  margin: 0;
}

.panel-note {
  margin: -0.25rem 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

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

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

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

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

.btn-danger:hover {
  background: #991B1B;
  border-color: #991B1B;
}

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

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.25rem;
}

.file-btn {
  position: relative;
  cursor: pointer;
}

.icon-btn {
  min-width: var(--touch);
  min-height: var(--touch);
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

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

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: flex-end;
}

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

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

.field label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

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

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

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.check-field {
  margin-top: 0.25rem;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: var(--touch);
  font-weight: 600;
  cursor: pointer;
}

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

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

fieldset.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem 0.25rem;
  margin: 0 0 1rem;
  background: var(--bg);
}

fieldset.form-section legend {
  font-weight: 700;
  color: var(--accent-ink);
  padding: 0 0.4rem;
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

.card.is-sample {
  border-left: 4px solid var(--accent);
}

.card.is-done {
  opacity: 0.78;
}

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

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

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

.card-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.metric {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
}

.metric-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-value {
  display: block;
  font-weight: 700;
  color: var(--accent-ink);
  font-size: 1rem;
}

.metric-value.positive {
  color: var(--success);
}

.metric-value.negative {
  color: var(--danger);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}

.status-pill.draft { background: var(--surface-2); color: var(--text-muted); }
.status-pill.considering { background: var(--info-soft); color: var(--info); }
.status-pill.favorite { background: var(--warn-soft); color: var(--warn); }
.status-pill.decided { background: var(--success-soft); color: var(--success); }
.status-pill.passed { background: var(--danger-soft); color: var(--danger); }
.status-pill.sample { background: var(--accent-soft); color: var(--accent-ink); }

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

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

/* Breakdown & bars */
.breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.breakdown-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem 1rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.breakdown-row.is-total {
  background: var(--accent-soft);
  font-weight: 700;
  color: var(--accent-ink);
}

.breakdown-row.is-sub {
  background: transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}

.breakdown-label {
  color: var(--text);
}

.breakdown-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.breakdown-value.positive { color: var(--success); }
.breakdown-value.negative { color: var(--danger); }

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

.bar-row {
  display: grid;
  grid-template-columns: minmax(100px, 34%) 1fr auto;
  gap: 0.55rem;
  align-items: center;
}

.bar-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  word-break: break-word;
}

.bar-track {
  height: 1.1rem;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

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

.bar-fill.is-alt {
  background: var(--accent-ink);
}

.bar-fill.is-warn {
  background: var(--warn);
}

.bar-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: var(--accent-ink);
  white-space: nowrap;
}

.insight-callout {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 1rem;
  color: var(--accent-ink);
}

.insight-callout strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

/* Tips */
.tip-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.tip-list li {
  background: var(--bg);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.75rem 0.9rem;
  color: var(--text);
}

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

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

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

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

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

.modal.modal-wide {
  width: min(96vw, 720px);
}

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

.modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

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

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

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

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  padding: 0.85rem 1.25rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.detail-grid {
  display: grid;
  gap: 0.65rem;
}

.detail-row {
  display: grid;
  grid-template-columns: minmax(120px, 40%) 1fr;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.detail-row dt {
  margin: 0;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-row dd {
  margin: 0;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

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

@media (max-width: 480px) {
  .bar-row {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .bar-value {
    justify-self: start;
  }

  .detail-row {
    grid-template-columns: 1fr;
  }
}
