/* app.css — Mobile-first, με σεβασμό στο light/dark του συστήματος. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #12161f;
  --text-dim: #5b6472;
  --border: #d9dee6;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #c8362f;
  --ok: #1a7f4b;
  --warn: #a86400;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 6px 20px rgba(0, 0, 0, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1219;
    --surface: #171b24;
    --surface-2: #1f2530;
    --text: #e7eaf0;
    --text-dim: #98a2b3;
    --border: #2b3240;
    --accent: #4d8ef7;
    --accent-text: #06111f;
    --danger: #f0665e;
    --ok: #4ec98a;
    --warn: #e0a458;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

/* Το [hidden] του browser είναι απλό `display: none` και το νικάει κάθε
   δικός μας κανόνας με display (π.χ. flex). Το επιβάλλουμε ρητά. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding-bottom: calc(24px + var(--safe-b));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Κεφαλίδα & tabs ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.01em; }

.counter {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 19;
}

.tab {
  flex: 1;
  padding: 12px 4px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 16px; max-width: 760px; margin: 0 auto; }

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

/* ---------- Κάμερα ---------- */

.camera-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 62vh;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .camera-frame { aspect-ratio: 4 / 3; }
}

#video { width: 100%; height: 100%; object-fit: cover; display: block; }

.reticle {
  position: absolute;
  inset: 18% 14%;
  border: 2px solid rgba(255, 255, 255, .85);
  border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .3);
  pointer-events: none;
}

.camera-hint {
  position: absolute;
  left: 0; right: 0; bottom: 12px;
  text-align: center;
  color: #fff;
  font-size: 14px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
  pointer-events: none;
}

/* ---------- Κουμπιά ---------- */

.scan-actions { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; min-width: 120px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 550;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-lg { min-height: 54px; font-size: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-outline { background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.is-on { background: var(--warn); border-color: var(--warn); color: #1a1300; }

.ico { font-size: 18px; line-height: 1; }

.icon-btn {
  border: 0;
  background: none;
  color: var(--text-dim);
  font-size: 26px;
  line-height: 1;
  width: 40px;
  height: 40px;
  cursor: pointer;
}

/* ---------- Κατάσταση / πρόοδος ---------- */

.status {
  margin: 14px 0 0;
  padding: 0;
  font-size: 14px;
  color: var(--text-dim);
  min-height: 20px;
}

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

.progress {
  margin-top: 12px;
  background: var(--surface-2);
  border-radius: 999px;
  height: 24px;
  position: relative;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .25s ease;
}

.progress-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--text);
  mix-blend-mode: difference;
  filter: invert(1) grayscale(1) contrast(9);
}

.hint {
  margin-top: 20px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
}

/* ---------- Λίστα ---------- */

.list-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }

#searchBox {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

.sum { font-size: 14px; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }

.receipt-list { display: flex; flex-direction: column; gap: 8px; }

.receipt {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.receipt-main { min-width: 0; cursor: pointer; }
.receipt-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receipt-sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.receipt-total { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.empty { text-align: center; color: var(--text-dim); padding: 40px 0; font-size: 14px; }

/* ---------- Κάρτες εξαγωγής ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card h2 { margin: 0 0 6px; font-size: 16px; }

.card-danger { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

/* ---------- Φόρμα (bottom sheet) ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 620px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  animation: rise .2s ease;
}

@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; }
}

@keyframes rise { from { transform: translateY(24px); opacity: .6; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 14px 18px;
  border-bottom: 1px solid var(--border);
}

.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { padding: 16px 18px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }

.sheet-foot {
  display: flex;
  gap: 10px;
  padding: 12px 18px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
}

.sheet-foot .btn { flex: 1; white-space: nowrap; }
.sheet-foot .btn-primary { flex: 2; }
.sheet-foot #btnOpenSource { flex: 0 0 auto; text-decoration: none; padding-inline: 12px; }

.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

.badge {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 550;
}

.badge.good { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid .span2 { grid-column: 1 / -1; }

.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 550;
}

.field-grid input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px = δεν κάνει zoom το iOS Safari */
  width: 100%;
}

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

.field-grid .highlight input { font-size: 20px; font-weight: 650; }

.field-note { font-size: 12px; font-weight: 500; min-height: 15px; }
.field-note.err { color: var(--danger); }
.field-note.ok { color: var(--ok); }

.candidates { margin-top: 16px; }
.candidates-label { font-size: 13px; color: var(--text-dim); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.raw-box { margin-top: 16px; font-size: 13px; color: var(--text-dim); }
.raw-box summary { cursor: pointer; padding: 6px 0; }

.raw-box pre {
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--surface-2);
  padding: 10px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.5;
  max-height: 220px;
  overflow: auto;
  margin: 6px 0 0;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 550;
  z-index: 100;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
  text-align: center;
}
