* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: #1a1a1a; color: #e8e8e8; min-height: 100vh; padding: 1.5rem; }
.app-header { position: relative; margin-bottom: 1rem; }
.header-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 18px; font-weight: 500; color: #f0f0f0; padding: 0.4rem 0 0.5rem; }
.bg-picker { display: flex; gap: 6px; align-items: center; }
.bg-swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0; flex-shrink: 0;
  box-shadow: 0 0 0 1px #555;
  transition: box-shadow 0.15s;
}
.bg-swatch:hover { box-shadow: 0 0 0 2px #1D9E75; }
.bg-swatch.active { box-shadow: 0 0 0 2px #1D9E75, 0 0 0 4px #0a6b4a; }

/* Background themes */
body.bg-fondo1 { background: #1a1a1a url('../fondos/fondo1.jpg') center/cover fixed; }
body.bg-fondo2 { background: #1a1a1a url('../fondos/fondo2.jpg') center/cover fixed; }

body.bg-fondo1 .page.active,
body.bg-fondo2 .page.active {
  background: rgba(10, 10, 10, 0.72);
  border-radius: 10px;
  padding: 1rem;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

/* ── TAB NAV ── */
.page-tabs {
  display: flex; gap: 0; margin-bottom: 1.2rem;
  border-bottom: 1px solid #444;
}
.page-tabs button {
  border: none; border-radius: 0; background: none;
  color: #888; padding: 7px 22px; font-size: 14px; font-weight: 400;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  cursor: pointer;
}
.page-tabs button:hover { color: #e8e8e8; background: none; }
.page-tabs button.active { color: #e8e8e8; border-bottom-color: #1D9E75; font-weight: 500; }
.page { display: none; }
.page.active { display: block; }
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  background: #2a2a2a; border: 0.5px solid #444; border-radius: 8px;
}
.toolbar label { font-size: 13px; color: #aaa; white-space: nowrap; }
.toolbar input[type=range] { width: 80px; accent-color: #1D9E75; }
.toolbar span { font-size: 13px; font-weight: 500; min-width: 28px; color: #e8e8e8; }
button {
  font-size: 13px; padding: 5px 14px; border-radius: 8px;
  border: 0.5px solid #555; background: #2a2a2a; color: #e8e8e8; cursor: pointer; white-space: nowrap;
}
button:hover { background: #333; }
button.primary { background: #1D9E75; color: #fff; border-color: #0F6E56; font-weight: 500; }
button.primary:hover { background: #0F6E56; }
button.primary:disabled { background: #555; border-color: #444; cursor: not-allowed; }
button.active-tool { background: #8B1A1A; color: #fff; border-color: #5a1010; }
button.danger { border-color: #c0392b; color: #e74c3c; }
button.danger:hover { background: #2a1515; }
.sep { width: 1px; height: 24px; background: #444; flex-shrink: 0; }
/* ── MEASURE PAGE: HORIZONTAL LAYOUT ── */
.editor-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.editor-left {
  flex: 1;
  min-width: 0;
}
.editor-right {
  width: 340px;
  flex-shrink: 0;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}
.editor-resize-handle {
  width: 8px;
  flex-shrink: 0;
  cursor: col-resize;
  border-radius: 4px;
  background: transparent;
  transition: background 0.15s;
  align-self: stretch;
  position: relative;
}
.editor-resize-handle::after {
  content: '';
  position: absolute;
  inset: 0 2px;
  border-radius: 4px;
  background: transparent;
  transition: background 0.15s;
}
.editor-resize-handle:hover::after,
.editor-resize-handle.dragging::after {
  background: #555;
}

#canvas-outer {
  overflow: hidden; border: 0.5px solid #444; border-radius: 8px; background: #111;
  width: 100%; cursor: crosshair;
  max-height: 900px;
  resize: vertical;
}
#canvas-outer.ctrl-zoom { cursor: zoom-in; }
#canvas-outer.ctrl-pan  { cursor: grab; }
#canvas-outer.ctrl-panning { cursor: grabbing; }
#canvas-wrap {
  position: relative; display: inline-block;
  transform-origin: 0 0;
}
canvas { display: block; }
#overlay { position: absolute; top: 0; left: 0; pointer-events: none; }
#status { font-size: 13px; color: #aaa; margin-top: 8px; min-height: 18px; }
#roots-table-wrap {
  display: none;
}
#roots-table-wrap .tbl-label {
  font-size: 13px; font-weight: 500; color: #e8e8e8; margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
table#roots-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
#roots-table th {
  text-align: left; padding: 5px 10px; color: #888;
  border-bottom: 0.5px solid #444; font-weight: 400;
}
#roots-table td { padding: 4px 8px; border-bottom: 0.5px solid #2a2a2a; }
#roots-table tr.root-row td { border-bottom: 0.5px solid #333; }
#roots-table tr.root-row:last-child td { border-bottom: none; }
#roots-table tr.root-row, #roots-table tr.lateral-row { cursor: pointer; }
#roots-table tr.row-highlighted td { background: #1a2e26; }
#roots-table tr.root-row.row-highlighted td { background: #1a2e26; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; }
/* Tree indentation */
.tree-indent {
  display: inline-flex; align-items: center; gap: 4px;
  padding-left: 6px;
}
.tree-branch {
  display: inline-block; width: 18px; flex-shrink: 0;
  border-left: 1.5px solid #444; border-bottom: 1.5px solid #444;
  height: 10px; margin-bottom: -4px; border-radius: 0 0 0 3px;
}
tr.lateral-row td { background: rgba(255,255,255,0.04); font-size: 12px; }
tr.lateral-row td:first-child { padding-left: 0; }
tr.add-lateral-row td { background: transparent; padding: 3px 8px 3px 0; }
.expand-btn {
  background: none; border: none; color: #666; cursor: pointer;
  padding: 0 4px; font-size: 11px; line-height: 1;
}
.expand-btn:hover { color: #aaa; background: none; }
.add-lateral-btn {
  background: none; border: 1px dashed #444; color: #888;
  border-radius: 5px; font-size: 11px; padding: 2px 8px;
  cursor: pointer; margin-left: 28px;
}
.add-lateral-btn:hover { border-color: #1D9E75; color: #1D9E75; background: none; }
.add-lateral-btn.add-lateral-active { border-color: #e74c3c; border-style: solid; color: #e74c3c; }
.add-lateral-btn.add-lateral-active:hover { background: #2a1515; }

/* ── CATEGORY SELECTOR ── */
.cat-select-wrap { display: flex; align-items: center; gap: 8px; }
.cat-select-wrap select {
  background: #222; border: 0.5px solid #555; color: #e8e8e8;
  border-radius: 6px; padding: 4px 8px; font-size: 13px; cursor: pointer;
}
.cat-select-wrap select:focus { outline: none; border-color: #1D9E75; }
.cat-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}

/* ── DATA PAGE ── */
#data-page { padding-top: 4px; }
.data-toolbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap;
}
.data-filter-area { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.data-filter-row {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: #aaa;
}
.data-filter-row select,
.data-filter-row input[type=number] {
  background: #2a2a2a; border: 1px solid #444; color: #e8e8e8;
  border-radius: 4px; padding: 3px 6px; font-size: 13px;
}
.data-filter-row input[type=number] { width: 72px; }
.data-section { margin-bottom: 24px; }
.data-section-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
  padding-bottom: 6px; border-bottom: 0.5px solid #444;
}
.data-section-header .cat-name-input {
  background: transparent; border: none; color: #f0f0f0;
  font-size: 15px; font-weight: 500; cursor: text; padding: 2px 4px;
  border-radius: 4px; min-width: 60px; max-width: 220px;
}
.data-section-header .cat-name-input:hover { background: #2a2a2a; }
.data-section-header .cat-name-input:focus { background: #2a2a2a; outline: 1px solid #1D9E75; }
.data-section-header input[type=color] {
  width: 26px; height: 26px; padding: 0; border: none;
  border-radius: 50%; cursor: pointer; background: none;
  flex-shrink: 0;
}
.data-section-header .cat-count { font-size: 12px; color: #555; }
.data-section-header .delete-cat-btn {
  margin-left: auto; padding: 2px 8px; font-size: 11px;
}
table.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data-table th {
  text-align: left; padding: 4px 10px; color: #888;
  border-bottom: 0.5px solid #444; font-weight: 400; white-space: nowrap;
}
table.data-table td { padding: 4px 10px; border-bottom: 0.5px solid #222; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr.lat-data-row td { background: rgba(255,255,255,0.04); font-size: 12px; color: #bbb; }
.data-empty { color: #555; font-size: 13px; font-style: italic; padding: 8px 0; }
.export-csv-btn { font-size: 12px; padding: 4px 12px; }


#upload-area {
  padding: 2.5rem; text-align: center;
  border: 1.5px dashed #555; border-radius: 12px; cursor: pointer;
  color: #aaa; font-size: 14px; background: #222; transition: background 0.15s;
}
#upload-area:hover { background: #2a2a2a; border-color: #1D9E75; }
#upload-area .hint { font-size: 12px; color: #555; margin-top: 6px; display: block; }
a.download-btn {
  display: inline-block; font-size: 13px; padding: 5px 14px;
  border-radius: 8px; border: 0.5px solid #1D9E75; color: #1D9E75;
  text-decoration: none; background: transparent;
}
a.download-btn:hover { background: #0f2e25; }

/* ── PHOTOS PAGE ── */
#photos-page { padding-top: 4px; }
.photos-toolbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.photos-toolbar select {
  background: #222; border: 0.5px solid #555; color: #e8e8e8;
  border-radius: 6px; padding: 5px 10px; font-size: 13px; cursor: pointer;
}
.photos-toolbar select:focus { outline: none; border-color: #1D9E75; }

/* Folders sidebar + gallery layout */
.photos-layout {
  display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: start;
}
.folders-panel {
  background: #222; border: 0.5px solid #3a3a3a; border-radius: 8px;
  padding: 10px 0; min-height: 120px;
}
.folders-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 8px; border-bottom: 0.5px solid #333; margin-bottom: 4px;
}
.folders-panel-header span { font-size: 12px; color: #888; font-weight: 500; }
.folders-panel-header button { padding: 2px 8px; font-size: 11px; }
.folder-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; color: #ccc;
  border-left: 2px solid transparent; user-select: none;
}
.folder-item:hover { background: #2a2a2a; color: #e8e8e8; }
.folder-item.active { background: #1a2e26; color: #1D9E75; border-left-color: #1D9E75; }
.folder-item .folder-count { margin-left: auto; font-size: 11px; color: #555; }
.folder-item .folder-delete {
  display: none; margin-left: 4px; background: none; border: none;
  color: #c0392b; cursor: pointer; padding: 0 2px; font-size: 12px; line-height: 1;
}
.folder-item:hover .folder-delete { display: inline; }

/* Photo grid */
.photos-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px;
}
.photo-card {
  background: #222; border: 0.5px solid #333; border-radius: 8px;
  overflow: hidden; cursor: pointer; transition: border-color 0.15s;
  display: flex; flex-direction: column;
}
.photo-card:hover { border-color: #1D9E75; }
.photo-card-img-wrap {
  width: 100%; padding-bottom: 75%; position: relative; overflow: hidden; background: #111;
}
.photo-card-img-wrap img {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.photo-card-info {
  padding: 8px 10px; flex: 1; display: flex; flex-direction: column; gap: 3px;
}
.photo-card-name {
  font-size: 12px; font-weight: 500; color: #e8e8e8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.photo-card-meta { font-size: 11px; color: #666; }
.photo-card-actions {
  display: flex; gap: 6px; padding: 0 10px 8px; flex-wrap: wrap;
}
.photo-card-actions button { font-size: 11px; padding: 3px 8px; flex: 1; }
.photos-empty {
  color: #555; font-size: 13px; font-style: italic; padding: 32px 0; text-align: center;
  grid-column: 1 / -1;
}
.photo-measured-tick {
  position: absolute; bottom: 36px; right: 6px;
  background: #1D9E75; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* Sort bar */
.sort-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 12px; color: #666;
}
.sort-bar button {
  font-size: 11px; padding: 3px 10px;
  border: 0.5px solid #444; background: #222; color: #888;
}
.sort-bar button.active { border-color: #1D9E75; color: #1D9E75; background: #1a2e26; }

/* Photo detail modal */
.photo-modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
.photo-modal {
  background: #222; border: 0.5px solid #444; border-radius: 12px;
  max-width: 520px; width: 100%; padding: 20px; display: flex; flex-direction: column; gap: 14px;
}
.photo-modal h3 { font-size: 15px; font-weight: 500; color: #f0f0f0; }
.photo-modal img { width: 100%; border-radius: 6px; max-height: 280px; object-fit: contain; background: #111; }
.photo-modal-fields { display: flex; flex-direction: column; gap: 10px; }
.photo-modal-fields label { font-size: 12px; color: #888; display: flex; flex-direction: column; gap: 4px; }
.photo-modal-fields input[type=text],
.photo-modal-fields select {
  background: #2a2a2a; border: 0.5px solid #555; color: #e8e8e8;
  border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.photo-modal-fields input:focus, .photo-modal-fields select:focus {
  outline: none; border-color: #1D9E75;
}
.photo-modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Scale banner — sits above the canvas, never blocks clicks on it */
#scale-banner {
  display: none;
  background: #2a2a2a; border: 0.5px solid #555; border-radius: 8px;
  padding: 14px 18px; margin-bottom: 10px;
}
#scale-banner h2 { font-size: 14px; font-weight: 500; margin-bottom: 6px; color: #f0f0f0; }
#scale-banner p  { font-size: 13px; color: #aaa; margin-bottom: 10px; line-height: 1.5; }
#scale-banner .btns { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#px-per-cm-display { font-size: 12px; color: #1D9E75; margin-bottom: 8px; min-height: 16px; }
#mark-instructions { font-size: 12px; color: #f0a500; margin-bottom: 8px; display: none; line-height: 1.5; }
