:root {
  --bg: #101418;
  --panel: #1a2027;
  --panel-2: #222a33;
  --text: #e8edf2;
  --muted: #8a96a3;
  --accent: #3da9fc;
  --green: #3ddc84;
  --red: #ef476f;
  --amber: #ffd166;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
main { padding: 14px; max-width: 760px; margin: 0 auto; }
a { color: var(--accent); text-decoration: none; }
h1, h2 { margin: 8px 0; }
h2 { font-size: 1.05rem; }

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
.top nav a { margin-left: 16px; }

.card {
  background: var(--panel); border-radius: 14px; padding: 16px; margin: 12px 0;
  display: flex; flex-direction: column; gap: 10px;
}
.login-card { margin-top: 18vh; text-align: center; }

.input, select.input {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #2e3942;
  background: var(--panel-2); color: var(--text); font-size: 1rem;
}
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 12px; border: none; cursor: pointer;
  font-size: 1rem; font-weight: 600; background: var(--panel-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: #07202f; }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn.ghost { background: transparent; border: 1px solid #2e3942; color: var(--text); }
.btn.wide { width: 100%; }

.scan-zone { display: flex; flex-direction: column; gap: 12px; padding: 18px 0 6px; }
.scan-btn {
  flex-direction: column; font-size: 2.6rem; padding: 34px;
  background: linear-gradient(160deg, #1c4e74, #173a56);
  border: 1px solid #2c6f9e; border-radius: 20px;
}
.scan-btn span { font-size: 1.05rem; }

.row-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 18px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
  background: var(--panel); border-radius: 12px; overflow: hidden; color: var(--text);
  display: flex; flex-direction: column;
}
.tile img { width: 100%; aspect-ratio: 1; object-fit: cover; background: #000; }
.tile-meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; font-size: .85rem; }
.tile-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cat { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.cat-receipt { color: var(--green); }
.cat-business-card { color: var(--amber); }
.cat-document { color: var(--accent); }
.cat-other { color: var(--muted); }

.filter-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.chip {
  padding: 8px 14px; border-radius: 999px; background: var(--panel); color: var(--text);
  white-space: nowrap; font-size: .9rem; border: 1px solid #2e3942;
}
.chip.active { background: var(--accent); color: #07202f; border-color: var(--accent); }

.item-view { display: flex; flex-direction: column; gap: 4px; }
.scan-img { width: 100%; border-radius: 14px; background: #000; }
.contact-box { background: var(--panel-2); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px; font-size: .95rem; }
.meta-card { gap: 4px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 24px; }
.actions form { display: contents; }

.muted { color: var(--muted); }
.small { font-size: .78rem; word-break: break-all; }

.flash { margin: 10px 14px 0; padding: 10px 14px; border-radius: 10px; font-size: .92rem; }
.flash.success { background: #15351f; color: var(--green); }
.flash.error { background: #3a1622; color: var(--red); }
.flash.warn { background: #38301a; color: var(--amber); }

.spinner-overlay {
  position: fixed; inset: 0; background: rgba(8, 12, 16, .88); z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 5px solid #2e3942; border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
