:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f4ee;
  --bg-tertiary: #ece9de;
  --bg-info: #e6f1fb;
  --bg-success: #eaf3de;
  --bg-warning: #faeeda;
  --bg-danger: #fcebeb;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-tertiary: #999;
  --text-info: #0c447c;
  --text-success: #3b6d11;
  --text-warning: #854f0b;
  --text-danger: #a32d2d;
  --border-tertiary: rgba(0,0,0,0.1);
  --border-secondary: rgba(0,0,0,0.2);
  --border-info: rgba(12,68,124,0.3);
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 1rem;
  line-height: 1.5;
  font-size: 16px;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

#app {
  max-width: 720px;
  margin: 0 auto;
}

p { margin: 0; }

.boot { color: var(--text-tertiary); text-align: center; padding: 2rem 1rem; }
.boot.error { color: var(--text-danger); }

/* ---------- header ---------- */

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 0 0 1rem;
  border-bottom: 0.5px solid var(--border-tertiary);
  margin-bottom: 1.25rem;
}
.app-eyebrow {
  font-size: 11px; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.app-title { font-size: 18px; font-weight: 500; }
.header-actions { display: flex; gap: 6px; }

/* ---------- buttons ---------- */

.btn {
  font-family: inherit;
  font-size: 14px;
  background: transparent;
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  min-height: 44px;
  cursor: pointer;
  color: var(--text-primary);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-secondary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { font-size: 12px; padding: 4px 10px; min-height: 0; }
.btn-primary {
  background: var(--bg-info);
  border-color: var(--border-info);
  color: var(--text-info);
  font-weight: 500;
}
.btn-primary:hover { background: #d8e7f7; }
.btn-ghost { border-color: transparent; }
.btn-ghost:hover { background: var(--bg-secondary); border-color: var(--border-tertiary); }

/* ---------- cards ---------- */

.card {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
}

.card-list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.1s;
}
.row:hover { background: var(--bg-secondary); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 500; margin-bottom: 2px; }
.row-sub { font-size: 12px; color: var(--text-secondary); }

/* ---------- badges ---------- */

.badge {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-weight: 500;
  white-space: nowrap;
}
.badge-active, .badge-draft { background: var(--bg-success); color: var(--text-success); }
.badge-completed { background: var(--bg-info); color: var(--text-info); }
.badge-archived { background: var(--bg-secondary); color: var(--text-secondary); }

/* ---------- empty states ---------- */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--bg-primary);
  border: 0.5px dashed var(--border-tertiary);
  border-radius: var(--radius-lg);
}
.empty-title { font-size: 16px; font-weight: 500; margin-bottom: 4px; }
.empty-sub { font-size: 13px; color: var(--text-secondary); }

.empty-inline {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 1.25rem 1rem;
  border-style: dashed;
}

/* ---------- forms ---------- */

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.field-label em {
  font-style: normal;
  color: var(--text-tertiary);
  font-weight: 400;
  margin-left: 6px;
}
.field input, .field textarea {
  font-family: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 44px;
}
.field input:focus, .field textarea:focus {
  outline: 2px solid var(--border-info);
  outline-offset: -1px;
}
.field textarea { resize: vertical; min-height: 88px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 4px;
  background: var(--bg-secondary);
  padding: 4px;
  border-radius: var(--radius-md);
}
.segmented-item {
  text-align: center;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.1s;
}
.segmented-item:hover { background: rgba(255,255,255,0.5); }
.segmented-item.is-active {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.segmented-item input { display: none; }

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

/* ---------- visit overview ---------- */

.visit-card { padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.visit-card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.visit-card-title { font-size: 16px; font-weight: 500; margin-bottom: 2px; }
.visit-card-sub { font-size: 13px; color: var(--text-secondary); }
.visit-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.visit-card-notes {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 0.5px solid var(--border-tertiary);
}

.chip {
  background: var(--bg-secondary);
  padding: 10px 12px;
  border-radius: var(--radius-md);
}
.chip-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
.chip-value { font-size: 13px; font-weight: 500; }

.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 720px) {
  .two-col { grid-template-columns: 1.2fr 1fr; }
}

.col { display: flex; flex-direction: column; gap: 10px; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.section-title { font-size: 14px; font-weight: 500; }
.section-sub { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }

/* ---------- template picker ---------- */

.picker-intro { margin-bottom: 1rem; }
.picker-title { font-size: 18px; font-weight: 500; margin-bottom: 4px; }
.picker-sub { font-size: 13px; color: var(--text-secondary); }

.picker-search {
  font-family: inherit;
  font-size: 16px;
  width: 100%;
  padding: 10px 14px;
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  margin-bottom: 1rem;
  min-height: 44px;
}
.picker-search:focus { outline: 2px solid var(--border-info); outline-offset: -1px; }

.picker-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 1rem;
}
@media (min-width: 520px) {
  .picker-grid { grid-template-columns: 1fr 1fr; }
}

.picker-empty {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 1.5rem;
}

.tpl-card {
  cursor: pointer;
  padding: 12px 14px;
  transition: background 0.1s, border-color 0.1s;
}
.tpl-card:hover { background: var(--bg-secondary); border-color: var(--border-secondary); }
.tpl-card-generic { background: var(--bg-secondary); }
.tpl-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.tpl-card-title { font-size: 14px; font-weight: 500; }
.tpl-card-use {
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 1px 6px;
  border-radius: var(--radius-md);
  white-space: nowrap;
}
.tpl-card-meta { font-size: 11px; color: var(--text-secondary); }
.tpl-card-desc {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ---------- equipment cards on visit overview ---------- */

.eq-list { display: flex; flex-direction: column; gap: 8px; }
.eq-card {
  cursor: pointer;
  padding: 12px 14px;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.eq-card:hover { background: var(--bg-secondary); }
.eq-card-active { border-left-color: var(--text-info); }
.eq-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.eq-card-title { font-size: 14px; font-weight: 500; }
.eq-card-badge {
  font-size: 10px;
  color: var(--text-info);
  background: var(--bg-info);
  padding: 2px 6px;
  border-radius: var(--radius-md);
}
.eq-card-sn {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  margin-top: 4px;
}
.eq-card-meta { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

/* ---------- equipment form ---------- */

.form-context {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 1.25rem;
}
.form-context-title { font-size: 14px; font-weight: 500; }
.form-context-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ---------- equipment detail ---------- */

.eq-head { padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.eq-head-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.eq-head-title { font-size: 18px; font-weight: 500; }
.eq-head-sn {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  margin-top: 4px;
}

.eq-section { margin-bottom: 1.25rem; }

.readings-card { padding: 0; overflow-x: auto; }
.readings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.readings-table th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 11px;
  background: var(--bg-secondary);
  white-space: nowrap;
}
.readings-table .unit {
  font-weight: 400;
  color: var(--text-tertiary);
}
.readings-table td { padding: 8px 12px; }
.readings-table .empty-row td {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 12px;
  padding: 1rem;
}

.prompt-list {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
  padding-left: 1.25rem;
}
.prompt-list li { margin-bottom: 2px; }

/* ---------- reading form ---------- */

.reading-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.field-unit-label {
  color: var(--text-tertiary);
  font-weight: 400;
}

.input-with-unit { position: relative; display: flex; }
.input-with-unit input { flex: 1; padding-right: 36px; }
.input-unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.field-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}
.field-warning {
  font-size: 11px;
  margin-top: 2px;
  font-weight: 500;
}
.field-warning-out { color: var(--text-danger); }
.field-warning-borderline { color: var(--text-warning); }

.btn-danger {
  border-color: var(--bg-danger);
  color: var(--text-danger);
  background: var(--bg-danger);
}
.btn-danger:hover {
  background: #f8dcdc;
}

.form-actions-edit { justify-content: space-between; }

/* ---------- readings table cells ---------- */

.readings-table tbody tr {
  cursor: pointer;
  border-top: 0.5px solid var(--border-tertiary);
  transition: background 0.1s;
}
.readings-table tbody tr:hover { background: var(--bg-secondary); }
.readings-table .cell-time {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  white-space: nowrap;
}
.readings-table .cell-note {
  color: var(--text-secondary);
  max-width: 220px;
}
.readings-table .cell-empty { color: var(--text-tertiary); }
.readings-table .cell-out { color: var(--text-danger); font-weight: 500; }
.readings-table .cell-borderline { color: var(--text-warning); font-weight: 500; }

/* ---------- observations ---------- */

.obs-list { padding: 0; overflow: hidden; }

.obs-row {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 0.5px solid var(--border-tertiary);
  cursor: pointer;
  transition: background 0.1s;
}
.obs-row:first-child { border-top: 0; }
.obs-row:hover { background: var(--bg-secondary); }

.obs-bar {
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--border-tertiary);
}
.obs-row.obs-sev-repair_now   .obs-bar { background: var(--text-danger); }
.obs-row.obs-sev-repair_later .obs-bar { background: var(--text-warning); }
.obs-row.obs-sev-monitor      .obs-bar { background: var(--text-info); }
.obs-row.obs-sev-fyi          .obs-bar { background: var(--border-secondary); }

.obs-body { flex: 1; min-width: 0; }
.obs-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.obs-desc {
  font-size: 13px;
  font-weight: 500;
  word-break: break-word;
}
.obs-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.obs-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-md);
  font-weight: 500;
  white-space: nowrap;
  text-transform: lowercase;
  letter-spacing: 0.2px;
}
.obs-badge.obs-sev-repair_now   { background: var(--bg-danger);    color: var(--text-danger); }
.obs-badge.obs-sev-repair_later { background: var(--bg-warning);   color: var(--text-warning); }
.obs-badge.obs-sev-monitor      { background: var(--bg-info);      color: var(--text-info); }
.obs-badge.obs-sev-fyi          { background: var(--bg-secondary); color: var(--text-secondary); }

/* severity preview tint on form segmented buttons */
.segmented-item.segmented-sev-repair_now.is-active   { color: var(--text-danger); }
.segmented-item.segmented-sev-repair_later.is-active { color: var(--text-warning); }
.segmented-item.segmented-sev-monitor.is-active      { color: var(--text-info); }
.segmented-item.segmented-sev-fyi.is-active          { color: var(--text-secondary); }

/* ---------- form select ---------- */

.field select {
  font-family: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 44px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23999' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.field select:focus { outline: 2px solid var(--border-info); outline-offset: -1px; }

/* ---------- timeline ---------- */

.timeline { padding: 0; overflow: hidden; }

.timeline-row {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-top: 0.5px solid var(--border-tertiary);
  cursor: pointer;
  transition: background 0.1s;
}
.timeline-row:first-child { border-top: 0; }
.timeline-row:hover { background: var(--bg-secondary); }

.timeline-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  min-width: 44px;
  padding-top: 2px;
  flex-shrink: 0;
}
.timeline-body { flex: 1; min-width: 0; }
.timeline-desc {
  font-size: 13px;
  word-break: break-word;
}
.timeline-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ---------- photo grid (equipment detail) ---------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px;
}
.photo-tile {
  aspect-ratio: 1;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.1s;
}
.photo-tile:hover { opacity: 0.85; }
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- photo attach (forms) ---------- */

.photo-attach {
  border: 0.5px dashed var(--border-tertiary);
  border-radius: var(--radius-md);
  padding: 12px;
}
.photo-attach-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.photo-attach-empty {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 8px 0;
}
.photo-attach-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.photo-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}
.photo-thumb {
  aspect-ratio: 1;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 10px;
  color: var(--text-tertiary);
}
.photo-thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-thumb-remove:hover { background: rgba(0,0,0,0.75); }

/* ---------- photo viewer ---------- */

.photo-viewer {
  display: flex;
  flex-direction: column;
  min-height: 90vh;
  gap: 12px;
}
.photo-viewer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.photo-viewer-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 240px;
}
.photo-viewer-stage img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}
.photo-viewer-foot {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.photo-viewer-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

/* ---------- active equipment pin bar ---------- */

.active-pin-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-info);
  border: 0.5px solid var(--border-info);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  margin-bottom: 1rem;
  font-size: 13px;
}
.active-pin-eyebrow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-info);
  font-weight: 600;
  flex-shrink: 0;
}
.active-pin-select {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-info);
  background: transparent;
  border: 0;
  appearance: none;
  padding: 4px 24px 4px 0;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%230c447c' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 4px center;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.active-pin-select:focus { outline: 2px solid var(--border-info); outline-offset: 2px; }

/* ---------- quick-add bar (sticky bottom) ---------- */

.quick-add-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 6px;
  padding: 10px 0;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  margin-top: 1.5rem;
  background: linear-gradient(to top, var(--bg-tertiary) 70%, rgba(236, 233, 222, 0));
  z-index: 10;
}
.quick-btn {
  flex: 1;
  min-height: 48px;
  font-size: 14px;
  padding: 10px 12px;
}

/* ---------- settings ---------- */

.settings-section {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.settings-title {
  font-size: 14px;
  font-weight: 500;
  margin: 0 0 6px;
}
.settings-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.settings-table {
  width: 100%;
  font-size: 13px;
}
.settings-table td { padding: 4px 0; }
.settings-table td:last-child {
  text-align: right;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}
.settings-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
}
.settings-status {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg-info);
  color: var(--text-info);
  border-radius: var(--radius-md);
  font-size: 12px;
}
.settings-status-error {
  background: var(--bg-danger);
  color: var(--text-danger);
}

/* ---------- dialog ---------- */

.app-dialog {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  max-width: 360px;
  width: calc(100% - 2rem);
  background: var(--bg-primary);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.app-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog-title { margin: 0 0 8px; font-size: 16px; font-weight: 500; }
.dialog-message {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 16px;
  white-space: pre-line;
}
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* ---------- print view (screen styles) ---------- */

.print-view {
  background: white;
  color: #1a1a1a;
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-lg);
  padding: 2rem 2rem;
  max-width: 800px;
  margin: 0 auto;
  font-size: 13px;
  line-height: 1.5;
}

.print-eyebrow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}
.print-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.print-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.print-header { margin-bottom: 24px; }

.print-meta {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.print-meta th {
  text-align: left;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 4px 12px 4px 0;
  white-space: nowrap;
  width: 1%;
  vertical-align: top;
}
.print-meta td { padding: 4px 0; vertical-align: top; }
.print-meta-inline { margin-bottom: 8px; }

.print-notes,
.print-notes-inline {
  font-size: 12px;
  margin-top: 12px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  white-space: pre-line;
}
.print-section-eyebrow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.print-section { margin: 24px 0; }
.print-section-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 0.5px solid var(--border-secondary);
}
.print-sn {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 8px;
}
.print-subsection-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin: 16px 0 6px;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-bottom: 4px;
}
.print-table th,
.print-table td {
  border: 0.5px solid var(--border-secondary);
  padding: 4px 6px;
  text-align: left;
  vertical-align: top;
}
.print-table th {
  background: var(--bg-secondary);
  font-weight: 500;
}
.print-col-time { width: 56px; white-space: nowrap; }
.print-col-sev  { width: 90px; white-space: nowrap; }
.print-unit { color: var(--text-tertiary); font-weight: 400; }
.print-cell-note {
  font-size: 10px;
  color: var(--text-secondary);
}
.print-cell-out { color: var(--text-danger); font-weight: 500; }
.print-cell-borderline { color: var(--text-warning); font-weight: 500; }

.print-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
  margin-top: 4px;
}
.print-photo {
  margin: 0;
  aspect-ratio: 1;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.print-photo img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}

.print-empty,
.print-empty-inline {
  color: var(--text-tertiary);
  font-size: 11px;
  font-style: italic;
}
.print-empty-inline { margin: 4px 0 12px; }

.print-footer {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 0.5px solid var(--border-tertiary);
  font-size: 10px;
  color: var(--text-tertiary);
  text-align: right;
  font-family: var(--font-mono);
}

/* ---------- print media (paper output) ---------- */

@page {
  size: letter;
  margin: 0.6in;
}

@media print {
  body {
    background: white !important;
    padding: 0 !important;
    font-size: 11pt;
    line-height: 1.4;
  }
  #app { max-width: none !important; }
  .no-print,
  .app-header,
  .active-pin-bar,
  .quick-add-bar { display: none !important; }
  .print-view {
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
    max-width: none;
    background: white;
  }
  .print-equipment {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .print-table thead { display: table-header-group; }
  .print-table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .print-photos {
    grid-template-columns: repeat(6, 1fr);
  }
  .print-photo { aspect-ratio: 1; }
  /* respect color text in cells */
  .print-cell-out { color: #a32d2d !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-cell-borderline { color: #854f0b !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-table th {
    background: #f5f4ee !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ---------- update banner ---------- */

.update-banner {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-info);
  border: 0.5px solid var(--border-info);
  color: var(--text-info);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  z-index: 100;
  max-width: 480px;
  margin: 0 auto;
}
.update-banner-text {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

@media print {
  .update-banner { display: none !important; }
}

/* ---------- photo manager ---------- */

.pm-filterbar {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pm-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.pm-filter {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 100px;
}
.pm-filter > span {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.pm-filter select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 24px 6px 8px;
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23999' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
}
.pm-search {
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  padding: 8px 10px;
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
}
.pm-count {
  font-size: 11px;
  color: var(--text-tertiary);
}
.pm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  padding-bottom: 80px;
}
.pm-tile {
  position: relative;
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.pm-tile.is-selected {
  outline: 3px solid var(--text-info);
  outline-offset: -3px;
}
.pm-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--bg-secondary);
}
.pm-tile-check {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--border-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-info);
}
.pm-tile.is-selected .pm-tile-check {
  background: var(--text-info);
  color: white;
  border-color: var(--text-info);
}
.pm-tile-info {
  padding: 6px 8px;
}
.pm-tile-caption {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pm-tile-meta {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 2px;
}
.pm-bulkbar {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  background: var(--bg-primary);
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 50;
  max-width: 720px;
  margin: 0 auto;
}
.pm-bulk-count {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

/* ---------- photo viewer (citations) ---------- */

.photo-viewer-nav {
  display: flex;
  gap: 6px;
  align-items: center;
}
.photo-viewer-position {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.photo-viewer-printhome {
  font-size: 12px;
  background: var(--bg-secondary);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}
.photo-viewer-printhome-label {
  font-weight: 500;
  color: var(--text-primary);
  margin-right: 4px;
}

.photo-citations {
  margin-top: 4px;
}
.photo-citations-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.photo-citation-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 0.5px solid var(--border-tertiary);
  font-size: 12px;
}
.photo-citation-row:first-child { border-top: 0; }

.photo-citation-badge {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.photo-citation-badge-observation { background: var(--bg-warning); color: var(--text-warning); }
.photo-citation-badge-event       { background: var(--bg-success); color: var(--text-success); }
.photo-citation-badge-reading     { background: var(--bg-info);    color: var(--text-info); }
.photo-citation-badge-equipment   { background: var(--bg-secondary); color: var(--text-secondary); }

.photo-citation-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo-citation-printhome {
  font-size: 10px;
  color: var(--text-info);
  background: var(--bg-info);
  padding: 1px 6px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

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

/* ---------- photo source actions row ---------- */

.photo-attach-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- picker dialogs ---------- */

.app-dialog-wide { max-width: 560px; }

.picker-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
  margin: 12px 0;
}
.picker-photo-tile {
  position: relative;
  cursor: pointer;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.picker-photo-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--bg-secondary);
}
.picker-photo-tile.is-selected {
  outline: 3px solid var(--text-info);
  outline-offset: -3px;
}
.picker-photo-overlay {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-info);
}
.picker-photo-tile.is-selected .picker-photo-overlay {
  display: flex;
  background: var(--text-info);
  color: white;
}
.picker-photo-caption {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 10px;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.picker-entity-list {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
  border: 0.5px solid var(--border-tertiary);
  border-radius: var(--radius-md);
}
.picker-entity-list li { border-top: 0.5px solid var(--border-tertiary); }
.picker-entity-list li:first-child { border-top: 0; }
.picker-entity-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}
.picker-entity-row:hover { background: var(--bg-secondary); }
.picker-entity-badge {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.picker-entity-badge-observation { background: var(--bg-warning); color: var(--text-warning); }
.picker-entity-badge-event       { background: var(--bg-success); color: var(--text-success); }
.picker-entity-badge-reading     { background: var(--bg-info);    color: var(--text-info); }
.picker-entity-badge-equipment   { background: var(--bg-secondary); color: var(--text-secondary); }
.picker-entity-label {
  flex: 1;
  font-size: 13px;
}

.dialog-input {
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  padding: 10px 12px;
  border: 0.5px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  margin: 12px 0;
}

/* ---------- print: per-row photo blocks ---------- */

.print-obs-block {
  margin-bottom: 6px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.print-obs-desc { font-weight: 500; }
.print-photos-small {
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  margin-top: 4px;
  gap: 4px;
}
.print-photos-small .print-photo {
  aspect-ratio: 1;
}
.print-photo-caption {
  font-size: 9px;
  color: var(--text-secondary);
  padding: 2px 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.print-reading-photos {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.print-reading-photo-block { font-size: 11px; }
.print-event-photos { margin-top: 4px; }

@media print {
  .pm-filterbar,
  .pm-bulkbar { display: none !important; }
  .print-obs-block,
  .print-reading-photo-block { page-break-inside: avoid; break-inside: avoid; }
}
