/* GiveWise Charitable Tracker — senior-friendly, offline-first UI */

:root {
  --accent: #2b6b4f;
  --accent-hover: #1f523c;
  --accent-soft: #e8f3ed;
  --accent-mid: #3a8a65;
  --gold: #d4a03c;
  --gold-soft: #faf3e3;
  --danger: #c0392b;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #1a6b4a;
  --ok-soft: #e6f4ed;
  --text: #1a1f28;
  --text-muted: #4a5568;
  --border: #c5cdd9;
  --surface: #ffffff;
  --bg: #fafaf7;
  --shadow: 0 2px 10px rgba(26, 31, 40, 0.08);
  --radius: 12px;
  --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%;
}

/* 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 {
  font-size: 1.75rem;
  line-height: 1;
}

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

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

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

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

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

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

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

/* 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.15rem;
  color: var(--text-muted);
  font-size: 1rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  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.75rem;
}

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

.card-head h3 {
  margin-bottom: 0;
}

.sample-card {
  border-color: var(--accent-mid);
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface) 55%);
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (min-width: 560px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr 1fr 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;
  min-height: 6.5rem;
}

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

.stat-card.stat-primary .stat-label {
  color: rgba(255, 255, 255, 0.9);
}

.stat-card.stat-primary .stat-value {
  color: #fff;
}

.stat-card.stat-primary .stat-link {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stat-card.stat-ok {
  border-color: #8ec9ad;
  background: var(--ok-soft);
}

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

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

.stat-value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

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

.stat-link:hover {
  text-decoration: underline;
}

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

/* Location pills */
.location-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.location-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.location-pill strong {
  color: var(--text);
  font-weight: 700;
}

.loc-icon {
  font-size: 1rem;
}

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

.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(--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;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

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

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

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

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

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

.btn-inline {
  margin-top: 0.25rem;
  min-height: 44px;
}

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

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

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

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

.field-hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

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

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

.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-check {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

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

.field-check label {
  margin: 0;
  font-weight: 500;
  cursor: pointer;
}

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

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

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

.inline-warn {
  margin: 0 0 0.9rem;
  padding: 0.75rem 0.9rem;
  background: var(--warn-soft);
  color: var(--warn);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* Lists / items */
.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.85rem 1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.35rem;
}

.item-card:focus-within,
.item-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

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

.item-amount {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

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

.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.tag-qcd {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: #8ec9ad;
}

.tag-method {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #a8d4bc;
}

.tag-receipt-pending {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: #e0c98a;
}

.tag-receipt-received {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: #8ec9ad;
}

.tag-sample {
  background: var(--gold-soft);
  color: var(--warn);
  border-color: var(--gold);
}

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

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

/* YTD banner */
.ytd-banner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.ytd-total {
  margin: 0.15rem 0 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.method-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.method-chip {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #a8d4bc;
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Year nav */
.year-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.year-display {
  text-align: center;
  flex: 1;
}

.year-value {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.year-nav .btn {
  min-width: var(--touch);
  font-size: 1.5rem;
  padding: 0.4rem 0.75rem;
}

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

.bar-row {
  display: grid;
  gap: 0.25rem;
}

.bar-label-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.bar-track {
  height: 12px;
  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;
  transition: width 0.25s ease;
}

.bar-fill.qcd {
  background: var(--ok);
}

.bar-fill.stock {
  background: var(--gold);
}

/* Empty / status */
.empty-msg {
  margin: 0.5rem 0 0;
  padding: 1.1rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  line-height: 1.55;
}

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

.tip-body {
  margin: 0 0 0.65rem;
  color: var(--text);
}

.fine-print {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

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

.about-list li {
  margin-bottom: 0.45rem;
}

/* Detail blocks */
.detail-dl {
  margin: 0;
  display: grid;
  gap: 0.65rem;
}

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

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

.summary-block {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
}

.summary-block:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.summary-block h3 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.summary-lines {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}

.summary-lines li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--bg);
  font-size: 0.95rem;
}

.summary-grand {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

/* Modal / dialog */
.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(26, 31, 40, 0.22);
  color: var(--text);
}

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

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

.modal::backdrop {
  background: rgba(26, 31, 40, 0.55);
}

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

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

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

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

/* Toast */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(var(--max), calc(100vw - 2rem));
  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;
}

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

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

/* Print */
@media print {
  .app-header,
  .tab-nav,
  .app-footer,
  .header-actions,
  .btn,
  .filters,
  .skip-link,
  .sample-card,
  #panel-tools,
  #panel-home,
  #panel-giving,
  #panel-charities {
    display: none !important;
  }

  #panel-summary.panel {
    display: block !important;
  }

  body {
    background: #fff;
  }

  .card,
  .stat-card,
  .item-card {
    box-shadow: none;
    break-inside: avoid;
  }

  main {
    max-width: none;
    padding: 0;
  }
}

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