:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #16202a;
  --muted: #5d6b78;
  --accent: #0f766e;
  --border: #dde3e8;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b;
    --surface: #1b2229;
    --text: #e8edf1;
    --muted: #9aa8b4;
    --accent: #2dd4bf;
    --border: #2a333c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 8px;
}

h1 { margin: 0; font-size: 1.6rem; }

.top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--surface); }
.btn.secondary { background: var(--border); color: var(--text); }
.btn.danger { background: transparent; color: #dc2626; padding-inline: 8px; }
.btn.wide { width: 100%; padding-block: 14px; }

.link {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.error { min-height: 1.2em; margin: 8px 0; color: #dc2626; font-size: 0.9rem; }

input[type="password"], input:not([type]) {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin: 16px 0 6px; font-weight: 600; }

/* Sign-in */
.login { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px; }
.login-panel {
  width: 100%;
  max-width: 380px;
  padding: 24px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.login-panel h2 { margin: 0 0 4px; }
.login-panel p { margin: 0; color: var(--muted); }

main { flex: 1; padding: 8px 16px 16px; }

.hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.hint button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.tile {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.tile:active { transform: scale(0.98); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.tile img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center;
  background: #fff;
  display: block;
}

.tile span {
  padding: 12px 14px;
  font-size: 1.15rem;
  font-weight: 600;
}

.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 48px;
}

.status {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
#status.offline { color: #b45309; }

/* Full-screen card view: always white so scanners get maximum contrast. */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: #16202a;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}
.viewer-bar h2 { flex: 1; margin: 0; font-size: 1.4rem; }
.viewer-bar .btn.secondary { background: #eef1f4; color: #16202a; }

.close {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: #eef1f4;
  color: #16202a;
  font-size: 1.3rem;
  cursor: pointer;
}

.viewer img {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  padding: 0 8px;
}

.viewer-tip {
  margin: 0;
  padding: 10px 16px 16px;
  text-align: center;
  font-size: 0.85rem;
  color: #5d6b78;
}

/* Add / edit sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.sheet-panel {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
}
@media (min-width: 600px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 20px; }
}
.sheet-panel h2 { margin: 0 0 12px; }

.pick {
  width: 100%;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.pick img {
  max-width: 100%;
  max-height: 40vh;
  border-radius: 8px;
  background: #fff;
}

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.sheet-actions .spacer { flex: 1; }
