:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --ink: #18211f;
  --muted: #65716d;
  --line: #d9e0dd;
  --green: #207a57;
  --red: #b73535;
  --amber: #b46f12;
  --blue: #276a9f;
  --violet: #7559a4;
  --shadow: 0 14px 35px rgba(18, 31, 26, 0.12);
}

body.dark-mode {
  --bg: #111715;
  --panel: #18211f;
  --ink: #edf3ef;
  --muted: #a5b4ae;
  --line: #31403b;
  --green: #55b987;
  --red: #f07f7f;
  --amber: #f0b35b;
  --blue: #71afe2;
  --violet: #b49ae1;
  --shadow: 0 14px 35px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.brand,
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 14px;
}

.brand h1,
.section-header h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.icon-button,
.icon-button:visited,
.tab,
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
}

body.dark-mode .icon-button,
body.dark-mode .tab,
body.dark-mode .primary-button,
body.dark-mode .secondary-button,
body.dark-mode .filters input,
body.dark-mode .filters select,
body.dark-mode .detail-panel input,
body.dark-mode .detail-panel select,
body.dark-mode .detail-panel textarea {
  background: #202b28;
  border-color: var(--line);
  color: var(--ink);
}

.icon-button {
  width: 40px;
  padding: 0;
}

.icon-button svg,
.tab svg,
.primary-button svg,
.secondary-button svg {
  width: 18px;
  height: 18px;
}

.primary-button {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  padding: 0 14px;
  font-weight: 700;
}

.secondary-button {
  padding: 0 12px;
  color: var(--green);
  font-weight: 700;
  text-decoration: none;
}

.brand-actions,
.map-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0 14px 14px;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 8px;
  background: #fbfcfb;
}

body.dark-mode .metric,
body.dark-mode .field,
body.dark-mode .photo-box,
body.dark-mode .order-card,
body.dark-mode .summary-block {
  background: #1d2825;
}

.metric span {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.metric.critical span { color: var(--red); }
.metric.pending span { color: var(--amber); }
.metric.done span { color: var(--green); }
.metric.total span { color: var(--blue); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 14px 14px;
}

.tab {
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.tab.active {
  border-color: #b9cec6;
  background: #eaf3ef;
  color: var(--green);
}

body.dark-mode .tab.active {
  background: #263b33;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 14px 14px;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filters .search {
  grid-column: 1 / -1;
}

.filters span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filters input,
.filters select,
.detail-panel input,
.detail-panel select,
.detail-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
}

.list-panel {
  overflow: auto;
  padding: 0 10px 14px;
}

.bench-row {
  width: 100%;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 9px 8px;
  text-align: left;
}

.bench-row:hover,
.bench-row.active {
  border-color: var(--line);
  background: #f7faf8;
}

body.dark-mode .bench-row:hover,
body.dark-mode .bench-row.active,
body.dark-mode .bench-id,
body.dark-mode .bench-thumb {
  background: #22302c;
}

.bench-id {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 34px;
  border-radius: 8px;
  background: #eef2f0;
  font-size: 12px;
  font-weight: 800;
}

.bench-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 44px;
  overflow: hidden;
  border-radius: 8px;
  background: #eef2f0;
}

.bench-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bench-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.bench-row small {
  color: var(--muted);
  font-size: 12px;
}

.priority-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.priority-pill.critica { background: #ffe9e9; color: var(--red); }
.priority-pill.alta { background: #fff0d7; color: var(--amber); }
.priority-pill.media { background: #eaf3ff; color: var(--blue); }
.priority-pill.baja { background: #eee9f6; color: var(--violet); }
.priority-pill.sin-actuacion { background: #eaf3ef; color: var(--green); }

.workspace {
  min-width: 0;
  min-height: 100vh;
}

.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: block;
}

#mapView {
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
  min-height: 100vh;
}

.map-tools {
  position: absolute;
  left: 18px;
  top: 18px;
  z-index: 500;
}

.detail-panel {
  position: absolute;
  top: 18px;
  right: 18px;
  width: min(420px, calc(100vw - 430px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
  z-index: 520;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 180px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 32px;
  height: 32px;
}

.detail-body {
  padding: 18px;
}

.detail-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.detail-title h2 {
  margin: 0;
  font-size: 24px;
}

.detail-title p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.field small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.field strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}

.order-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.order-form label {
  display: grid;
  gap: 5px;
}

.order-form span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.photo-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.photo-box {
  display: grid;
  place-items: center;
  position: relative;
  min-height: 120px;
  border: 1px dashed #bdc8c3;
  border-radius: 8px;
  overflow: hidden;
  background: #f7faf8;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
}

.photo-box img {
  width: 100%;
  height: 160px;
  object-fit: cover;
}

.photo-link strong {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(24, 33, 31, 0.82);
  color: #fff;
  font-size: 12px;
}

.photo-link strong svg {
  width: 15px;
  height: 15px;
}

.photo-link.disabled {
  pointer-events: none;
}

.map-popup {
  display: grid;
  gap: 6px;
  width: 190px;
}

.map-popup img {
  width: 190px;
  height: 130px;
  border-radius: 6px;
  object-fit: cover;
}

.map-popup strong,
.map-popup span {
  display: block;
}

.orders-view,
.summary-view {
  padding: 0 22px 26px;
  background: #f8faf8;
}

.orders-grid,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.order-card,
.summary-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.order-card h3,
.summary-block h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.order-card p {
  margin: 6px 0;
  color: var(--muted);
  font-size: 13px;
}

.order-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.wide {
  grid-column: 1 / -1;
}

.bars {
  display: grid;
  gap: 10px;
}

.two-col {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.bar-row {
  display: grid;
  grid-template-columns: 150px 1fr 42px;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #edf1ef;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.leaflet-marker-icon.marker-dot {
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    max-height: 54vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace,
  .view,
  #map {
    min-height: 76vh;
  }

  #map {
    position: relative;
    height: 76vh;
  }

  .map-tools {
    left: 10px;
    top: 10px;
  }

  .detail-panel {
    position: relative;
    top: auto;
    right: auto;
    width: auto;
    max-height: none;
    margin: 10px;
  }

  .dashboard {
    grid-template-columns: repeat(2, 1fr);
  }
}

body.mobile-version .app-shell {
  grid-template-columns: 1fr;
}

body.mobile-version .sidebar {
  min-height: auto;
  max-height: none;
  border-right: 0;
  border-bottom: 1px solid var(--line);
}

body.mobile-version .workspace,
body.mobile-version .view,
body.mobile-version #map {
  min-height: 78vh;
}

body.mobile-version #map {
  position: relative;
  height: 78vh;
}

body.mobile-version .detail-panel {
  position: relative;
  top: auto;
  right: auto;
  width: auto;
  max-height: none;
  margin: 10px;
}

body.mobile-version .dashboard {
  grid-template-columns: repeat(2, 1fr);
}

body.mobile-version .filters,
body.mobile-version .field-grid,
body.mobile-version .photo-row {
  grid-template-columns: 1fr;
}

body.mobile-version .tabs {
  grid-template-columns: 1fr;
}

body.mobile-version .brand h1,
body.mobile-version .section-header h2 {
  font-size: 23px;
}

@media (max-width: 520px) {
  .filters,
  .field-grid,
  .photo-row {
    grid-template-columns: 1fr;
  }

  .tabs {
    grid-template-columns: 1fr;
  }

  .brand h1,
  .section-header h2 {
    font-size: 23px;
  }
}
