/* Vigyan Scanner (web): navy and gold like the group website; phone first. */
:root {
  --navy: #102544; --navy-2: #1a3760; --navy-3: #0a1830;
  --gold: #d6ad60; --gold-2: #e4c486; --gold-ink: #8a6a24; --gold-soft: #f6eedb;
  --ink: #18202b; --ink-2: #4c5766; --muted: #7a8593; --line: #e2e6ec;
  --bg: #f7f8fa; --card: #fff; --good: #1f8a4c; --bad: #c0392b; --focus: #2a78d6;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 37, 68, .06), 0 6px 18px rgba(16, 37, 68, .08);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-font-smoothing: antialiased; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0; line-height: 1.2; color: var(--navy); }
h1 { font-size: 22px; font-weight: 800; } h2 { font-size: 18px; font-weight: 800; } h3 { font-size: 15px; font-weight: 700; }
p { margin: 0; }
a { color: var(--navy); }
img, canvas { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* Top bar */
.bar { position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 16px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; text-decoration: none; }
.brand b { display: block; font-size: 16px; font-weight: 800; }
.brand small { display: block; font-size: 11.5px; color: var(--gold); }
.tabs { margin-left: auto; display: none; gap: 4px; }
.tabs a { color: #d5deea; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.tabs a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.tabs a.on { background: var(--gold); color: var(--navy); }
.bottom-tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: #fff; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, 1fr); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(16, 37, 68, .06); }
.bottom-tabs a { display: grid; justify-items: center; gap: 1px; padding: 8px 4px 9px; font-size: 11.5px; font-weight: 600; color: var(--muted); text-decoration: none; }
.bottom-tabs a span { font-size: 20px; line-height: 1.1; }
.bottom-tabs a.on { color: var(--navy); }
.bottom-tabs a.on span { filter: none; transform: scale(1.08); }
@media (min-width: 860px) {
  .tabs { display: flex; }
  .bottom-tabs { display: none; }
  body { padding-bottom: 0; }
}

/* Layout */
.view { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.head-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.head-row h1 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.back { text-decoration: none; font-weight: 700; color: var(--navy); font-size: 14px; }
.note { font-size: 13px; color: var(--ink-2); background: var(--gold-soft); border-radius: 10px; padding: 10px 12px; }
.warn { font-size: 13px; color: var(--bad); background: #fbe6e3; border-radius: 10px; padding: 10px 12px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; cursor: pointer; text-decoration: none; font: inherit; font-weight: 700; font-size: 14px;
  padding: 10px 14px; border-radius: 10px; background: var(--navy); color: #fff; min-height: 42px; transition: background .15s, transform .1s; -webkit-tap-highlight-color: transparent; }
.btn:hover { background: var(--navy-2); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.gold:hover { background: var(--gold-2); }
.btn.light { background: #fff; color: var(--navy); box-shadow: inset 0 0 0 1px var(--line); }
.btn.light:hover { background: #f1f4f7; }
.btn.danger { background: #fff; color: var(--bad); box-shadow: inset 0 0 0 1px #f0c9c3; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.big { min-height: 54px; font-size: 16px; padding: 12px 18px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 99px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); cursor: pointer; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Forms */
label.f { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input[type=text], input[type=number], input[type=search], input[type=password], select, textarea {
  width: 100%; font: inherit; font-size: 15px; padding: 9px 11px; border: 1px solid #cfd6de; border-radius: 9px; background: #fff; color: var(--ink); min-height: 42px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
input[type=range] { width: 100%; accent-color: var(--navy); }
label.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; color: var(--ink-2); }

/* Home */
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-actions .btn { flex-direction: column; min-height: 86px; font-size: 15px; }
.hero-actions .btn span { font-size: 26px; }
.scans { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.scan-tile { background: #fff; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; border: 2px solid transparent; position: relative; }
.scan-tile:hover { border-color: var(--gold); }
.scan-tile .thumb { aspect-ratio: 3 / 4; background: #eef1f5 center / contain no-repeat; }
.scan-tile .meta { padding: 8px 10px; }
.scan-tile b { display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-tile small { color: var(--muted); font-size: 12px; }
.scan-tile .count { position: absolute; top: 8px; right: 8px; background: rgba(16, 37, 68, .85); color: #fff; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty .big { font-size: 46px; }

/* Scan editor */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.page { background: #fff; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; border: 2px solid transparent; cursor: pointer; padding: 0; font: inherit; text-align: left; position: relative; }
.page:hover { border-color: var(--gold); }
.page .thumb { aspect-ratio: 3 / 4; background: #eef1f5 center / contain no-repeat; }
.page .n { position: absolute; left: 8px; top: 8px; background: var(--navy); color: var(--gold); font-weight: 800; font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.page-tools { display: flex; justify-content: space-between; padding: 4px; border-top: 1px solid var(--line); }
.page-tools button { border: 0; background: none; font-size: 16px; padding: 6px 8px; cursor: pointer; border-radius: 6px; }
.page-tools button:hover { background: #f1f4f7; }
.add-page { border: 2px dashed #c6cfda; background: #fbfcfd; border-radius: 12px; display: grid; place-items: center; gap: 4px; padding: 16px; color: var(--ink-2); font-weight: 700; cursor: pointer; min-height: 160px; font: inherit; }
.add-page span { font-size: 28px; }

/* Page editor (crop & filters) */
.editor { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.stage { position: relative; background: #1b2433; border-radius: var(--radius); overflow: hidden; touch-action: none; user-select: none; display: grid; place-items: center; min-height: 300px; }
.stage canvas { max-height: 70vh; width: auto; }
.handles { position: absolute; inset: 0; pointer-events: none; }
.handles svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.handle { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: rgba(214, 173, 96, .35); border: 3px solid var(--gold); pointer-events: auto; cursor: grab; touch-action: none; }
.handle:active { cursor: grabbing; background: rgba(214, 173, 96, .6); }
.filters { display: grid; gap: 8px; }
.filter { display: grid; grid-template-columns: 54px 1fr; gap: 10px; align-items: center; text-align: left; font: inherit; background: #fff; border: 1.5px solid var(--line); border-radius: 10px; padding: 6px; cursor: pointer; }
.filter.on { border-color: var(--navy); background: #f2f5f9; }
.filter img, .filter canvas { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; background: #eef1f5; }
.filter b { display: block; font-size: 13.5px; } .filter small { color: var(--muted); font-size: 12px; }

/* Tools */
.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tool { display: flex; gap: 12px; align-items: flex-start; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; text-decoration: none; color: inherit; border: 1.5px solid transparent; transition: transform .15s, border-color .15s; }
.tool:hover { border-color: var(--gold); transform: translateY(-2px); }
.tool .ic { width: 46px; height: 46px; border-radius: 12px; background: var(--gold-soft); display: grid; place-items: center; font-size: 24px; flex: none; }
.tool p { color: var(--ink-2); font-size: 13.5px; margin-top: 3px; }
.preview { background: repeating-conic-gradient(#eef1f5 0% 25%, #fff 0% 50%) 50% / 18px 18px; border-radius: 12px; display: grid; place-items: center; padding: 12px; min-height: 180px; }
.preview canvas, .preview img { max-height: 380px; width: auto; box-shadow: 0 2px 10px rgba(0, 0, 0, .15); }
.frame-stage { position: relative; display: inline-block; touch-action: none; user-select: none; overflow: hidden; border-radius: 10px; }
.frame-stage canvas { max-height: 60vh; width: auto; }
.frame { position: absolute; border: 2px solid var(--gold); box-shadow: 0 0 0 9999px rgba(10, 24, 48, .55); cursor: move; touch-action: none; }
.frame .grip { position: absolute; right: -14px; bottom: -14px; width: 28px; height: 28px; border-radius: 50%; background: var(--gold); border: 3px solid #fff; cursor: nwse-resize; }
.result-line { font-size: 13.5px; color: var(--ink-2); }
.result-line b { color: var(--good); }

/* Smart Fill */
.forms-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.forms-table th, .forms-table td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
.forms-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-2); background: #fafbfc; }
.table-wrap { overflow-x: auto; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields .wide { grid-column: 1 / -1; }
.scanner-video { width: 100%; max-height: 60vh; background: #000; border-radius: 12px; object-fit: cover; }
textarea.ocr { min-height: 260px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13.5px; }

/* Busy and toast */
.busy { position: fixed; inset: 0; z-index: 50; background: rgba(10, 24, 48, .45); display: grid; place-items: center; }
.busy-box { background: #fff; border-radius: 14px; padding: 18px 22px; display: flex; gap: 12px; align-items: center; font-weight: 600; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); max-width: 86vw; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #dfe5ec; border-top-color: var(--navy); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); max-width: 90vw; }
@media (min-width: 860px) { .toast { bottom: 24px; } }

@media (max-width: 760px) {
  .editor { grid-template-columns: 1fr; }
  .stage canvas { max-height: 56vh; }
  .grid2, .fields { grid-template-columns: 1fr; }
  .view { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { .btn, .tool { transition: none; } .spin { animation-duration: 2s; } }

/* ID cards on A4 */
.id-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: #fbfcfd; }
.id-side { display: grid; gap: 8px; }
.id-pic { min-height: 150px; border-radius: 10px; overflow: hidden; background: #eef1f5; display: grid; place-items: center; padding: 6px; }
.id-pic canvas { max-width: 100%; max-height: 240px; width: auto; height: auto; border-radius: 6px; }
.id-empty { color: var(--muted); font-weight: 700; }

/* 🏠 Home: back to the group website */
.bar .homes { margin-left: auto; display: flex; gap: 6px; }
@media (min-width: 860px) { .bar .homes { margin-left: 4px; } }
@media (max-width: 520px) { .bar .home span { display: none; } }
.bar .home { color: #fff; text-decoration: none; font-weight: 700; font-size: 14px; padding: 7px 12px; border-radius: 8px; background: rgba(255, 255, 255, .1); white-space: nowrap; }
.bar .home:hover { background: rgba(255, 255, 255, .18); }
@media (max-width: 1040px) { .bar .home + .home span { display: none; } }
