:root {
  --bg: #05070a;
  --card: #10151d;
  --card-border: #232c38;
  --text: #e8ecf0;
  --muted: #8a94a0;
  --navy: #0a1c35;
  --accent: #2f7ad9;
  --accent-hover: #1f5fb0;
  --danger: #e05555;
  --ok: #4caf7d;
  --warn: #d9a441;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* .hidden lives inline in index.html's <head> — must apply even if this
   file never loads. Don't redefine it here. */

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* avoid iOS zoom-on-focus */
  background: #0a0d12;
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  width: 100%;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

h1, h2, h3 { color: var(--text); }

.brand-mark {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  margin-bottom: 14px;
}
.brand-mark.small { width: 30px; height: 30px; border-radius: 8px; margin: 0 10px 0 0; }

/* PIN screen */
#pin-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.pin-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.pin-card h1 { font-size: 1.2rem; margin: 0 0 20px; }

#pin-input {
  text-align: center;
  letter-spacing: 8px;
  font-size: 1.4rem;
  margin-bottom: 16px;
}

.primary-btn {
  background: var(--accent);
  color: white;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  width: 100%;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  background: #232c38;
  color: var(--text);
  padding: 12px 18px;
  font-size: 1rem;
  width: 100%;
}

.small-btn { width: auto; padding: 8px 14px; font-size: 0.9rem; }

.link-btn {
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 4px;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 10px;
}
.success-msg { color: var(--ok); font-size: 0.9rem; margin-top: 10px; }

/* App shell */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 5;
}

.header-title { display: flex; align-items: center; }
header h1 { font-size: 1.05rem; margin: 0; line-height: 1.3; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 90px; /* clear the fixed tab bar */
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.panel-header h2 { margin: 0; font-size: 1.1rem; }

.card-list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; margin-bottom: 2px; word-break: break-word; }
.card-meta { color: var(--muted); font-size: 0.85rem; }
.card-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.card-actions.row { flex-direction: row; }

.empty-state { color: var(--muted); text-align: center; padding: 30px 10px; }

.icon-btn {
  background: #232c38;
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}
.icon-btn.danger { color: var(--danger); }
.icon-btn.ok { color: var(--ok); }

/* Tab bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--card-border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab-btn {
  flex: 1;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px 8px;
  font-size: 0.72rem;
  border-radius: 0;
}
.tab-btn.active { color: var(--accent); }
.tab-icon { font-size: 1.25rem; }

.view { display: none; }
.view.active-view { display: block; }

/* Badges */
.status-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 10px;
}
.status-badge.pending { background: #3a3220; color: var(--warn); }
.status-badge.ok { background: #1c3a2a; color: var(--ok); }
.status-badge.off { background: #2a232e; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge.matched { background: #1c3a2a; color: var(--ok); }
.badge.bank-only { background: #3a3220; color: var(--warn); }
.badge.wave-only { background: #23283a; color: #8fa8e0; }
.badge.applied { background: #1c3a2a; color: var(--ok); }
.badge.error { background: #3a2020; color: var(--danger); }

/* Settings */
.settings-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.settings-card h3 { margin: 0 0 10px; font-size: 1rem; }

.radio-row, .checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 10px 0;
  font-size: 0.9rem;
  cursor: pointer;
}
.radio-row input, .checkbox-row input { width: auto; margin-top: 3px; }
.radio-row.compact { margin: 6px 0; font-size: 0.88rem; }

.muted { color: var(--muted); font-size: 0.9rem; margin: 0 0 14px; }
.muted.small { font-size: 0.82rem; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--card-border);
  border-radius: var(--radius);
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 16px;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag-over { border-color: var(--accent); background: rgba(43,108,219,0.08); }
.dropzone-icon { font-size: 2rem; margin-bottom: 6px; }
.dropzone p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.search-row { margin-bottom: 14px; }

/* Receipt card thumbnails */
.receipt-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  background: #0a0d12;
  border: 1px solid var(--card-border);
  flex-shrink: 0;
}
.receipt-thumb-icon {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #0a0d12;
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-content { border-radius: var(--radius); }
}

.modal-content h2 { margin-top: 0; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

#mapping-preview { margin-top: 14px; overflow-x: auto; }
#mapping-preview table { border-collapse: collapse; width: 100%; font-size: 0.8rem; }
#mapping-preview th, #mapping-preview td { border: 1px solid var(--card-border); padding: 6px 8px; text-align: left; white-space: nowrap; }
#mapping-preview th { color: var(--muted); font-weight: 600; }

.recon-section { margin-bottom: 20px; }
.recon-section-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.recon-section-header h3 { margin: 0; font-size: 0.95rem; }

.recon-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.recon-item-check { width: auto; flex-shrink: 0; }

.sticky-apply-bar {
  position: sticky;
  bottom: calc(70px + env(safe-area-inset-bottom));
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 16px;
  z-index: 6;
}

.toast {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 30;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.toast.error { border-color: var(--danger); color: #ffb3b3; }
.toast.success { border-color: var(--ok); color: #b7ffd8; }

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--warn);
  color: #1a1400;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
}

#offline-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
