/* ==========================================================================
   Recreation Asset Manager v2 — full app stylesheet
   ========================================================================== */
:root {
  --bg: #F7F6F2;
  --surface: #F9F8F5;
  --surface-2: #FBFBF9;
  --border: #D4D1CA;
  --text: #28251D;
  --text-muted: #7A7974;
  --text-faint: #BAB9B4;
  --primary: #01696F;
  --primary-hover: #0C4E54;
  --primary-faint: #E2EFF0;
  --error: #A12C7B;
  --warn: #964219;
  --success: #437A22;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.18);
  --rad: 8px;
  --rad-lg: 12px;
  --font: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --appbar-h: 56px;
  --sidebar-w: 340px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

/* ---------- App bar ---------- */
#appbar {
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1100;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 15px; font-weight: 700; margin: 0; line-height: 1.1; }
.brand .subtitle { font-size: 11px; color: var(--text-muted); margin: 2px 0 0; }
.viewswitch { display: flex; gap: 4px; padding: 3px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; }
.vsw {
  border: none; background: transparent; color: var(--text-muted);
  padding: 6px 16px; font-size: 13px; font-weight: 500;
  border-radius: 999px; cursor: pointer;
}
.vsw.active { background: var(--primary); color: white; }
.appbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pill {
  font-size: 11px; padding: 3px 10px; background: var(--primary-faint); color: var(--primary);
  border-radius: 999px; font-weight: 500;
}
.pill.dirty { background: #FCE4D6; color: var(--warn); }

#hamburger { display: none; }

/* ---------- View containers ---------- */
.view { display: none; height: calc(100vh - var(--appbar-h)); }
.view.active { display: flex; }
#map-view { position: relative; }
#table-view { flex-direction: column; }

/* ---------- Sidebar (map view) ---------- */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex-shrink: 0;
}
.tabs {
  display: flex;
  padding: 8px 8px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tab {
  border: none; background: transparent;
  padding: 8px 12px; font-size: 13px; font-weight: 500;
  color: var(--text-muted); cursor: pointer;
  border-radius: 6px 6px 0 0;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--surface-2); }
.tab:hover:not(.active) { color: var(--text); }

.panels { flex: 1; overflow-y: auto; min-height: 0; }
.panel { display: none; padding: 14px; }
.panel.active { display: block; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  background: var(--surface-2);
}
#status { font-family: var(--mono); }

/* ---------- Stats row ---------- */
.stat-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--rad); padding: 10px 8px; text-align: center;
}
.stat-num { display: block; font-size: 22px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Fields & inputs ---------- */
.field { margin-bottom: 16px; }
.field label, .field > label > span { font-size: 12px; font-weight: 500; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.field-head label { margin-bottom: 0; }
.hint { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; }
.hint.sm { font-size: 11px; margin-top: 4px; }

input[type="text"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; font-family: inherit; font-size: 13px; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(1,105,111,.15);
}
input[type="file"] { padding: 6px; background: transparent; }
textarea { resize: vertical; min-height: 60px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.search-wrap { position: relative; }
.search-wrap input { padding-right: 28px; }
.icon-btn {
  background: transparent; border: none; cursor: pointer; padding: 4px 8px;
  color: var(--text-muted); font-size: 16px;
}
.icon-btn:hover { color: var(--text); }
#search-clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: 8px 14px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  border-radius: 6px; font-family: inherit;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--error); color: white; border-color: var(--error); }
.btn.danger:hover { background: #862263; }
.btn.full { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; margin-bottom: 12px; }
.btn-row .btn { flex: 1; }
.link-row { display: flex; gap: 8px; }
.linkbtn {
  background: transparent; border: none; cursor: pointer;
  color: var(--primary); font-size: 12px; font-weight: 500; padding: 2px 4px;
}
.linkbtn:hover { text-decoration: underline; }
.row-with-btn { display: flex; gap: 6px; }
.row-with-btn select { flex: 1; }

/* ---------- Segmented control ---------- */
.seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  flex-wrap: wrap;
}
.seg-btn {
  flex: 1; border: none; background: transparent;
  padding: 6px 8px; font-size: 12px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; border-radius: 6px; white-space: nowrap;
}
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg-btn:not(.active):hover { color: var(--text); }

/* ---------- Checkline ---------- */
.checkline { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 6px; }
.checkline input { width: auto; }
.checkline span { margin-bottom: 0; color: var(--text); }

/* ---------- Type list ---------- */
.type-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; margin-bottom: 6px; }
.type-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  border-radius: 4px; cursor: pointer; font-size: 12px;
}
.type-row:hover { background: var(--bg); }
.type-row input { width: 18px; height: 18px; flex-shrink: 0; cursor: pointer; accent-color: var(--accent); }
.type-row .name { flex: 1; color: var(--text); }
.type-row .count { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(0,0,0,.1); }
.swatch.clickable { cursor: pointer; }
.swatch.clickable:hover { transform: scale(1.2); }

/* ---------- Map ---------- */
#map-wrap { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }
.sidebar-toggle {
  position: absolute; top: 12px; left: 12px;
  z-index: 500; background: white; border: 1px solid var(--border);
  width: 32px; height: 32px; border-radius: 6px;
  cursor: pointer; font-size: 18px; color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}
body.sidebar-collapsed #sidebar { display: none; }
body.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }

/* ---------- Markers ---------- */
.asset-marker {
  border: 2px solid white; box-shadow: 0 1px 3px rgba(0,0,0,.4);
  transition: transform .15s;
}
.asset-marker.shape-circle { border-radius: 50%; }
.asset-marker.shape-square { border-radius: 2px; }
.asset-marker.shape-diamond { transform: rotate(45deg); border-radius: 2px; }
.asset-marker.shape-triangle {
  width: 0 !important; height: 0 !important; background: transparent !important;
  border-left: var(--half) solid transparent !important;
  border-right: var(--half) solid transparent !important;
  border-bottom: var(--full) solid var(--fill) !important;
  border-top: none !important; box-shadow: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
}
.asset-marker.shape-star {
  border: none;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
  box-shadow: none;
}
.asset-marker.has-ring { box-shadow: 0 0 0 3px white, 0 0 0 5px var(--ring-color, var(--primary)), 0 2px 6px rgba(0,0,0,.3); }
/* Move mode: signal that markers are draggable */
body.move-mode .asset-marker,
body.move-mode .park-marker { cursor: move; }
body.move-mode .leaflet-marker-draggable.leaflet-marker-icon { outline: 2px dashed rgba(220, 38, 38, .55); outline-offset: 2px; border-radius: 50%; }
.asset-marker.selected { transform: scale(1.4); box-shadow: 0 0 0 3px var(--primary), 0 2px 6px rgba(0,0,0,.4); }
.park-marker {
  border-radius: 50%; border: 4px solid currentColor;
  background: rgba(255,255,255,.7); box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
/* Park halo: bold ring + translucent tinted fill so asset markers sit clearly INSIDE the park */
.park-marker.filled {
  background: color-mix(in srgb, currentColor 22%, white 78%);
  border: 5px solid currentColor;
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(255,255,255,.85), 0 3px 8px rgba(0,0,0,.22);
}
.asset-label {
  background: rgba(255,255,255,.92); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 3px; font-size: 11px; font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.leaflet-popup-content { margin: 10px 14px; font-family: inherit; }
.leaflet-popup-content .ptype {
  font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
}
.leaflet-popup-content h4 { margin: 4px 0; font-size: 14px; }
.leaflet-popup-content .pcoord { font-family: var(--mono); font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.leaflet-popup-content .pactions { display: flex; gap: 6px; }
.leaflet-popup-content .pactions button {
  flex: 1; padding: 4px 8px; font-size: 11px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-family: inherit;
}
.leaflet-popup-content .pactions button.danger { background: var(--error); color: white; border-color: var(--error); }

/* ---------- Selection list ---------- */
.selected-list { list-style: none; padding: 0; margin: 0; max-height: 180px; overflow-y: auto; }
.selected-list li {
  display: flex; align-items: center; gap: 8px; padding: 6px;
  border-radius: 4px; font-size: 12px; cursor: pointer;
}
.selected-list li:hover { background: var(--bg); }
.selected-list li.muted { color: var(--text-muted); font-style: italic; cursor: default; }
.selected-list li.muted:hover { background: transparent; }
.selected-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-list .rm { border: none; background: transparent; cursor: pointer; color: var(--text-muted); font-size: 16px; padding: 0 4px; }

/* ---------- Results ---------- */
.results .summary { background: var(--primary-faint); padding: 10px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.results-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 12px 0 8px; }
.results-section table { width: 100%; border-collapse: collapse; font-size: 12px; }
.results-section th, .results-section td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.results-section th { font-weight: 600; color: var(--text-muted); background: var(--surface-2); }
.results-section td.num, .results-section th { font-variant-numeric: tabular-nums; }
.results-section td.num { text-align: right; font-family: var(--mono); }

/* ---------- Drawer (detail / edit) ---------- */
.drawer {
  position: fixed;
  top: var(--appbar-h);
  right: 0; bottom: 0;
  width: min(440px, 100vw);
  z-index: 1200;
  display: flex;
  pointer-events: none;
}
.drawer[hidden] { display: none; }
.drawer:not([hidden]) { pointer-events: auto; }
.drawer-card {
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.drawer-card > header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 10px;
}
.drawer-card > header > div:first-child { flex: 1; min-width: 0; }
.drawer-card .ptype { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; display: block; }
.drawer-card h3 { margin: 4px 0 2px; font-size: 16px; }
.drawer-card .pcoord { font-size: 11px; color: var(--text-muted); }

.drawer-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin-bottom: 16px;
}
.form-grid label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--text-muted); font-weight: 500;
}
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { font-size: 13px; padding: 7px 9px; }

.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--primary-faint);
  border-radius: var(--rad);
}
.calc { display: flex; flex-direction: column; }
.calc-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.calc-val { font-size: 15px; font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; font-family: var(--mono); }

.photos-section { margin-bottom: 16px; }
.ps-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ps-head label { font-size: 12px; font-weight: 500; color: var(--text-muted); margin: 0; }
.photo-btn { position: relative; overflow: hidden; cursor: pointer; }
.photo-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
  min-height: 40px;
}
.photo-grid:empty::after {
  content: "No photos yet — tap “Take / pick” to add some.";
  display: block;
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.drawer-actions { display: flex; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.drawer-actions .btn { flex: 1; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1300; padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: var(--rad-lg);
  width: 100%; max-width: 460px; max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-card.wide { max-width: 640px; }
.modal-card .modal-body label.full { grid-column: 1 / -1; }
.modal-card .modal-body .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.modal-card .modal-body .form-grid label.full { grid-column: 1 / -1; }
.modal-card .modal-body .form-grid label { margin-bottom: 0; }
.section-head {
  margin: 14px 0 6px; padding: 0 2px 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.row-delete { color: #b91c1c; font-weight: 700; cursor: pointer; padding: 0 6px; border: 0; background: transparent; }
.row-delete:hover { color: #fff; background: #b91c1c; border-radius: 4px; }
.park-marker-pin {
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 11px;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  background: var(--park-color, #15803d);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
@media (max-width: 600px) {
  .modal-card .modal-body .form-grid { grid-template-columns: 1fr; }
}
.modal-card > header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-card > header h3 { margin: 0; font-size: 15px; }
.modal-card .modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-card .modal-body label { display: block; margin-bottom: 10px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.modal-card .modal-body label input { margin-top: 4px; }
.modal-card > footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.color-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.color-row input[type="color"] { width: 40px; height: 36px; padding: 2px; border-radius: 6px; cursor: pointer; flex-shrink: 0; }
.swatch-grid { display: grid; grid-template-columns: repeat(8, 22px); gap: 4px; }
.swatch-grid .sw {
  width: 22px; height: 22px; border-radius: 4px; cursor: pointer;
  border: 2px solid transparent;
}
.swatch-grid .sw.active { border-color: var(--text); }
.preview-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 12px; background: var(--bg); border-radius: 6px; }
.plabel { font-size: 11px; color: var(--text-muted); }
.preview { width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; }

.nt-list {
  max-height: 200px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2);
}
.nt-row {
  display: grid;
  grid-template-columns: 1fr 80px 60px 80px 28px;
  gap: 6px; padding: 6px 8px;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.nt-row:last-child { border-bottom: none; }
.nt-row.head { background: var(--bg); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-size: 10px; }
.nt-row .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.nt-row button { padding: 2px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: white;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13px; box-shadow: var(--shadow-md);
  z-index: 1400;
}

/* ---------- Table view ---------- */
.table-toolbar {
  padding: 10px 14px;
  display: flex; gap: 10px; flex-wrap: wrap;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tt-left { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.tt-left input, .tt-left select { padding: 6px 10px; font-size: 12px; min-width: 140px; }
.tt-right { display: flex; gap: 8px; align-items: center; }
.table-scroll { flex: 1; overflow: auto; background: var(--surface-2); }

#datatable { width: 100%; border-collapse: collapse; font-size: 12px; }
#datatable thead { position: sticky; top: 0; background: var(--surface); z-index: 5; }
#datatable th {
  padding: 8px 10px;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  text-align: left;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  background: var(--surface);
}
#datatable th:hover { color: var(--text); }
#datatable th.sorted-asc::after { content: " ↑"; color: var(--primary); }
#datatable th.sorted-desc::after { content: " ↓"; color: var(--primary); }
#datatable td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  vertical-align: middle;
  background: white;
  white-space: nowrap;
}
#datatable tbody tr:hover td { background: var(--primary-faint); }
#datatable tbody tr.selected td { background: rgba(1,105,111,.12); }
#datatable td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); color: var(--text); }
#datatable td.calc { background: var(--bg) !important; color: var(--text-muted); font-style: italic; }
#datatable td input, #datatable td select, #datatable td textarea {
  border: none; background: transparent;
  width: 100%;
  padding: 4px 4px;
  font-size: 12px;
  font-family: inherit;
  min-width: 60px;
}
/* Wider columns for park name and asset type so full names are visible without truncation */
#datatable th[data-col="park_id"],
#datatable td[data-col="park_id"],
#datatable th[data-col="name"],
#datatable td[data-col="name"],
#datatable th[data-col="asset_type"],
#datatable td[data-col="asset_type"] {
  min-width: 240px;
}
#datatable td[data-col="park_id"] select,
#datatable td[data-col="asset_type"] select {
  min-width: 220px;
}
#datatable td input:focus, #datatable td select:focus {
  background: white; box-shadow: 0 0 0 2px var(--primary);
  border-radius: 3px;
}
#datatable td.cond-1 { background: #FDECEC; }
#datatable td.cond-2 { background: #FFF4E5; }
#datatable td.cond-3 { background: #FFFCEC; }
#datatable td.cond-4 { background: #ECF7E5; }
#datatable td.photo-cell { text-align: center; font-size: 14px; cursor: pointer; }
#datatable td.row-actions { text-align: center; }
#datatable td.row-actions button {
  padding: 2px 6px; font-size: 11px; border: 1px solid var(--border);
  background: var(--surface); border-radius: 3px; cursor: pointer;
}

/* ---------- Full-screen photo viewer ---------- */
.photo-viewer {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 1500;
  display: flex; align-items: center; justify-content: center;
}
.photo-viewer[hidden] { display: none; }
.photo-viewer img { max-width: 95vw; max-height: 92vh; object-fit: contain; }
.photo-viewer .close { position: absolute; top: 16px; right: 16px; color: white; font-size: 28px; }
.photo-viewer .delete { position: absolute; top: 16px; right: 60px; color: white; font-size: 20px; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  #appbar { padding: 0 10px; gap: 8px; }
  .brand h1 { font-size: 13px; }
  .brand .subtitle { display: none; }
  #hamburger { display: inline-block; }
  #sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: 320px; max-width: 88vw;
    z-index: 800;
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open #sidebar { transform: translateX(0); }
  body.sidebar-open #sidebar-toggle { display: none; }
  body.sidebar-collapsed #sidebar { display: flex; }
  .sidebar-toggle { display: none; }
  .drawer { width: 100vw; top: var(--appbar-h); }
  .form-grid { grid-template-columns: 1fr; }
  .calc-grid { grid-template-columns: 1fr 1fr; }
  .table-toolbar .tt-left { width: 100%; }
  .table-toolbar .tt-left input, .table-toolbar .tt-left select { min-width: 0; flex: 1; }
}
