/* SCS Field Tracker - mobile-first styles */
:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card2: #273549;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f97316;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.hidden { display: none !important; }

header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15, 23, 42, .95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
}
.topbar-inner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; max-width: 1100px; margin: 0 auto;
}
.top-title { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 14px 90px; }

h1 { font-size: 1.4rem; margin-bottom: 4px; }
h2 { font-size: 1.15rem; margin: 18px 0 10px; }
h3 { font-size: 1rem; margin: 12px 0 8px; }
.sub { color: var(--muted); font-size: .9rem; margin-bottom: 14px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.card.tappable { cursor: pointer; transition: border-color .15s; }
.card.tappable:hover { border-color: var(--accent); }

.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }

button, .btn {
  font: inherit; cursor: pointer; border: none; border-radius: 10px;
  padding: 12px 18px; background: var(--accent); color: #fff; font-weight: 600;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--red); }
button.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.chip {
  padding: 7px 14px; font-size: .85rem; border-radius: 999px;
  background: var(--card2); color: var(--text); border: 1px solid var(--border);
}
.icon-btn {
  background: var(--card2); color: var(--text); border: 1px solid var(--border);
  width: 38px; height: 38px; border-radius: 10px; padding: 0; font-size: 1.1rem;
}

label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; color: #fff; background: var(--muted);
}
.tag { font-size: .78rem; color: var(--muted); }

/* login */
.login-wrap { max-width: 380px; margin: 12vh auto 0; }
.logo { text-align: center; margin-bottom: 24px; }
.logo .mark { font-size: 2.2rem; }
.logo h1 { font-size: 1.5rem; }

/* floor plan viewer */
.plan-wrap {
  position: relative; overflow: auto; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff; max-height: 72vh;
  touch-action: pan-x pan-y;
}
.plan-inner { position: relative; display: block; width: 100%; }
.plan-inner img { display: block; max-width: none; width: 100%; }
.pin {
  position: absolute; transform: translate(-50%, -100%);
  cursor: pointer; text-align: center; z-index: 5;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.4));
}
.pin .dot {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center; margin: 0 auto;
}
.pin .dot span { transform: rotate(45deg); font-size: 12px; }
.pin .pin-label {
  font-size: 10px; font-weight: 700; color: #111; background: rgba(255,255,255,.85);
  border-radius: 4px; padding: 1px 4px; margin-top: 2px; white-space: nowrap;
}
.plan-wrap.placing { cursor: crosshair; }

/* plan + pin list layout */
.plan-layout { display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 900px) {
  .plan-layout { flex-direction: row; align-items: flex-start; }
  .plan-layout .plan-wrap { flex: 1; }
  .plan-layout .pin-panel { width: 300px; flex: none; }
}
.pin-panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.pin-list { max-height: 62vh; overflow-y: auto; }
.pin-list-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px;
  border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 6px;
}
.pin-list-item:hover { background: var(--card2); }
.mini-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid #fff3; }

.zoom-ctrl { display: flex; gap: 6px; }
.zoom-ctrl button { padding: 9px 14px; font-size: 1rem; }

.pin.flash .dot { animation: pinflash .3s ease 8 alternate; }
@keyframes pinflash {
  from { transform: rotate(-45deg) scale(1); }
  to   { transform: rotate(-45deg) scale(1.9); }
}
.placing-banner {
  background: var(--accent); color: #fff; padding: 10px 14px;
  border-radius: 10px; margin-bottom: 10px; display: flex; align-items: center; gap: 10px;
}

/* bottom sheet / modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 700px) { .modal { align-items: center; } }
.modal-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px 16px 0 0; width: 100%; max-width: 700px;
  max-height: 88vh; overflow-y: auto; padding: 20px;
}
@media (min-width: 700px) { .modal-card { border-radius: 16px; } }
.modal-head { display: flex; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; flex: 1; }

/* history entries */
.entry {
  border-left: 3px solid var(--border); padding: 8px 0 8px 12px; margin-left: 4px;
}
.entry .when { font-size: .78rem; color: var(--muted); }
.entry .kv { font-size: .88rem; margin-top: 2px; }
.entry img { max-width: 140px; border-radius: 8px; margin-top: 6px; display: block; }

/* tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button {
  background: var(--card2); color: var(--muted); border: 1px solid var(--border);
  padding: 9px 16px; font-size: .9rem;
}
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table-scroll { overflow-x: auto; }

/* in-app photo viewer */
.lightbox {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, .88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 20px;
}
.lightbox img {
  max-width: 96vw; max-height: 88vh; border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.lightbox-cap { color: #e2e8f0; margin-top: 10px; font-size: .9rem; text-align: center; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 10px; z-index: 200; max-width: 90vw;
}
.toast.error { border-color: var(--red); }

.status-grid { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }

.preset-btn.active-preset { background: var(--accent); border-color: var(--accent); color: #fff; }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin: 10px 0; }
.dash-card { background: var(--card2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
@media print { .dash-card { background: #fff; border-color: #ccc; break-inside: avoid; } }
.status-tile {
  background: var(--card2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; text-align: center; min-width: 90px;
}
.status-tile .n { font-size: 1.4rem; font-weight: 800; }
.status-tile .l { font-size: .75rem; color: var(--muted); }

.field-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.field-row input[type="text"] { flex: 1; min-width: 120px; }
.field-row select { width: auto; }
.field-row input[type="checkbox"] { width: auto; }
.inline-label { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); margin: 0; }

.drag-handle { cursor: grab; color: var(--muted); font-size: 1.1rem; padding: 4px 6px; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.field-row.dragging { opacity: .4; }
.field-row.drag-over { outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 8px; }

/* report photo thumbnails: ~2in tall, natural width, no cropping so detail is visible */
.thumb { height: 190px; width: auto; max-width: 340px; border-radius: 8px; display: block; }
.no-thumbs .photo-col { display: none; }
.thumb-cap { font-size: .7rem; color: var(--muted); margin-top: 3px; max-width: 260px; }
.loc-thumb {
  width: 96px; height: 96px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; display: block;
}
.thumb-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* pin detail photo strip */
.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0 10px; }
.strip-item { position: relative; flex: none; }
.photo-x {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; padding: 0; border-radius: 50%;
  background: var(--red); color: #fff; font-size: 12px; line-height: 22px;
  border: 2px solid var(--card);
}
.photo-strip img {
  width: 76px; height: 76px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); flex: none; display: block;
}

.entry-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.entry-photos img { max-width: 120px; border-radius: 8px; display: block; }

/* floor plan figures in reports */
.plan-figure { margin-top: 12px; }
.plan-fig-wrap { position: relative; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.plan-fig-wrap img { width: 100%; display: block; }
.rpt-pin { position: absolute; transform: translate(-50%, -50%); text-align: center; pointer-events: none; }
.rpt-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; display: block; margin: 0 auto; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.rpt-lbl { font-size: 9px; font-weight: 700; background: rgba(255,255,255,.9); color: #111; padding: 0 3px; border-radius: 3px; white-space: nowrap; }
.rpt-pin.dim { opacity: .3; }

@media print {
  .thumb { height: 2in; width: auto; max-width: 3.4in; }
  img { break-inside: avoid; }
  tr { break-inside: avoid; }
  .plan-figure { page-break-before: always; break-inside: avoid; }
  .plan-fig-wrap { border-color: #ccc; }
  body { background: #fff; color: #000; }
  header, .no-print { display: none !important; }
  .card { border: 1px solid #ccc; background: #fff; }
  .status-tile { background: #fff; border: 1px solid #ccc; }
  .status-tile .l, .sub, .tag { color: #444; }
}
