/* styles.css — Bonnetje base styles. Phase 1 shell. */

:root {
  --accent: #1565c0;
  --accent-dark: #0d47a1;
  --bg: #ffffff;
  --bg-muted: #f4f6f8;
  --text: #1a1a1a;
  --text-muted: #5f6368;
  --border: #e0e0e0;
  --danger: #c62828;
  --radius: 12px;
  --nav-height: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
}

/* ---- App shell: sidebar + master + detail ---- */
.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.side-nav {
  display: none; /* desktop only */
}

.master {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.detail {
  flex: 0 0 auto;
  width: 100%;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--bg);
}

/* Mobile (default): master and detail are exclusive — detail overlays master. */
.detail {
  display: none;
}

body.detail-open .master {
  display: none;
}

body.detail-open .detail {
  display: block;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.empty-state,
.error-state {
  color: var(--text-muted);
  line-height: 1.5;
}

.error-state {
  color: var(--danger);
}

/* Bottom navigation */
.bottom-nav {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  min-height: var(--nav-height);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  padding: 4px 0;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.nav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 8px;
}

/* Online status badge */
.online-badge {
  position: fixed;
  top: 8px;
  right: 8px;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-muted);
  pointer-events: none;
}

.online-badge.offline {
  background: var(--danger);
  color: #fff;
}

/* Desktop (>=1024px): master–detail. Sidebar + list column + detail pane. */
@media (min-width: 1024px) {
  .app-shell {
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    gap: 0;
  }

  .side-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 200px;
    flex: 0 0 200px;
    border-right: 1px solid var(--border);
    padding: 16px 12px;
  }

  .side-brand {
    font-weight: 700;
    font-size: 1.1rem;
    padding: 8px 12px 16px;
  }

  .side-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: left;
  }

  .side-btn:hover,
  .side-btn:focus-visible {
    background: var(--bg-muted);
    color: var(--text);
    outline: none;
  }

  .master {
    flex: 0 0 380px;
    max-width: 380px;
    border-right: 1px solid var(--border);
    padding-bottom: 16px;
  }

  .detail {
    flex: 1;
    min-width: 0;
    display: block;
    padding: 24px 32px;
  }

  /* On desktop, master is always visible; detail is always visible. */
  .master {
    display: block !important;
  }
  .detail {
    display: block !important;
  }

  .bottom-nav {
    display: none;
  }
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

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

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

.btn-outline {
  background: var(--bg);
  color: var(--accent);
  border-color: var(--accent);
}

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

.btn-icon {
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 8px;
  background: var(--bg-muted);
  color: var(--text-muted);
  font-size: 1rem;
}

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

/* ---- Search + list header ---- */
.list-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.search-wrap {
  width: 100%;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
}

.search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.list-header .btn-primary {
  align-self: flex-start;
}

/* Filter chips */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

/* ---- Receipt list ---- */
.receipt-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.receipt-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.receipt-card-row {
  display: flex;
  align-items: stretch;
}

.receipt-card-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  background: none;
  border: none;
  padding: 14px 4px 14px 14px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

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

.receipt-card-merchant {
  font-weight: 600;
  font-size: 1rem;
  flex: 1 1 100%;
}

.receipt-card-date,
.receipt-card-count {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.receipt-card-total {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chevron {
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.chevron-open {
  transform: rotate(180deg);
}

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

/* Inline (expanded) items */
.receipt-items {
  list-style: none;
  margin: 0;
  padding: 0 14px 12px;
  border-top: 1px solid var(--border);
}

.receipt-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.receipt-item:last-child {
  border-bottom: none;
}

.receipt-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-item-model {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: ui-monospace, monospace;
}

.receipt-item-total {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ---- Receipt form ---- */
.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.form-header h2 {
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field-full {
  grid-column: 1 / -1;
}

.field input,
.field select,
.field textarea {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
}

.field textarea {
  min-height: auto;
}

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

.items-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 12px 0;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-muted);
  min-width: 0;
}

.item-row .field {
  min-width: 0;
}

.form-footer {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.form-footer .error-state {
  flex: 1 1 100%;
  margin: 0;
}

/* ---- Receipt detail (read-only) ---- */
.detail-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-header {
  margin-bottom: 16px;
}

.detail-header h2 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.detail-city {
  color: var(--text-muted);
  margin-right: 12px;
}

.detail-date {
  color: var(--text-muted);
  margin-right: 12px;
}

.detail-type {
  color: var(--text-muted);
}

.detail-total {
  margin-top: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.detail-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0 0 16px;
  padding: 12px;
  background: var(--bg-muted);
  border-radius: var(--radius);
}

.detail-meta dt {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.detail-meta dd {
  margin: 0;
}

/* Item table (used in the detail view) */
.item-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.item-table th,
.item-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.item-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.82rem;
}

.item-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Per-item rows inside the mobile detail can simply use the table; no extra
   styles needed. */

@media (min-width: 1024px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .item-row {
    grid-template-columns: repeat(6, minmax(0, 1fr)) auto;
    align-items: end;
  }
  .item-row .btn-icon {
    align-self: end;
    margin-bottom: 2px;
  }
  .item-row input,
  .item-row select {
    min-width: 0;
    width: 100%;
  }
}

/* ---- Settings + scan ---- */
.settings-section {
  margin-bottom: 24px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.settings-section h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.settings-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.status-line {
  color: var(--text);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.settings-section .search-input {
  margin-top: 8px;
}

/* ---- Warranty fields (item form) ---- */
.warranty-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  grid-column: 1 / -1;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}

.durable-toggle-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.durable-toggle-field input[type='checkbox'] {
  min-height: auto;
  width: 20px;
  height: 20px;
}

/* ---- Warranty screen ---- */
.warranty-section {
  margin-bottom: 24px;
}

.warranty-section h3 {
  font-size: 1rem;
  margin: 0 0 10px;
  color: var(--text-muted);
  text-transform: none;
}

.warranty-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.warranty-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.warranty-entry-btn {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  background: none;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}

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

.warranty-entry-name {
  font-weight: 600;
  flex: 1 1 100%;
}

.warranty-entry-model {
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}

.warranty-entry-date {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---- Drive list + status ---- */
.drive-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drive-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.drive-entry span {
  flex: 1;
  min-width: 0;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.status-warn {
  color: var(--danger);
}

/* ---- Original document viewer (full-screen overlay) ---- */
.doc-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.9);
  padding: 16px;
}

body.doc-viewer-open {
  overflow: hidden;
}

.doc-viewer-close {
  align-self: flex-end;
  background: #222;
  color: #fff;
  border-color: #444;
  margin-bottom: 8px;
}

.doc-viewer-close:hover {
  background: #333;
}

.doc-viewer-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.doc-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.doc-viewer-frame {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 4px;
  background: #fff;
}