/* =============================================================
   Münter Tool Register - styles (v2)
   Palette lives in the variables below. To match the brand deck
   exactly, swap these hex values and nothing else needs to change.
   ============================================================= */

:root {
  --shadow:  #1c2420;
  --forest:  #22332a;
  --moss:    #4f6a54;
  --moss-dk: #405746;
  --lichen:  #a9baa4;
  --granite: #6d726c;
  --ash:     #f3f2ee;
  --card:    #ffffff;
  --line:    #e0dfd9;
  --ok:      #3e6b47;
  --warn:    #9a6b1f;
  --bad:     #8c3a34;
  --radius:  10px;
  --mono: "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ash);
  color: var(--shadow);
  font-family: "Avenir Next", Avenir, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 680px; margin: 0 auto; padding-bottom: 56px; }

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--forest);
  color: #e9ede6;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar .wordmark {
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.topbar .wordmark span { color: var(--lichen); font-weight: 400; }
.topbar .tb-btns { display: flex; gap: 6px; }
.topbar button {
  background: none;
  border: 1px solid rgba(233,237,230,0.35);
  color: #e9ede6;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.topbar button.tb-solid { background: var(--moss); border-color: var(--moss); }

/* ---------- Tag plate ---------- */

.tag-plate {
  background: var(--forest);
  color: #eef1ec;
  margin: 16px;
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 10px rgba(28,36,32,0.18);
}
.tag-plate .code {
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.tag-plate .sub {
  font-size: 0.78rem;
  color: var(--lichen);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}
.tag-plate .state {
  font-size: 0.9rem;
  color: #eef1ec;
  margin-top: 4px;
}
.tag-plate .badges { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* ---------- Generic layout ---------- */

.wrap { padding: 0 16px; }
.center-wrap {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 16px 16px;
}

h1 { font-size: 1.35rem; margin: 18px 16px 8px; font-weight: 600; }
h2 { font-size: 1.05rem; margin: 0 0 10px; font-weight: 600; }
p.muted, .muted { color: var(--granite); }
.small { font-size: 0.85rem; }

/* ---------- Forms ---------- */

label.field { display: block; margin-bottom: 14px; }
label.field > .lbl {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--granite);
  margin-bottom: 5px;
}
label.field .req { color: var(--bad); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  font-size: 16px;
  font-family: inherit;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--shadow);
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236d726c' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--moss);
  outline-offset: 1px;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; gap: 0; } }

/* ---------- Buttons ---------- */

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  text-align: center;
}
.btn-primary { background: var(--moss); color: #fff; }
.btn-primary:active { background: var(--moss-dk); }
.btn-primary:disabled { background: var(--lichen); cursor: default; }
.btn-secondary {
  background: #fff;
  color: var(--forest);
  border: 1px solid var(--line);
}
.btn-danger { background: #fff; color: var(--bad); border: 1px solid #dcc3c0; }
.btn + .btn { margin-top: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Filter chips ---------- */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 16px 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--shadow);
  border-radius: 99px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.chip.on { background: var(--forest); border-color: var(--forest); color: #fff; }

/* ---------- Photo pickers ---------- */

.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.photo-slot {
  border: 1.5px dashed var(--lichen);
  border-radius: var(--radius);
  background: #fbfbf9;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  text-align: center;
  padding: 8px;
}
.photo-slot img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-slot .ps-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--granite);
  position: relative;
  z-index: 1;
}
.photo-slot.has-img .ps-label {
  background: rgba(28,36,32,0.72);
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
}
.photo-slot .ps-icon { font-size: 1.5rem; position: relative; z-index: 1; }
.photo-slot.has-img .ps-icon { display: none; }

/* ---------- Tool list ---------- */

.controls { padding: 12px 16px 4px; display: flex; flex-direction: column; gap: 10px; }

.tool-row {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 16px 10px;
  cursor: pointer;
}
.tool-row .thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--ash);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: var(--lichen);
  overflow: hidden;
}
.tool-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.tool-row .meta { min-width: 0; flex: 1; }
.tool-row .meta .code { font-family: var(--mono); font-weight: 700; font-size: 0.95rem; }
.tool-row .meta .name {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-row .meta .where {
  font-size: 0.8rem;
  color: var(--granite);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 99px;
  white-space: nowrap;
}
.badge.b-in        { background: #e4ecdf; color: var(--ok); }
.badge.b-out       { background: #f3e8d2; color: var(--warn); }
.badge.active      { background: #e4ecdf; color: var(--ok); }
.badge.in_repair   { background: #f3e8d2; color: var(--warn); }
.badge.lost        { background: #f2ddda; color: var(--bad); }
.badge.retired     { background: #e6e5e1; color: var(--granite); }
.badge.good        { background: #e4ecdf; color: var(--ok); }
.badge.fair        { background: #f3e8d2; color: var(--warn); }
.badge.needs_service { background: #f2ddda; color: var(--bad); }

/* ---------- Detail view ---------- */

.detail-photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 16px 16px; }
.detail-photos a {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--card);
}
.detail-photos img { width: 100%; height: 150px; object-fit: cover; display: block; }
.detail-photos .cap {
  font-size: 0.75rem;
  color: var(--granite);
  padding: 6px 8px;
  text-align: center;
}

.kv { display: grid; grid-template-columns: 42% 58%; gap: 8px 10px; font-size: 0.95rem; }
.kv dt { color: var(--granite); font-size: 0.85rem; padding-top: 1px; }
.kv dd { margin: 0; word-break: break-word; }
.kv dd.mono { font-family: var(--mono); font-size: 0.9rem; }

/* ---------- History ---------- */

.hist { list-style: none; margin: 0; padding: 0; }
.hist li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.hist li:last-child { border-bottom: none; }
.hist .h-date { color: var(--granite); flex: none; width: 62px; font-size: 0.82rem; padding-top: 2px; }
.hist .h-flag { color: var(--bad); font-weight: 600; }

/* ---------- Bottom sheets ---------- */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(28,36,32,0.5);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--ash);
  width: 100%;
  max-width: 680px;
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-up 0.18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(30px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 2px 0 12px; }
.sheet .grab {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto 12px;
}

.loc-group { margin-bottom: 8px; }
.lg-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--granite);
  margin: 10px 2px 6px;
}
.loc-opt {
  display: block;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 8px;
  cursor: pointer;
}
.loc-opt.sel { border-color: var(--moss); background: #eef3ec; font-weight: 600; }
.loc-opt.add { color: var(--moss); font-weight: 600; border-style: dashed; background: transparent; }

.seg { display: flex; gap: 8px; margin-bottom: 12px; }
.seg button {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.seg button.on { background: var(--forest); border-color: var(--forest); color: #fff; }
.seg button.on.warn { background: var(--bad); border-color: var(--bad); }

/* ---------- Scanner ---------- */

.scan-stage {
  position: relative;
  margin: 0 16px 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 3 / 4;
  max-height: 52vh;
}
.scan-stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-stage .reticle {
  position: absolute;
  inset: 14%;
  border: 2px solid rgba(255,255,255,0.75);
  border-radius: 14px;
  pointer-events: none;
}
.scan-stage.hit .reticle { border-color: #7ddb8a; box-shadow: 0 0 0 3px rgba(125,219,138,0.5); }
.scan-stage .torch {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(28,36,32,0.7);
  color: #fff;
  border: none;
  border-radius: 99px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-family: inherit;
}
.scan-ctx {
  margin: 0 16px 10px;
  padding: 10px 14px;
  background: var(--forest);
  color: #eef1ec;
  border-radius: var(--radius);
  font-size: 0.92rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.scan-ctx .cnt { font-family: var(--mono); font-weight: 700; font-size: 1.1rem; }

.result-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.result-row:last-child { border-bottom: none; }
.result-row .r-code { font-family: var(--mono); font-weight: 700; flex: none; }
.result-row.ok .r-code { color: var(--ok); }
.result-row.err .r-code { color: var(--bad); }

/* ---------- Manage ---------- */

.mg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.mg-row:last-child { border-bottom: none; }
.mg-row .mg-main { flex: 1; min-width: 0; }
.mg-row .mg-name { font-weight: 600; }
.mg-row .mg-sub { font-size: 0.8rem; color: var(--granite); word-break: break-all; }
.mg-row select { width: auto; padding: 8px 30px 8px 10px; font-size: 0.88rem; }
.mg-row .mg-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.mg-row.off .mg-name, .mg-row.off .mg-sub { color: var(--lichen); text-decoration: line-through; }

/* ---------- Success screen ---------- */

.success-check {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--moss);
  color: #fff;
  font-size: 2.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

/* ---------- Toasts and spinner ---------- */

#toast-zone {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  width: min(92vw, 480px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--shadow);
  color: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.92rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  animation: toast-in 0.18s ease-out;
}
.toast.err { background: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.spinner {
  width: 34px;
  height: 34px;
  border: 3.5px solid var(--line);
  border-top-color: var(--moss);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
  .toast, .sheet { animation: none; }
}
