:root {
  --ink: #17211c;
  --muted: #5d6b64;
  --paper: #f4efe6;
  --card: #fffdf8;
  --line: #d9d0c2;
  --sage: #2f5d4a;
  --sage-soft: #e4efe8;
  --gold: #c4a15a;
  --alert: #c43b32;
  --alert-soft: #f8d9d6;
  --alert-cell: #f4b8b2;
  --ok: #2a7a55;
  --wait: #b86b1a;
  --shadow: 0 18px 50px rgba(23, 33, 28, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Outfit", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #e7f0e8 0%, transparent 50%),
    var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto auto;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 20px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 86%, white);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--sage);
  color: #f6f1e4;
  font-family: "Fraunces", serif;
  font-weight: 650;
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  border-radius: 9px;
  flex-shrink: 0;
}
.brand-title {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.08;
}
.brand-title span { display: block; }

.tabs { display: flex; gap: 6px; background: #efe8db; padding: 4px; border-radius: 999px; }
.tab {
  border: 0; background: transparent;
  padding: 6px 14px; border-radius: 999px;
  font: inherit; color: var(--muted); cursor: pointer;
}
.tab.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 0 var(--line); }

.top-controls { position: relative; display: flex; align-items: center; justify-content: flex-end; }
.perfil-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 560;
  cursor: pointer;
}
.perfil-btn:hover, .perfil-btn.on { border-color: var(--sage); color: var(--sage); }
.perfil-btn-badge,
.perfil-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--alert);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 650;
  line-height: 1;
}
.perfil-btn-badge[hidden],
.perfil-badge[hidden] { display: none; }
.perfil-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(280px, calc(100vw - 32px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
  display: grid;
  gap: 12px;
  z-index: 30;
}
.perfil-panel.mod-open { width: min(480px, calc(100vw - 32px)); }
.perfil-tabs { width: 100%; flex-wrap: wrap; }
.perfil-tabs .seg-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
#perfilCuenta { display: grid; gap: 12px; }
#perfilCuenta[hidden],
#perfilMod[hidden],
#perfilAcceso[hidden],
#perfilTabs[hidden],
#perfilHeading.perfil-heading-hide { display: none; }
.access-list { display: grid; gap: 10px; max-height: min(60vh, 480px); overflow: auto; }
.access-card {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf6ee;
}
.access-card b { font-size: 0.9rem; font-weight: 560; }
.access-card > span { font-size: 0.74rem; color: var(--muted); word-break: break-all; }
.access-flags { display: grid; gap: 6px; margin-top: 8px; }
.access-flags > div { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.access-flags .tog { font-size: 0.8rem; }
.access-card.access-fail { box-shadow: inset 0 0 0 1px var(--alert); }
.tog.locked { opacity: 0.65; }
.mod-list { display: grid; gap: 14px; max-height: min(60vh, 420px); overflow: auto; }
.mod-group { display: grid; gap: 8px; }
.mod-group > span { font-size: 0.78rem; color: var(--muted); }
.mod-item {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf6ee;
  font-size: 0.88rem;
}
.mod-item b { font-weight: 560; }
.mod-actions { display: flex; gap: 6px; }
.mod-actions button {
  border: 0;
  background: var(--sage-soft);
  color: var(--sage);
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 560;
  cursor: pointer;
}
.mod-actions button[data-crop-reject],
.mod-actions button[data-pest-reject],
.mod-actions button[data-sup-reject] {
  background: var(--alert-soft);
  color: var(--alert);
}
.mod-empty { margin: 0; color: var(--muted); font-size: 0.86rem; }
.perfil-panel[hidden] { display: none; }
.perfil-panel h3 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 1.05rem;
}
.perfil-block { display: grid; gap: 8px; }
.perfil-block > span { font-size: 0.82rem; color: var(--muted); }
.seg { display: flex; background: #efe8db; border-radius: 999px; padding: 3px; }
.seg-btn {
  border: 0; background: transparent; min-width: 42px;
  padding: 6px 10px; border-radius: 999px; cursor: pointer; font: inherit;
}
.seg-btn.on { background: var(--sage); color: #f6f1e4; }
.tog { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; user-select: none; }
.tog.slim { font-size: 0.84rem; }
.tog input { accent-color: var(--sage); width: 16px; height: 16px; }

.toolbar { padding: 10px 20px 0; display: grid; gap: 10px; }
.search-wrap { min-width: 0; }
.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}
.search-wrap input:focus { border-color: var(--sage); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  max-width: 220px;
}
#fTipo { max-width: 86px; width: 86px; }
.view-seg { margin-right: 6px; }

.stats-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 28px 0;
}
.stats { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.stats[hidden] { display: none; }
.add-use-stat {
  margin-left: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 0.88rem;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 5px 9px;
  min-width: 72px;
}
.stat b { display: block; font-family: "Fraunces", serif; font-size: 0.98rem; line-height: 1.15; }
.stat span { color: var(--muted); font-size: 0.68rem; }
.stat.alert {
  background: var(--alert-soft);
  border-color: #e7b3ae;
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: inherit;
}
.stat.alert b { color: var(--alert); }
.stat.alert:hover, .stat.alert.on { box-shadow: inset 0 0 0 2px var(--alert); }
.stat.pais {
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: inherit;
}
.stat.pais:hover { box-shadow: inset 0 0 0 2px var(--sage); }
.stat.pais.on {
  background: var(--sage-soft);
  border-color: var(--sage);
  box-shadow: inset 0 0 0 2px var(--sage);
}
.stat.pais.on b { color: var(--sage); }
.stat.ok, .stat.wait {
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: inherit;
}
.stat.ok:hover { box-shadow: inset 0 0 0 2px var(--ok); }
.stat.ok.on {
  background: #dcefe4;
  border-color: var(--ok);
  box-shadow: inset 0 0 0 2px var(--ok);
}
.stat.ok.on b { color: var(--ok); }
.stat.wait:hover { box-shadow: inset 0 0 0 2px var(--wait); }
.stat.wait.on {
  background: #f7e6cf;
  border-color: var(--wait);
  box-shadow: inset 0 0 0 2px var(--wait);
}
.stat.wait.on b { color: var(--wait); }
#fEstado { display: none; }
.estado-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 28px 0;
}
.estado-details[hidden] { display: none; }
.estado-details .detail-label {
  color: var(--muted);
  font-size: 0.78rem;
  margin-right: 4px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--ink);
}
.chip b { font-family: "Fraunces", serif; }
.chip:hover { border-color: var(--wait); }
.chip.on {
  background: #f7e6cf;
  border-color: var(--wait);
  box-shadow: inset 0 0 0 1px var(--wait);
}
main {
  flex: 1;
  min-height: 0;
  padding: 10px 20px 12px;
  display: flex;
  flex-direction: column;
}
.table-wrap {
  flex: 1;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 9px 11px; text-align: left; border-bottom: 1px solid #eee6d8; vertical-align: top; }
th {
  position: sticky; top: 0; z-index: 2;
  background: #faf6ee;
  font-weight: 560;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
th.sortable { padding: 0; white-space: nowrap; }
th.col-dv, td.col-dv { min-width: 240px; width: 18%; }
th.col-dv { white-space: normal; }
th.col-dv .sort-btn { white-space: normal; }
.admin-row td.col-dv input { min-width: 220px; }
th.sortable[aria-sort="ascending"],
th.sortable[aria-sort="descending"] { color: var(--sage); }
.sort-btn {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 9px 11px;
  font: inherit;
  font-weight: 560;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.sort-btn:hover { color: var(--ink); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f3ea; }
.sci { font-style: italic; color: #3f5349; font-size: 0.84em; }
.muted { color: var(--muted); }
.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 560;
  background: var(--sage-soft);
  color: var(--sage);
  white-space: nowrap;
}
.pill.st-registrada, .pill.st-vigente { background: #dcefe4; color: var(--ok); }
.pill.st-pendiente, .pill.st-enproceso, .pill.st-maestro, .pill.st-plan { background: #f7e6cf; color: var(--wait); }
.pill.st-cancelada, .pill.st-vacio { background: var(--alert-soft); color: var(--alert); }
.pill.st-entransferencia { background: #f3e4c8; color: #8a5a12; }
.pill.rac { background: #e8e4f4; color: #43357a; }
.flag-row { background: var(--alert-soft) !important; }
.flag-cell { background: var(--alert-cell) !important; }
.pending-cell { background: #d4e6f8 !important; }
.pending-cell input,
.pending-cell input[readonly],
.pending-cell input:disabled {
  background: #e4f0fb !important;
}
.admin-row input,
.admin-row select {
  width: 100%;
  min-width: 86px;
  border: 1px solid #e4d9c8;
  background: #fff;
  border-radius: 8px;
  padding: 6px 7px;
  font: inherit;
  font-size: 0.84rem;
}
.admin-row input:disabled,
.admin-row input[readonly] {
  background: #f4efe6;
  color: var(--ink);
}
.combo-search {
  flex-shrink: 0;
  width: calc(100% - 8px);
  margin: 6px 4px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.84rem;
}
.combo-menu {
  position: fixed;
  z-index: 70;
  display: flex;
  flex-direction: column;
  max-height: 280px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(23, 33, 28, 0.16);
}
.combo-menu[hidden] { display: none; }
.combo-list {
  overflow: auto;
  max-height: 220px;
  padding: 4px;
}
.combo-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  color: var(--ink);
}
.combo-item:hover,
.combo-item.on { background: var(--sage-soft); }
.combo-item.pending { background: #e4f0fb; }
.combo-item.pending.on,
.combo-item.pending:hover { background: #d4e6f8; }
.combo-new {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  color: var(--sage);
  font-weight: 560;
}
.pending-chip.pending-pest,
.pending-chip.pending-sup {
  background: #e4f0fb;
  border-color: #9bb8d4;
}
.sup-block { margin-top: 18px; }
.sup-block > b {
  display: block;
  color: var(--muted);
  font-weight: 460;
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.sup-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sup-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  border-radius: 999px;
  background: #efe8db;
  font-size: 0.8rem;
}
.sup-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0 2px;
}
.sup-x:hover { color: var(--alert); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.ghost {
  border: 1px solid var(--line);
  background: #efe8db;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}
.sup-chip.pending { background: #d4e6f8; }
#supSearch {
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  color: var(--ink);
}
.combo-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.82rem;
}
.pending-chip button {
  margin-left: 6px;
  border: 0;
  background: #efe8db;
  border-radius: 999px;
  padding: 2px 8px;
  font: inherit;
  font-size: 0.74rem;
  cursor: pointer;
}
.drawer-inner.crop-modal {
  width: min(420px, 100%);
  left: 50%;
  right: auto;
  top: 12vh;
  bottom: auto;
  height: auto;
  transform: translateX(-50%);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(23, 33, 28, 0.16);
}
.field { display: grid; gap: 6px; margin: 14px 0; font-size: 0.86rem; color: var(--muted); }
.field input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
}
.primary {
  border: 0;
  background: var(--sage);
  color: #f6f1e4;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}
.hint { color: var(--muted); font-size: 0.85rem; padding: 10px 4px 0; }

.drawer {
  position: fixed; inset: 0;
  background: rgba(23, 33, 28, 0.28);
  z-index: 40;
}
#cropModal, #pestModal, #supModal, #supRemoveModal, #useModal { z-index: 55; }
.table-actions { display: none; }
.drawer-inner.use-modal { width: min(560px, 100%); max-height: 86vh; }
.use-modal .seg { margin: 12px 0 4px; }
.ai-block { margin: 14px 0; }
.ai-head {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.ai-row {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
  margin-bottom: 8px;
}
.ai-row input, .ai-conc {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  width: 100%;
  box-sizing: border-box;
}
.field select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
.add-use-btn {
  margin-top: 12px;
  border: 1px dashed var(--line);
  background: #f7f3ea;
  color: var(--sage);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}
.drawer-inner {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(640px, 100%);
  background: var(--card);
  padding: 28px;
  overflow: auto;
  box-shadow: -20px 0 50px rgba(23,33,28,0.12);
}
.close {
  position: absolute; top: 12px; right: 14px;
  border: 0; background: #efe8db; width: 36px; height: 36px;
  border-radius: 50%; font-size: 1.3rem; cursor: pointer;
}
.drawer h2 { font-family: "Fraunces", serif; margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin-top: 16px; font-size: 0.9rem; }
.kv b { color: var(--muted); font-weight: 460; }
.uses {
  width: 100%;
  margin-top: 18px;
  font-size: 0.84rem;
}
.uses th { position: static; }
.uses tr.on { background: var(--sage-soft); }

#reviewOnlyWrap { display: flex; }
body:not(.admin-mode) #reviewOnlyWrap,
body:not(.admin-mode) #statReview { display: none; }
body.usos-mode .table-wrap { overflow-x: hidden; }
body.usos-mode table {
  table-layout: fixed;
  font-size: 0.8rem;
}
body.usos-mode th,
body.usos-mode td {
  padding: 5px 4px;
  vertical-align: middle;
  overflow-wrap: anywhere;
}
body.usos-mode th {
  font-size: 0.64rem;
  letter-spacing: 0.02em;
}
body.usos-mode th.sortable { white-space: normal; }
body.usos-mode .sort-btn {
  padding: 5px 4px;
  font-size: 0.64rem;
  white-space: normal;
}
body.usos-mode th.col-dv,
body.usos-mode td.col-dv {
  min-width: 0;
  width: 15%;
}
body.usos-mode .pill { padding: 2px 6px; font-size: 0.7rem; }
body.usos-mode table th:nth-child(1),
body.usos-mode table td:nth-child(1) { width: 5.5%; }
body.usos-mode table th:nth-child(2),
body.usos-mode table td:nth-child(2) { width: 13%; }
body.usos-mode table th:nth-child(4),
body.usos-mode table td:nth-child(4) { width: 11%; }
body.usos-mode table th:nth-child(5),
body.usos-mode table td:nth-child(5) { width: 13%; }
body.usos-mode table th:nth-child(6),
body.usos-mode table td:nth-child(6) { width: 10%; }
body.usos-mode table th:nth-child(7),
body.usos-mode table td:nth-child(7) { width: 8%; }
body.usos-mode table th:nth-child(8),
body.usos-mode table td:nth-child(8) { width: 11%; }
body.usos-mode table th:nth-child(9),
body.usos-mode table td:nth-child(9) { width: 5.5%; }
body.usos-mode table th:nth-child(10),
body.usos-mode table td:nth-child(10) { width: 8%; }
body.admin-mode .view-seg { display: none; }
body.admin-mode .table-wrap { overflow-x: hidden; }
body.admin-mode table {
  table-layout: fixed;
  font-size: 0.74rem;
}
body.admin-mode th,
body.admin-mode td {
  padding: 3px 4px;
  vertical-align: middle;
}
body.admin-mode th {
  font-size: 0.62rem;
  letter-spacing: 0.02em;
}
body.admin-mode .sort-btn {
  padding: 4px;
  font-size: 0.62rem;
}
body.admin-mode th.col-dv,
body.admin-mode td.col-dv {
  min-width: 0;
  width: 16%;
}
body.admin-mode .admin-row input,
body.admin-mode .admin-row select {
  min-width: 0;
  width: 100%;
  padding: 3px 4px;
  font-size: 0.74rem;
  border-radius: 5px;
}
body.admin-mode .admin-row td.col-dv input { min-width: 0; }
body.admin-mode .admin-row select { text-overflow: ellipsis; }
body.admin-mode table th:nth-child(6),
body.admin-mode table td:nth-child(6) { width: 8%; }
body.admin-mode table th:nth-child(7),
body.admin-mode table td:nth-child(7) { width: 9%; }
body.admin-mode table th:nth-child(9),
body.admin-mode table td:nth-child(9) { width: 9%; }

@media (max-width: 900px) {
  html, body { height: auto; }
  body { overflow: auto; }
  .top { grid-template-columns: 1fr; }
  main { flex: none; }
  .table-wrap { max-height: none; }
}

body:not(.authed) > :not(#loginGate) { display: none !important; }
body.must-change > :not(#pwGate) { display: none !important; }
#pwGate { z-index: 80; }
.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-gate[hidden] { display: none; }
.login-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 26px 24px;
}
.login-card .mark { margin-bottom: 12px; }
.login-card h2 {
  margin: 0 0 6px;
  font-family: "Fraunces", serif;
  font-size: 1.4rem;
}
.login-card .primary { width: 100%; margin-top: 8px; }
.login-card .login-resend {
  width: 100%;
  margin-top: 8px;
  background: transparent;
}
.perfil-user { display: grid; gap: 2px; }
.perfil-user b { font-size: 0.92rem; }
.perfil-user span { font-size: 0.78rem; color: var(--muted); word-break: break-all; }
.logout-btn { justify-self: start; margin-top: 4px; }
body.viewer [data-tab="admin"],
body.viewer #addUseBtn,
body.country-locked #fPais { display: none !important; }
