/* CollectorVault — senior-friendly, offline-first catalog UI */

:root {
  --accent: #1b365d;
  --accent-hover: #142844;
  --accent-soft: #e8eef6;
  --accent-mid: #2a4a75;
  --gold: #c5963a;
  --gold-soft: #f8f0de;
  --danger: #a32020;
  --danger-hover: #8a1a1a;
  --danger-soft: #fdecec;
  --ok: #5b7f5e;
  --ok-soft: #e8f0e9;
  --text: #1a1f28;
  --text-muted: #4a5568;
  --border: #c8d0dc;
  --surface: #ffffff;
  --bg: #f8f6f3;
  --shadow: 0 2px 12px rgba(27, 54, 93, 0.1);
  --radius: 12px;
  --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.5;
  display: flex;
  flex-direction: column;
}

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

/* 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: 2.5rem;
  height: 2.5rem;
  background: var(--accent);
  color: var(--gold);
  font-size: 1.1rem;
  border-radius: 10px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  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;
}

/* Tabs */
.tab-nav {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.5rem 0.75rem 0;
  display: flex;
  gap: 0.35rem;
  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.5rem;
  padding: 0.6rem 0.85rem;
  border: 2px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}

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

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

.tab.active,
.tab[aria-selected="true"] {
  color: var(--accent);
  background: var(--surface);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  margin-bottom: -2px;
  padding-bottom: calc(0.6rem + 2px);
}

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

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-title {
  margin: 0 0 0.35rem;
  font-size: 1.4rem;
  color: var(--accent);
  font-weight: 700;
}

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

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 0.65rem;
  font-size: 1.15rem;
  color: var(--accent);
}

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

.card-head h3 {
  margin: 0;
}

.sample-card {
  border-style: dashed;
  border-width: 2px;
  border-color: var(--accent-mid);
  background: var(--accent-soft);
}

/* 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.15rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

.btn:disabled {
  opacity: 0.5;
  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;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

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

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

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  min-width: var(--touch);
  padding: 0.4rem;
  font-size: 1.25rem;
  line-height: 1;
}

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

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

.btn-row.stacked {
  flex-direction: column;
  align-items: stretch;
}

.btn-row.stacked .btn {
  width: 100%;
}

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

.field:last-child {
  margin-bottom: 0;
}

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

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

.field input[type="text"],
.field input[type="search"],
.field input[type="number"],
.field input[type="date"],
.field input[type="file"],
.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;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
}

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

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

.field-error {
  margin: 0.35rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}

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

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

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

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

.filters .field {
  margin-bottom: 0;
}

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

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

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

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

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

.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.25rem 0 0;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.15;
  word-break: break-word;
}

.stat-value.gold,
.gold {
  color: var(--gold);
}

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

/* Item list */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.item-card {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  width: 100%;
  padding: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  min-height: var(--touch);
}

button.item-card {
  appearance: none;
}

.item-card:hover {
  border-color: var(--accent-mid);
  background: #fbfcfe;
}

.item-card:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.item-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.item-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
}

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

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

.item-meta {
  margin: 0.3rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  line-height: 1.3;
}

.item-value {
  margin: 0.35rem 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gold);
}

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

.item-list.compact .item-card {
  box-shadow: none;
}

/* Category breakdown */
.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 1rem;
  align-items: center;
  padding: 0.75rem 0.85rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.breakdown-name {
  margin: 0;
  font-weight: 700;
  color: var(--text);
}

.breakdown-count {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.breakdown-value {
  margin: 0;
  font-weight: 700;
  color: var(--gold);
  font-size: 1.05rem;
  text-align: right;
}

.breakdown-bar-wrap {
  grid-column: 1 / -1;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

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

/* Empty states */
.empty-state {
  text-align: center;
  padding: 2rem 1.25rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.1rem;
}

.empty-icon {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  opacity: 0.7;
}

.empty-state h3 {
  margin: 0 0 0.4rem;
  font-size: 1.25rem;
  color: var(--accent);
}

.empty-state p {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

.empty-msg {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Photo */
.photo-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.photo-row input[type="file"] {
  flex: 1;
  min-width: 0;
}

.photo-preview {
  margin-top: 0.65rem;
  max-width: 200px;
}

.photo-preview img {
  width: 100%;
  border-radius: 12px;
  border: 2px solid var(--border);
  object-fit: cover;
  max-height: 200px;
}

/* Detail view */
.detail-photo {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  background: var(--accent-soft);
}

.detail-photo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
  background: var(--accent-soft);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  color: var(--accent);
  font-size: 2rem;
  font-weight: 700;
}

.detail-dl {
  margin: 0;
}

.detail-dl > div {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.detail-dl > div:last-child {
  border-bottom: none;
}

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

.detail-dl dd {
  margin: 0.2rem 0 0;
  font-size: 1rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-value {
  font-size: 1.35rem !important;
  font-weight: 700;
  color: var(--gold) !important;
}

/* About */
.about-list {
  margin: 0;
}

.about-list > div {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.about-list > div:last-child {
  border-bottom: none;
}

.about-list dt {
  margin: 0;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
}

.about-list dd {
  margin: 0.2rem 0 0;
  color: var(--text);
}

/* Modals */
.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(96vw, 560px);
  max-height: min(92vh, 900px);
  box-shadow: 0 16px 48px rgba(27, 54, 93, 0.25);
  background: var(--surface);
  color: var(--text);
}

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

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

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--accent);
}

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

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  padding: 0.9rem 1.15rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  bottom: 0;
}

/* Report content */
.report-body {
  background: #fff;
}

.report-cover {
  text-align: center;
  padding: 1.5rem 1rem 1.25rem;
  border-bottom: 3px solid var(--accent);
  margin-bottom: 1.25rem;
}

.report-cover h3 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--accent);
}

.report-cover p {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
}

.report-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  margin-top: 0.85rem;
  font-weight: 700;
}

.report-totals span {
  color: var(--gold);
  font-size: 1.15rem;
}

.report-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  page-break-inside: avoid;
}

.report-item h4 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  color: var(--accent);
}

.report-item-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 0.85rem;
}

@media (max-width: 420px) {
  .report-item-grid {
    grid-template-columns: 1fr;
  }
}

.report-item img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.report-fields {
  margin: 0;
  font-size: 0.95rem;
}

.report-fields dt {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.4rem;
}

.report-fields dd {
  margin: 0.1rem 0 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(92vw, 420px);
  padding: 0.9rem 1.25rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(27, 54, 93, 0.3);
  text-align: center;
}

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

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

/* Print */
@media print {
  body * {
    visibility: hidden;
  }

  #report-dialog,
  #report-dialog * {
    visibility: visible;
  }

  #report-dialog {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: none;
    max-height: none;
    border: none;
    box-shadow: none;
    display: block !important;
  }

  .no-print,
  .modal-header.no-print,
  .modal-footer.no-print {
    display: none !important;
  }

  .modal-body {
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  .report-item {
    break-inside: avoid;
  }
}

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