:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #dcdcd6;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --accent-soft: #e3ece8;
  --danger: #a33a2c;
  --danger-soft: #f7e6e3;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --ok: #2d6a3e;
  --ok-soft: #e2f1e6;
  --radius: 10px;
  --tap: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716;
    --surface: #202220;
    --text: #ebebe7;
    --muted: #a3a39c;
    --border: #3a3c39;
    --accent: #7fb8a5;
    --accent-text: #0f1a16;
    --accent-soft: #24332e;
    --danger: #e58b7d;
    --danger-soft: #3a2421;
    --warn: #e2b55c;
    --warn-soft: #3a3020;
    --ok: #86c995;
    --ok-soft: #1f3324;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.5rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
a { color: var(--accent); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- header ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem;
  padding: .5rem max(1rem, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); color: var(--text); text-decoration: none; font-weight: 650; }
.brand img { height: 32px; width: auto; max-width: 120px; object-fit: contain; }
.nav { display: flex; align-items: center; gap: .25rem; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav a, .nav .link {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 .8rem;
  border-radius: 999px; color: var(--text); text-decoration: none; white-space: nowrap; font: inherit;
}
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-logout { margin: 0; }
.link { background: none; border: 0; cursor: pointer; }
@media (max-width: 640px) {
  .nav { margin-left: 0; width: 100%; }
  .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70vw; }
}

/* ---- layout ---- */
.page { max-width: 1100px; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-left)) 4rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin: .5rem 0 1rem; }
.crumbs { margin: 0; }
.crumbs a { display: inline-flex; min-height: 44px; align-items: center; text-decoration: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; }
.card.narrow { max-width: 420px; margin: 8vh auto 0; }
.cols { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
.stack { display: grid; gap: .9rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }

/* ---- forms ---- */
label, .field { display: grid; gap: .35rem; font-weight: 550; }
label small, .field small { font-weight: 400; }
input[type=text], input:not([type]), input[type=search], input[type=password], select, textarea {
  width: 100%; min-height: var(--tap); padding: .6rem .75rem;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px;
}
input[readonly] { color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: 0 1.1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.alert { margin: 0; padding: .7rem .9rem; border-radius: 8px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
[hidden] { display: none !important; }

.picker { cursor: pointer; }
.picker-btn { border-style: dashed; }
.picker:focus-within .picker-btn { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.progress { display: grid; gap: .3rem; }
.progress-bar { height: 10px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---- materials ---- */
.filters { display: grid; gap: .5rem; grid-template-columns: 1fr; margin-bottom: .5rem; }
@media (min-width: 700px) { .filters { grid-template-columns: 1fr 220px 150px; } }
.count { margin: .25rem 0 .75rem; }
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
@media (max-width: 380px) { .grid { grid-template-columns: 1fr 1fr; gap: .5rem; } }
.tile { display: flex; flex-direction: column; height: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); text-decoration: none; }
.tile:hover { border-color: var(--accent); }
.tile.is-archived { opacity: .65; }
.tile-img { aspect-ratio: 1; background: var(--bg); display: grid; place-items: center; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-body { display: grid; gap: .15rem; padding: .6rem .7rem .7rem; }
.tile-body strong { overflow-wrap: anywhere; }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .78rem; font-weight: 600; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.noimg { color: var(--muted); font-size: .85rem; }
.noimg.big { padding: 2.5rem 0; text-align: center; background: var(--bg); border-radius: 8px; margin: 0 0 1rem; }
.empty { text-align: center; color: var(--muted); }
.preview { margin-bottom: 1rem; }
.preview img { display: block; width: 100%; max-height: 320px; object-fit: contain; background: var(--bg); border-radius: 8px; }
.preview p { margin: .4rem 0 0; overflow-wrap: anywhere; }
.logo-preview { min-height: 80px; display: grid; place-items: center; background: var(--bg); border-radius: 8px; margin-bottom: 1rem; padding: 1rem; }
.logo-preview img { max-height: 80px; max-width: 100%; }

/* ---- login ---- */
.login-brand { display: grid; justify-items: center; gap: .5rem; margin-bottom: 1rem; text-align: center; }
.login-brand img { max-height: 64px; max-width: 200px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100vw - 2rem); padding: .75rem 1.1rem; border-radius: 10px;
  background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 50;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ---- publish ---- */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem 1rem;
  padding: .5rem 1rem; background: var(--warn-soft); color: var(--warn); font-weight: 600; border-bottom: 1px solid var(--border);
}
.btn.small { min-height: 40px; padding: 0 .9rem; font-size: .9rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .65rem 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.issues { margin: 0 0 1rem; padding-left: 1.2rem; }
.issues li { margin: .2rem 0; overflow-wrap: anywhere; }
.status-pill { display: inline-flex; align-items: center; gap: .4rem; font-weight: 650; }
.status-pill::before { content: ""; width: .7rem; height: .7rem; border-radius: 50%; background: var(--ok); }
.status-pill.pending::before { background: var(--warn); }
.status-pill.none::before { background: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .5rem; border-top: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--muted); font-weight: 600; border-top: 0; }
pre.json { max-height: 420px; overflow: auto; background: var(--bg); padding: .75rem; border-radius: 8px; font-size: .82rem; margin: 0; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.err-text { color: var(--danger); }
.span-all { grid-column: 1 / -1; }
.form-error { white-space: pre-line; }
ol.small { padding-left: 1.2rem; }

/* ---- tags ---- */
.tabs { display: flex; gap: .25rem; overflow-x: auto; margin: -.25rem 0 1rem; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 .9rem; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.nfc-unsupported, .nfc-denied { margin-bottom: 1rem; }
.btn.big { min-height: 60px; font-size: 1.1rem; }
.mat-list { list-style: none; margin: .75rem 0 0; padding: 0; max-height: 55vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.mat-list li { display: flex; align-items: center; gap: .75rem; min-height: 64px; padding: .4rem .6rem; border-top: 1px solid var(--border); cursor: pointer; }
.mat-list li:first-child { border-top: 0; }
.mat-list li:hover { background: var(--bg); }
.mat-list li.is-selected { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.mat-list li > span:last-child, .selected-card > span { display: grid; min-width: 0; }
.mat-list li strong, .selected-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mat-list img, .selected-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex: none; background: var(--bg); }
.mat-list .noimg, .selected-card .noimg { width: 56px; height: 56px; display: grid; place-items: center; background: var(--bg); border-radius: 6px; flex: none; }
.selected { margin-bottom: .75rem; }
.selected-card { display: flex; align-items: center; gap: .75rem; padding: .6rem; border: 1px solid var(--border); border-radius: 8px; margin-bottom: .75rem; }
.nfc-status { display: flex; gap: .9rem; align-items: flex-start; margin: 1rem 0; padding: 1rem; border-radius: 10px; background: var(--bg); }
.nfc-status p { margin: .25rem 0 0; }
.nfc-status-icon { width: 28px; height: 28px; border-radius: 50%; flex: none; background: var(--muted); }
.nfc-status[data-state="waiting"] .nfc-status-icon { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.nfc-status[data-state="ok"] { background: var(--ok-soft); }
.nfc-status[data-state="ok"] .nfc-status-icon { background: var(--ok); }
.nfc-status[data-state="error"] { background: var(--danger-soft); }
.nfc-status[data-state="error"] .nfc-status-icon { background: var(--danger); }
@keyframes pulse { 0%, 100% { transform: scale(.85); opacity: .6; } 50% { transform: scale(1.1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .nfc-status[data-state="waiting"] .nfc-status-icon { animation: none; } }
#cancel-btn { margin-top: .5rem; }
.verdict { padding: .8rem 1rem; border-radius: 8px; margin-bottom: .9rem; }
.verdict p { margin: .25rem 0 0; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.warn { background: var(--warn-soft); color: var(--warn); }
.verdict.error { background: var(--danger-soft); color: var(--danger); }
.manual { margin-top: 1rem; }
textarea { width: 100%; padding: .6rem .75rem; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
textarea.mono, input.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; }
.json-editor { min-height: 50vh; font-size: .82rem; line-height: 1.45; tab-size: 2; white-space: pre; overflow: auto; }
.editor-actions { justify-content: flex-end; }
.editor-actions .btn { flex: 1 1 auto; }
@media (min-width: 700px) { .editor-actions .btn { flex: 0 0 auto; } }
