/* ==========================================================================
   Knutts Notes — design tokens
   Palette: charcoal ground, stamped-amber tag accent, signal teal for
   "synced", rust for danger. Monospace carries IDs/tags/timestamps —
   everything else sits in a plain system sans.
   ========================================================================== */

:root {
  --charcoal: #1b1d21;
  --graphite: #24272c;
  --graphite-raised: #2d3137;
  --line: #383c43;
  --bone: #edeae3;
  --bone-dim: #a3a29d;
  --amber: #f2a73b;
  --amber-dim: #7a5a26;
  --teal: #4fa89b;
  --rust: #d65a4a;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "IBM Plex Mono", "Roboto Mono", Consolas, monospace;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;

  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--charcoal);
  color: var(--bone);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

::selection { background: var(--amber-dim); color: var(--bone); }

/* Scrollbars stay quiet */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  background: var(--charcoal);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.topbar__mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--amber);
  position: relative;
  flex-shrink: 0;
}
.topbar__mark::before {
  content: "";
  position: absolute;
  top: 5px; left: 5px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--charcoal);
}

.topbar__title {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 17px;
  flex: 1;
}

.topbar__btn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: var(--radius-s);
  color: var(--bone-dim);
}
.topbar__btn:active { background: var(--graphite-raised); color: var(--bone); }

/* ---------- Search ---------- */
.searchbar {
  padding: 0 14px 10px;
  background: var(--charcoal);
  flex-shrink: 0;
}
.searchbar__field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--graphite);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 9px 12px;
}
.searchbar__field input {
  background: none;
  border: none;
  outline: none;
  flex: 1;
  font-size: 15px;
  color: var(--bone);
}
.searchbar__field input::placeholder { color: var(--bone-dim); }
.searchbar__field svg { flex-shrink: 0; color: var(--bone-dim); }

.search-summary {
  padding: 0 14px 6px;
  font-size: 12px;
  color: var(--bone-dim);
  font-family: var(--font-mono);
}

/* ---------- Content area ---------- */
.view {
  flex: 1;
  overflow-y: auto;
  display: none;
  padding: 4px 14px 90px;
}
.view.is-active { display: block; }

.empty-state {
  margin-top: 15vh;
  text-align: center;
  color: var(--bone-dim);
  padding: 0 20px;
}
.empty-state__glyph {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--amber);
  margin-bottom: 8px;
  text-transform: uppercase;
}
.empty-state__body { font-size: 14px; line-height: 1.5; }

/* ---------- Tag chip (the signature element) ----------
   A stamped asset tag: a die-cut card with a punched hole,
   set in monospace. Used for asset/equipment IDs everywhere. */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  background: var(--graphite-raised);
  border: 1px solid var(--line);
  border-radius: 5px 9px 9px 5px;
  padding: 4px 10px 4px 6px;
  color: var(--amber);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--charcoal);
  border: 1px solid var(--amber-dim);
  flex-shrink: 0;
}
.tag-chip--plain { color: var(--bone-dim); }
.tag-chip--plain::before { border-color: var(--line); }

.tag-chip.is-selectable { cursor: pointer; }
.tag-chip.is-selected {
  background: var(--amber);
  color: var(--charcoal);
  border-color: var(--amber);
}
.tag-chip.is-selected::before { background: var(--charcoal); border-color: var(--charcoal); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------- List cards ---------- */
.card-list { display: flex; flex-direction: column; gap: 8px; padding: 8px 0 0; }

.item-card {
  background: var(--graphite);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  width: 100%;
  cursor: pointer;
}
.item-card:active { background: var(--graphite-raised); }

.item-card__title { font-size: 15.5px; font-weight: 600; }
.item-card__snippet {
  font-size: 13px;
  color: var(--bone-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.item-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.item-card__date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--bone-dim);
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--charcoal);
  padding-bottom: env(safe-area-inset-bottom);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}
.tabbar__btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 8px;
  color: var(--bone-dim);
}
.tabbar__btn svg { width: 22px; height: 22px; }
.tabbar__btn span { font-size: 11px; font-weight: 600; letter-spacing: 0.02em; }
.tabbar__btn.is-active { color: var(--amber); }

/* ---------- Floating action button ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--charcoal);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  z-index: 6;
}
.fab:active { transform: scale(0.94); }
.fab svg { width: 24px; height: 24px; }

/* ---------- Sheet / editor overlay ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10;
  display: none;
}
.sheet-backdrop.is-open { display: block; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 92dvh;
  background: var(--charcoal);
  border-top: 1px solid var(--line);
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  z-index: 11;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.24s ease;
}
.sheet.is-open { transform: translateY(0); }

.sheet__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sheet__header h2 { font-size: 16px; margin: 0; flex: 1; }
.sheet__body { padding: 14px; overflow-y: auto; }
.sheet__footer {
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.field { margin-bottom: 16px; position: relative; }
.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bone-dim);
  margin-bottom: 6px;
}
.field input, .field textarea {
  width: 100%;
  background: var(--graphite);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 11px 12px;
  font-size: 15px;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--amber); }
.field textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.field--mono input { font-family: var(--font-mono); font-size: 14px; }

.field__pw-wrap { display: flex; gap: 8px; }
.field__pw-wrap input { flex: 1; }
.field__pw-toggle {
  width: var(--tap);
  height: var(--tap);
  flex-shrink: 0;
  background: var(--graphite);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  display: grid;
  place-items: center;
  color: var(--bone-dim);
}
.field__pw-toggle.is-revealed { color: var(--teal); border-color: var(--teal); }

.field__copy {
  position: absolute;
  right: 8px;
  top: 30px;
  font-size: 11px;
  color: var(--teal);
  padding: 4px 8px;
  border-radius: 5px;
  font-family: var(--font-mono);
}

/* Autocomplete dropdown */
.autocomplete {
  position: relative;
}
.autocomplete__list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: var(--graphite-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  max-height: 160px;
  overflow-y: auto;
  z-index: 3;
  display: none;
}
.autocomplete__list.is-open { display: block; }
.autocomplete__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--bone);
  border-bottom: 1px solid var(--line);
}
.autocomplete__item:last-child { border-bottom: none; }
.autocomplete__item:active { background: var(--charcoal); }

/* ---------- Buttons ---------- */
.btn {
  flex: 1;
  height: 46px;
  border-radius: var(--radius-m);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn--primary { background: var(--amber); color: var(--charcoal); }
.btn--primary:active { background: #d99327; }
.btn--ghost { background: var(--graphite); border: 1px solid var(--line); color: var(--bone); }
.btn--ghost:active { background: var(--graphite-raised); }
.btn--danger { background: transparent; color: var(--rust); flex: 0 0 auto; padding: 0 14px; }

/* ---------- Login reveal lock ---------- */
.unlock-scrim {
  position: fixed;
  inset: 0;
  background: rgba(10,11,13,0.92);
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  text-align: center;
}
.unlock-scrim.is-open { display: flex; }
.unlock-scrim__icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--graphite);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--amber);
}
.unlock-scrim input {
  width: min(220px, 80vw);
  text-align: center;
  letter-spacing: 0.3em;
  font-family: var(--font-mono);
  font-size: 20px;
  background: var(--graphite);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 12px;
  color: var(--bone);
}
.unlock-scrim__error { color: var(--rust); font-size: 13px; min-height: 16px; }

/* ---------- Photos grid ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding-top: 8px;
}
.photo-tile {
  position: relative;
  aspect-ratio: 1;
  background: var(--graphite);
  border-radius: 4px;
  overflow: hidden;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile__status {
  position: absolute;
  bottom: 4px; left: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 2px 5px;
  border-radius: 3px;
  background: rgba(0,0,0,0.65);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.photo-tile__status--pending { color: var(--amber); }
.photo-tile__status--synced { color: var(--teal); }
.photo-tile__status--failed { color: var(--rust); }
.photo-tile__tag {
  position: absolute;
  top: 4px; left: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 2px 5px;
  border-radius: 3px;
  background: rgba(0,0,0,0.65);
  color: var(--bone);
  max-width: calc(100% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Camera capture screen ---------- */
.camera-stage {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 15;
  display: none;
  flex-direction: column;
}
.camera-stage.is-open { display: flex; }
.camera-stage__viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}
.camera-stage__viewport video, .camera-stage__viewport canvas {
  width: 100%; height: 100%; object-fit: cover;
  display: block;
}
.camera-stage__top {
  position: absolute;
  top: max(14px, env(safe-area-inset-top)); left: 14px; right: 14px;
  display: flex;
  justify-content: space-between;
  z-index: 2;
}
.camera-stage__top button {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: var(--bone);
  display: grid;
  place-items: center;
}
.camera-stage__controls {
  padding: 18px 20px calc(24px + env(safe-area-inset-bottom));
  background: #000;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.shutter-btn {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 4px solid var(--bone);
  background: transparent;
  display: grid;
  place-items: center;
}
.shutter-btn::after {
  content: "";
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--bone);
}
.shutter-btn:active::after { background: var(--amber); }

.camera-stage__tag-field {
  width: 100%;
  max-width: 340px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  background: var(--graphite-raised);
  border: 1px solid var(--line);
  color: var(--bone);
  padding: 10px 16px;
  border-radius: var(--radius-m);
  font-size: 13.5px;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  max-width: 88vw;
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.setup-banner {
  margin: 10px 0 4px;
  padding: 10px 12px;
  border: 1px dashed var(--amber-dim);
  border-radius: var(--radius-s);
  font-size: 12.5px;
  color: var(--bone-dim);
  line-height: 1.5;
}
.setup-banner b { color: var(--amber); }

@media (prefers-reduced-motion: reduce) {
  .sheet, .fab, .toast { transition: none; }
}

/* ---------- Icon buttons (sheet header) ---------- */
.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-s);
  color: var(--bone-dim);
  flex-shrink: 0;
}
.icon-btn:active { background: var(--graphite-raised); }
.icon-btn.is-active { color: var(--amber); }

/* ---------- Filter row (Notes tab) ---------- */
.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 0 2px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-row:empty { display: none; }

/* ---------- Voice dictation ---------- */
.textarea-wrap { position: relative; }
.mic-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--graphite-raised);
  border: 1px solid var(--line);
  color: var(--bone-dim);
  display: grid;
  place-items: center;
}
.mic-btn.is-listening {
  color: var(--charcoal);
  background: var(--rust);
  border-color: var(--rust);
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214,90,74,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(214,90,74,0); }
}

/* ---------- Update banner ---------- */
.update-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--amber-dim);
  color: var(--bone);
  padding: 8px 14px;
  font-size: 13px;
  flex-shrink: 0;
}
.update-banner.is-visible { display: flex; }
.update-banner button {
  background: var(--amber);
  color: var(--charcoal);
  font-weight: 700;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 6px;
  flex-shrink: 0;
}

/* ---------- Item card pin/share affordances ---------- */
.item-card__pin {
  color: var(--amber);
  flex-shrink: 0;
}
.item-card__row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.item-card__row .item-card__title { flex: 1; }

/* ---------- Camera: flash, multi-shot strip, done ---------- */
.camera-stage__top button.is-active { color: var(--amber); }
.camera-stage__row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
}
.camera-stage__spacer { width: 64px; flex-shrink: 0; }
.camera-stage__done { flex: 0 0 auto; padding: 0 18px; height: 44px; }
.camera-shots-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  min-height: 0;
}
.camera-shots-strip:empty { display: none; }
.camera-shots-strip img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid var(--line);
  flex-shrink: 0;
}

/* ---------- Photo lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.96);
  z-index: 25;
  display: none;
  flex-direction: column;
}
.lightbox.is-open { display: flex; }
.lightbox__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 14px 10px;
  flex-shrink: 0;
}
.lightbox__meta {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--bone-dim);
}
.lightbox__top button {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: var(--bone);
  display: grid;
  place-items: center;
}
.lightbox__body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.lightbox__body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.lightbox__loading {
  position: absolute;
  color: var(--bone-dim);
  font-size: 13px;
}
.lightbox__footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.lightbox__comment-input {
  width: 100%;
  background: var(--graphite);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 11px 12px;
  font-size: 14px;
  color: var(--bone);
}
.lightbox__comment-input:focus { border-color: var(--amber); outline: none; }

/* ---------- Camera: zoom slider ---------- */
.camera-zoom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}
.camera-zoom-row__label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--bone);
  min-width: 34px;
  text-align: right;
  flex-shrink: 0;
}
.camera-zoom-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.25);
  outline: none;
  margin: 0;
}
.camera-zoom-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid var(--charcoal);
  cursor: pointer;
}
.camera-zoom-row input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--amber);
  border: none;
  cursor: pointer;
}

/* ---------- Photos: date-grouped headers ---------- */
.photo-date-header {
  grid-column: 1 / -1;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bone-dim);
  padding: 10px 2px 4px;
}
.photo-date-header:first-child { padding-top: 2px; }

/* ---------- Duplicate-login warning ---------- */
.field-warning {
  font-size: 12.5px;
  color: var(--amber);
  margin-top: -10px;
  margin-bottom: 16px;
  display: none;
}
.field-warning.is-visible { display: block; }
