:root {
  color-scheme: dark;
  --bg: #020817;
  --panel: #0d1729;
  --panel-2: #101b30;
  --line: #1d2d48;
  --text: #eef4ff;
  --muted: #8291a8;
  --blue: #2f7bff;
  --green: #35df79;
  --orange: #ff9f43;
  --red: #ff5e72;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.center-view { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: calc(22px + var(--safe-top)) 22px calc(22px + var(--safe-bottom)); }
.center-view > p { color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid #18325c; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-card { width: min(100%, 430px); padding: 24px; border: 1px solid #24497f; border-radius: 22px; background: rgba(13, 23, 43, .97); box-shadow: 0 24px 80px rgba(0, 0, 0, .36); }
.login-card h1 { margin: 0; font-size: 42px; text-align: center; letter-spacing: -.04em; }
.brand-subtitle { margin: 2px 0 28px; color: #64a1ff; font-weight: 900; text-align: center; }
#loginForm { display: grid; gap: 12px; }
input, select, textarea { width: 100%; color: white; border: 1px solid #2d67b8; border-radius: 13px; outline: none; background: rgba(5, 12, 27, .94); }
input, select { min-height: 54px; padding: 0 16px; }
input:focus, select:focus, textarea:focus { border-color: #4f91ff; box-shadow: 0 0 0 3px rgba(47, 123, 255, .18); }
.password-field { position: relative; }
.password-field input { padding-right: 54px; }
.eye-button { position: absolute; inset: 0 5px 0 auto; width: 46px; border: 0; background: transparent; color: #b9cbe8; display: grid; place-items: center; }
.eye-button svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.primary-button, .secondary-button, .danger-button, .small-button, .action-button { cursor: pointer; font-weight: 900; }
.primary-button, .secondary-button, .danger-button { width: 100%; min-height: 50px; border-radius: 13px; padding: 0 14px; }
.primary-button { color: white; border: 1px solid #4c8cff; background: linear-gradient(180deg, #347cf3, #2768e9); }
.secondary-button { color: #dce6f6; border: 1px solid #365a8a; background: #142036; }
.danger-button { color: var(--red); border: 1px solid #c33348; background: #111c31; }
.danger-button.compact { min-height: 48px; }
button:disabled { cursor: wait; opacity: .55; }
.message { min-height: 20px; margin: 12px 0 0; color: var(--red); font-weight: 800; text-align: center; }
.message.info { color: #78adff; }
.login-hint { margin: 9px 0 0; color: #8190a8; font-size: 12px; line-height: 1.45; text-align: center; }

.app-shell { width: min(100%, 760px); margin: 0 auto; padding: calc(10px + var(--safe-top)) 14px calc(28px + var(--safe-bottom)); display: grid; gap: 12px; }
.app-header { min-height: 58px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.brand-small { font-size: 30px; letter-spacing: -.04em; text-align: center; }
.header-actions { justify-self: end; display: flex; gap: 9px; align-items: center; }
.connection { color: var(--green); font-size: 11px; font-weight: 900; white-space: nowrap; }
.connection.offline { color: var(--orange); }
.small-button { min-height: 38px; padding: 0 15px; border: 1px solid var(--line); border-radius: 10px; color: #d7e0ee; background: #111b2f; }
.install-banner, .warning { border-radius: 14px; padding: 13px 14px; }
.install-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid #315e9c; background: #10213b; color: #dce9ff; }
.install-banner div { display: grid; gap: 3px; }
.install-banner span { color: #aebed8; font-size: 12px; }
.install-banner button { border: 0; background: transparent; color: #b9cbe8; font-size: 26px; }
.warning { border: 1px solid #9a641e; background: #2c210e; color: #ffd58c; font-size: 13px; }

.panel { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.panel h2 { margin: -5px 0 2px; font-size: 18px; }
.panel h3 { margin: 0; color: #c7d0df; font-size: 12px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; font-weight: 900; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #87a5d4 50%), linear-gradient(135deg, #87a5d4 50%, transparent 50%); background-position: calc(100% - 19px) 23px, calc(100% - 13px) 23px; background-size: 6px 6px; background-repeat: no-repeat; font-weight: 700; }
.cards-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.stat-card { min-height: 62px; padding: 8px 3px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid; border-radius: 12px; background: #0b1527; text-align: center; }
.stat-card span { font-size: 9px; font-weight: 900; }
.stat-card strong { margin-top: 3px; font-size: 17px; }
.blue { color: #62a9ff; border-color: #1d5ea9; }
.green { color: #39df7b; border-color: #087a4b; }
.orange { color: #ff9f43; border-color: #975219; }
.purple { color: #c58aff; border-color: #70449d; }
.cyan { color: #55dede; border-color: #277a7a; }
.code-input { min-height: 62px; border-width: 1.5px; border-color: #1e70ff; font-size: 17px; }
.preview-panel { min-height: 330px; align-content: start; }
.preview-list { min-height: 278px; }
.reading-row { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid #1b2940; }
.reading-index { color: #7e91ae; font-weight: 800; }
.reading-code { overflow: hidden; color: #dce6f5; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.reading-status { display: block; margin-top: 2px; font-size: 10px; font-weight: 900; }
.empty { padding: 28px 0; color: #6f7f98; font-size: 13px; text-align: center; }
.last-panel { min-height: 86px; padding: 14px; display: grid; align-content: center; border: 1px solid #14613e; border-radius: 13px; background: #08251d; }
.last-panel strong { overflow: hidden; font-size: 23px; text-overflow: ellipsis; white-space: nowrap; }
.last-panel span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.action-heading { margin-top: 2px; }
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.action-button { min-height: 68px; border-width: 1px; border-style: solid; border-radius: 10px; background: #111c31; }
.app-footer { display: flex; justify-content: space-between; gap: 12px; padding: 4px 3px; color: #5f718e; font-size: 10px; }

dialog { color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .78); backdrop-filter: blur(2px); }
.cvdb-dialog { width: min(calc(100% - 30px), 620px); max-height: 88dvh; padding: 0; border: 0; border-radius: 18px; background: transparent; }
.dialog-card { display: grid; gap: 10px; max-height: 88dvh; overflow: auto; padding: 18px; border: 1px solid #315485; border-radius: 18px; background: var(--panel-2); }
.dialog-card h2 { margin: 0 0 2px; font-size: 18px; }
.dialog-card p { margin: 0 0 4px; color: #c5d0e1; line-height: 1.5; white-space: pre-line; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.muted { color: #8fa1bc !important; font-size: 12px; }
.scroll-list { max-height: 55dvh; overflow: auto; overscroll-behavior: contain; }
.list-entry, .photo-entry { padding: 11px 3px; border-top: 1px solid #24324a; }
.list-entry { display: grid; grid-template-columns: 34px 1fr; gap: 8px; }
.list-entry code { overflow-wrap: anywhere; color: #dce6f5; }
.photo-entry { display: grid; gap: 9px; }
.photo-entry img { width: 100%; max-height: 260px; object-fit: contain; border-radius: 10px; background: #050a14; }
.photo-name { overflow-wrap: anywhere; color: #dce6f5; font-size: 12px; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-actions button { min-height: 42px; border-radius: 9px; font-weight: 900; }
.share-photo { border: 1px solid #42caca; color: #42caca; background: transparent; }
.delete-photo { border: 1px solid #c33348; color: var(--red); background: transparent; }
.block-editor { min-height: 48dvh; padding: 14px; resize: vertical; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.block-content { min-height: 200px; max-height: 46dvh; margin: 0; overflow: auto; color: #dce6f5; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.55; }
.scanner-dialog { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: #000; }
.scanner-card { width: 100%; min-height: 100dvh; padding: calc(16px + var(--safe-top)) 16px calc(20px + var(--safe-bottom)); display: grid; grid-template-rows: 1fr auto auto; gap: 14px; align-items: center; background: #000; }
#reader { width: min(100%, 720px); max-height: 75dvh; overflow: hidden; }
#reader video { object-fit: cover; border-radius: 16px; }
.scanner-card p { margin: 0; font-weight: 800; text-align: center; }

@media (max-width: 380px) {
  .app-shell { padding-inline: 9px; }
  .panel { padding: 11px; }
  .header-spacer { display: none; }
  .app-header { grid-template-columns: auto 1fr; }
  .brand-small { text-align: left; }
  .stat-card span { font-size: 8px; }
  .connection { font-size: 9px; }
}

@media (display-mode: standalone) {
  .app-shell { padding-top: calc(5px + var(--safe-top)); }
}
