/* ── KPI Cards ── */
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card:hover {
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}

.kpi-card.hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--brand-yellow);
}

.kpi-card.alert::before { background: var(--danger); }

.kpi-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.kpi-trend.up { color: var(--success); background: var(--success-bg); }
.kpi-trend.down { color: var(--danger); background: var(--danger-bg); }
.kpi-trend.neutral { color: var(--text-secondary); background: var(--bg-base); }

.kpi-value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.kpi-card.compact .kpi-value { font-size: var(--text-xl); }

.kpi-sparkline {
  margin: var(--space-3) 0 var(--space-2);
  height: 32px;
}

.kpi-sparkline svg { width: 100%; height: 100%; }

.kpi-footer {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* ── Panel / Card ── */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.panel-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.panel-subtitle {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 2px;
}

.panel-actions {
  display: flex;
  gap: var(--space-2);
}

.panel-actions--charts {
  align-items: center;
}

.btn.btn-sm.btn-icon.chart-clear-filter {
  width: auto;
  height: auto;
  min-width: 0;
  padding: var(--space-1) var(--space-2);
  line-height: 1;
}

.chart-clear-filter svg {
  width: 15px;
  height: 15px;
  min-width: 15px;
  max-width: none;
  flex-shrink: 0;
}

.panel-body { padding: var(--space-5); }
.panel-body.no-pad { padding: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: all var(--transition);
}

.btn-ghost {
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
}

.btn-ghost:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn.chart-clear-filter {
  display: none;
  color: var(--text-secondary);
}

.btn.chart-clear-filter.is-visible {
  display: inline-flex;
}

.btn.chart-clear-filter.is-visible:hover {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border-default));
  background: color-mix(in srgb, var(--danger) 8%, var(--bg-surface));
}

.btn-primary {
  background: var(--brand-yellow);
  color: var(--brand-dark);
  border: 1px solid var(--brand-yellow);
}

.btn-primary:hover {
  background: var(--brand-yellow-hover);
  border-color: var(--brand-yellow-hover);
}

.btn-primary:focus-visible {
  box-shadow: var(--focus-ring);
}

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }

/* ── Data Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table thead { position: sticky; top: 0; z-index: 1; }

.data-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.data-table th:hover { color: var(--text-secondary); }
.data-table th.sorted { color: var(--text-primary); }

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-surface-hover); }

.data-table .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }

/* ── Chart container ── */
.chart-container {
  position: relative;
  height: 280px;
}

/* ── Mobile overlay ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 199;
}

@media (max-width: 767px) {
  .sidebar-backdrop.visible { display: block; }
}

/* ── Segment panel (dashboard filters) ── */
.segment-panel {
  margin-bottom: var(--space-6);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
}

.segment-panel.segment-collapsible {
  padding: 0;
  overflow: hidden;
}

.segment-collapsible-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  transition: background var(--transition);
}

.segment-collapsible-trigger:hover {
  background: var(--bg-surface-hover);
}

.segment-collapsible-icon {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.segment-collapsible.has-active-filters .segment-collapsible-icon {
  color: var(--brand-yellow);
}

.segment-collapsible-title {
  font-size: var(--text-sm);
  font-weight: 700;
}

.segment-collapsible-summary {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

.segment-collapsible.has-active-filters .segment-collapsible-summary {
  color: var(--text-secondary);
}

.segment-collapsible-chevron {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
  transition: transform var(--transition);
}

.segment-collapsible.is-open .segment-collapsible-chevron {
  transform: rotate(180deg);
}

.segment-collapsible-body {
  display: none;
  border-top: 1px solid var(--border-default);
}

.segment-collapsible.is-open .segment-collapsible-body {
  display: block;
}

.segment-panel-body {
  padding: var(--space-4);
}

.segment-bar-inner {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr)) auto;
  gap: var(--space-3);
  align-items: end;
}

.segment-reset {
  white-space: nowrap;
  align-self: end;
  height: 36px;
  border: 1px dashed var(--border-strong);
  color: var(--text-primary);
  background: var(--bg-input);
}

.segment-reset:hover {
  border-color: var(--brand-yellow);
  color: var(--text-primary);
  background: var(--accent-subtle);
}

.segment-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.segment-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  line-height: 1;
}

.segment-field select {
  width: 100%;
  appearance: none;
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23524f4d' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color-scheme: light;
}

.segment-field select option {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 500;
}

.segment-field select option:checked {
  background-color: var(--brand-dark);
  color: var(--brand-yellow);
}

.segment-field select:hover {
  border-color: var(--border-strong);
}

.segment-field select:focus {
  outline: none;
  border-color: var(--brand-yellow);
  box-shadow: var(--focus-ring);
}

.segment-field.is-active select {
  border-color: var(--brand-yellow);
  background-color: var(--accent-subtle);
}

[data-theme="dark"] .segment-field select {
  background-color: var(--bg-input);
  color: var(--text-primary);
  color-scheme: dark;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23c8c4bc' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

[data-theme="dark"] .segment-field select option {
  background-color: #2e2c2a;
  color: #f5f2ec;
}

[data-theme="dark"] .segment-field select option:checked {
  background-color: #524f4d;
  color: var(--brand-yellow);
}

[data-theme="dark"] .segment-field.is-active select {
  background-color: rgba(250, 225, 0, 0.08);
}

@media (max-width: 1100px) {
  .segment-bar-inner {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .segment-reset {
    grid-column: 1 / -1;
    justify-self: start;
  }
}

@media (max-width: 640px) {
  .segment-bar-inner {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ── Performance card ── */
.performance-body {
  display: flex;
  gap: var(--space-5);
  align-items: center;
}

.performance-ring-wrap {
  position: relative;
  flex-shrink: 0;
  width: 100px;
  height: 100px;
}

.performance-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.performance-ring-value { font-size: var(--text-xl); font-weight: 800; line-height: 1; }
.performance-ring-sub { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 2px; }

.performance-list { flex: 1; display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.performance-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.performance-row-label { font-size: var(--text-sm); font-weight: 600; }
.performance-row-pct { font-size: var(--text-sm); font-weight: 700; }
.performance-bar-wrap { height: 6px; background: var(--bg-base); border-radius: var(--radius-full); overflow: hidden; }
.performance-bar { height: 100%; border-radius: var(--radius-full); transition: width 500ms ease; }
.performance-row-meta { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 4px; }

.performance-card.panel { height: 100%; margin: 0; }

/* ── Heatmap ── */
:root {
  --heatmap-0: #eceae4;
  --heatmap-1: rgba(250, 225, 0, 0.38);
  --heatmap-2: rgba(250, 225, 0, 0.62);
  --heatmap-3: #FAE100;
  --heatmap-lote-col: 44px;
  --heatmap-total-col: 44px;
  --heatmap-cell-height: 22px;
  --heatmap-week-min: 14px;
}

[data-theme="dark"] {
  --heatmap-0: #333130;
  --heatmap-1: rgba(250, 225, 0, 0.38);
  --heatmap-2: rgba(250, 225, 0, 0.68);
  --heatmap-3: #FAE100;
}

#harvestHeatmap {
  width: 100%;
}

.heatmap-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-bottom: var(--space-3);
}

.heatmap-legend {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
}

.heatmap-legend-label {
  font-weight: 600;
  color: var(--text-primary);
  margin-right: var(--space-1);
}

.heatmap-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.heatmap-legend-item i {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border-default);
}

.heatmap-scroll {
  width: 100%;
  overflow-x: auto;
  padding-bottom: var(--space-1);
  padding-right: var(--space-1);
  -webkit-overflow-scrolling: touch;
}

.heatmap-grid {
  display: grid;
  width: 100%;
  gap: 2px;
  grid-template-columns:
    var(--heatmap-lote-col)
    repeat(var(--heatmap-weeks, 12), minmax(var(--heatmap-week-min), 1fr))
    6px
    var(--heatmap-total-col);
  grid-auto-rows: var(--heatmap-cell-height);
  font-size: var(--text-xs);
}

.heatmap-corner,
.heatmap-col-head,
.heatmap-row-head {
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  height: var(--heatmap-cell-height);
}

.heatmap-cell,
.heatmap-total {
  box-sizing: border-box;
  width: 100%;
  height: var(--heatmap-cell-height);
  justify-self: stretch;
  align-self: center;
}

.heatmap-corner {
  justify-content: flex-start;
  padding-left: var(--space-2);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.heatmap-row-head {
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 11px;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-surface);
}

.heatmap-col-head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}

.heatmap-col-total {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--bg-surface);
  font-size: 10px;
  font-weight: 800;
  color: var(--brand-yellow);
  letter-spacing: 0.06em;
}

.heatmap-col-sep {
  pointer-events: none;
}

.heatmap-cell {
  border: 1px solid transparent;
  border-radius: 4px;
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 10px;
  cursor: pointer;
  transition: transform 100ms, box-shadow 100ms;
  color: var(--brand-dark);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.heatmap-cell:hover { transform: scale(1.04); box-shadow: var(--shadow-1); z-index: 1; }
.heatmap-cell.heat-0 {
  background: var(--heatmap-0);
  color: transparent;
  border-color: var(--border-default);
}
.heatmap-cell.heat-1 {
  background: var(--heatmap-1);
  color: var(--brand-dark);
}
.heatmap-cell.heat-2 {
  background: var(--heatmap-2);
  color: var(--brand-dark);
}
.heatmap-cell.heat-3 { background: var(--heatmap-3); }

.heatmap-total {
  display: flex;
  align-items: center;
  justify-content: center;
  position: sticky;
  right: 0;
  z-index: 2;
  font-weight: 800;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--brand-dark);
  color: var(--brand-yellow);
  border: 1px solid rgba(250, 225, 0, 0.35);
  border-left: 3px solid var(--brand-yellow);
  border-radius: 4px;
  box-shadow: -4px 0 8px rgba(0, 0, 0, 0.12);
}

.heatmap-panel-body {
  padding: var(--space-4) var(--space-3);
}

.heatmap-empty {
  text-align: center;
  padding: var(--space-8);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}

.heatmap-cell.is-selected {
  outline: 2px solid var(--brand-yellow);
  outline-offset: 2px;
}

.heatmap-popover {
  position: fixed;
  z-index: 500;
  min-width: 240px;
  max-width: 320px;
  padding: var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
}

.heatmap-popover-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.heatmap-popover-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
}

.heatmap-popover-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.heatmap-popover-close {
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
}
.heatmap-popover-close:hover { color: var(--text-primary); }

.heatmap-popover-dates {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.heatmap-popover-dates li {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.heatmap-popover-empty {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* ── Collapsible zones ── */
.section-collapsible { cursor: pointer; user-select: none; }
.section-toggle {
  border: none;
  background: var(--bg-base);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.section-collapsible.open .section-toggle { transform: rotate(0deg); }
.section-collapsible:not(.open) .section-toggle { transform: rotate(-90deg); }

.collapsible-zone {
  display: none;
}
.collapsible-zone.open {
  display: block;
  animation: fadeIn 250ms ease;
}

@media (max-width: 767px) {
  .performance-body { flex-direction: column; align-items: stretch; }
}

/* ── Data source banner ── */
.data-source-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-6);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-subtle);
}
.data-source-banner.demo {
  background: #fef9c3;
  color: #713f12;
}
[data-theme="dark"] .data-source-banner.demo {
  background: #422006;
  color: #fde68a;
}
.data-source-banner.live {
  background: #ecfdf5;
  color: #065f46;
}
[data-theme="dark"] .data-source-banner.live {
  background: #052e16;
  color: #6ee7b7;
}
.data-source-icon { font-weight: 700; flex-shrink: 0; }
.data-source-text { flex: 1; min-width: 0; }
.data-source-banner .btn { margin-left: auto; flex-shrink: 0; }
.data-source-dismiss {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  margin-left: auto;
}
.data-source-dismiss:hover { opacity: 1; background: rgba(0, 0, 0, 0.08); }
[data-theme="dark"] .data-source-dismiss:hover { background: rgba(255, 255, 255, 0.1); }
.data-source-banner[hidden] { display: none !important; }

/* ── Upload wizard ── */
.upload-zone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
  color: var(--text-secondary);
}
.upload-zone:hover,
.upload-zone.drag {
  border-color: var(--brand-yellow);
  background: var(--brand-yellow-soft, rgba(250, 225, 0, 0.08));
}
.upload-zone svg { margin: 0 auto var(--space-3); opacity: 0.75; color: var(--text-secondary); }
.upload-zone p { margin: 0 0 var(--space-1); color: var(--text-primary); }
.upload-hint { font-size: var(--text-xs); color: var(--text-secondary); }
.upload-zone--compact { padding: var(--space-5); }

.upload-status {
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  min-height: 1.25rem;
}
.upload-status--ok { color: var(--status-ok, #16a34a); }
.upload-status--error { color: var(--status-err, #dc2626); }
.upload-status--loading { color: var(--text-secondary); }

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.import-preview-panel {
  margin-top: var(--space-4);
  display: none;
}
.import-preview-panel.visible { display: block; }

.import-preview-panel .import-preview-scroll {
  max-height: min(50vh, 480px);
  overflow: hidden;
}

.import-preview-panel .maestro-table-wrap {
  max-height: min(50vh, 480px);
  overflow: auto;
}

.import-progress {
  margin-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.import-progress[hidden] { display: none !important; }
.import-progress-track {
  height: 4px;
  background: var(--border-subtle);
  border-radius: 99px;
  overflow: hidden;
}
.import-progress-fill {
  height: 100%;
  width: 0;
  background: var(--brand-yellow);
  border-radius: 99px;
  transition: width 200ms ease;
}
.import-progress-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.import-summary {
  margin-top: var(--space-3);
  display: none;
}
.import-summary.visible { display: block; }
.import-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3);
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.import-summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--text-sm);
}
.import-summary-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.import-summary-warn {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  color: var(--status-warn, #b45309);
}

.upload-empty {
  padding: var(--space-6);
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.upload-meta {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ── Maestro (estructura agrícola) ── */
.maestro-page-header {
  flex-wrap: wrap;
  gap: var(--space-3);
}

#cosechaFiltersShell[hidden] {
  display: none;
}

.jabas-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.jabas-summary-item {
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.jabas-summary-item.jabas-summary-span {
  grid-column: 1 / -1;
}

.jabas-summary-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: var(--space-1);
}

.jabas-summary-item strong {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text-primary);
}

#view-cosecha-jabas .maestro-table-shell {
  max-height: min(62vh, 640px);
  overflow: hidden;
}

#view-cosecha-jabas .maestro-table-wrap {
  max-height: min(62vh, 640px);
  overflow: auto;
}

#view-cosecha-jabas .maestro-table th.code,
#view-cosecha-jabas .maestro-table td.code {
  font-family: var(--font-mono, var(--font-ui));
  font-variant-numeric: tabular-nums;
}

#view-cosecha-jabas .maestro-table th.date,
#view-cosecha-jabas .maestro-table td.date {
  min-width: max-content;
}

.maestro-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.maestro-search {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  min-width: 11rem;
  box-sizing: border-box;
}

.maestro-search input {
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-xs);
  line-height: 1.25;
  color: var(--text-primary);
  width: 9rem;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

.maestro-search input::-webkit-search-cancel-button,
.maestro-search input::-webkit-search-decoration,
.maestro-search input::-webkit-search-results-button {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.maestro-search input::-ms-clear {
  display: none;
}

.maestro-search-clear {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  padding: 0;
  margin: 0;
  cursor: pointer;
  line-height: 1;
  transition: color var(--transition);
}

.maestro-search-clear.is-visible {
  display: inline-flex;
}

.maestro-search-clear:hover {
  color: var(--text-primary);
}

.maestro-search-clear:focus-visible {
  outline: 2px solid var(--brand-yellow);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.maestro-search input::placeholder {
  color: var(--text-tertiary);
}

.maestro-status {
  margin: var(--space-3) var(--space-4) 0;
}

.maestro-status[hidden] {
  display: none !important;
}

.maestro-table-shell {
  width: 100%;
  max-height: calc(100vh - 280px);
  min-height: 0;
  overflow: hidden;
}

.maestro-table-wrap {
  width: 100%;
  max-height: calc(100vh - 280px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: auto;
  scrollbar-color: var(--brand-dark-3) transparent;
  box-sizing: border-box;
}

.maestro-panel .panel-body.no-pad {
  padding: var(--space-4);
}

/* Scroll horizontal + vertical en body (vertical visible al borde derecho) */
.maestro-table-wrap::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.maestro-table-wrap::-webkit-scrollbar:vertical {
  width: 12px;
}

.maestro-table-wrap::-webkit-scrollbar:horizontal {
  height: 12px;
}

.maestro-table-wrap::-webkit-scrollbar-corner {
  background: transparent;
}

.maestro-table-wrap::-webkit-scrollbar-track:vertical,
.maestro-table-wrap::-webkit-scrollbar-track:horizontal {
  background: transparent;
  box-shadow: none;
}

.maestro-table-wrap::-webkit-scrollbar-thumb {
  background: var(--brand-dark-3);
  border-radius: var(--radius-full);
  min-width: 48px;
  min-height: 48px;
}

.maestro-table-wrap::-webkit-scrollbar-thumb:vertical,
.maestro-table-wrap::-webkit-scrollbar-thumb:horizontal {
  border: 2px solid transparent;
  background-clip: padding-box;
}

.maestro-table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--brand-dark-2);
}

.maestro-table-wrap::-webkit-scrollbar-thumb:active {
  background: var(--brand-dark);
}

.maestro-table-wrap::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

[data-theme="dark"] .maestro-table-wrap {
  scrollbar-color: var(--text-tertiary) transparent;
}

[data-theme="dark"] .maestro-table-wrap::-webkit-scrollbar-corner {
  background: transparent;
}

[data-theme="dark"] .maestro-table-wrap::-webkit-scrollbar-track:vertical,
[data-theme="dark"] .maestro-table-wrap::-webkit-scrollbar-track:horizontal {
  background: transparent;
  box-shadow: none;
}

[data-theme="dark"] .maestro-table-wrap::-webkit-scrollbar-thumb:vertical,
[data-theme="dark"] .maestro-table-wrap::-webkit-scrollbar-thumb:horizontal {
  background: var(--text-tertiary);
  border-color: transparent;
}

[data-theme="dark"] .maestro-table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

[data-theme="dark"] .maestro-table-wrap::-webkit-scrollbar-thumb:active {
  background: var(--brand-cream);
}

.maestro-table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

.maestro-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.maestro-table th,
.maestro-table td {
  white-space: nowrap;
  width: max-content;
  min-width: max-content;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  font-family: var(--font-ui);
}

.maestro-table td {
  font-size: var(--text-sm);
}

.maestro-table th {
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-inverse);
  background: var(--brand-dark);
  border-bottom: none;
  cursor: default;
}

.maestro-table th:hover {
  color: var(--text-inverse);
}

.maestro-table th.num {
  color: var(--text-inverse);
}

[data-theme="dark"] .maestro-table th {
  background: var(--brand-dark-2);
  box-shadow: inset 0 -2px 0 var(--brand-yellow);
}

.maestro-table td.num,
.maestro-table th.num {
  font-family: var(--font-ui);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.maestro-table.maestro-table--fitted {
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
}

.maestro-table.maestro-table--fitted th,
.maestro-table.maestro-table--fitted td {
  width: auto;
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
}

.maestro-empty-cell {
  text-align: center;
  padding: var(--space-8) var(--space-4) !important;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.upload-zone--maestro {
  border-color: color-mix(in srgb, var(--brand-yellow) 40%, var(--border-default));
  background: var(--accent-subtle);
}

.upload-zone--maestro:hover,
.upload-zone--maestro.drag {
  border-color: var(--brand-yellow);
  background: color-mix(in srgb, var(--brand-yellow) 12%, var(--bg-surface));
}

.upload-zone--maestro svg {
  color: var(--brand-yellow);
  opacity: 1;
}

.maestro-import-dialog {
  max-width: 720px;
}

.maestro-preview-wrap {
  max-height: 220px;
  overflow: auto;
}

.maestro-import-footer {
  justify-content: space-between;
  align-items: center;
}

.maestro-import-footer-actions {
  display: flex;
  gap: var(--space-2);
}

.maestro-modal-cancel {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}

.maestro-modal-cancel:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: min(22rem, calc(100vw - var(--space-8)));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--brand-yellow);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-3);
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: 1.4;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 220ms ease, transform 220ms ease;
  pointer-events: auto;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast--leaving {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
}

.toast--error {
  border-left-color: var(--danger);
}

.toast--loading {
  border-left-color: var(--border-strong);
}

.toast--info {
  border-left-color: var(--brand-yellow);
}

.toast-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  color: var(--brand-yellow);
}

.toast--error .toast-icon {
  color: var(--danger);
}

.toast--loading .toast-icon {
  color: var(--text-secondary);
}

.toast-message {
  flex: 1;
  min-width: 0;
}

.toast-close {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  margin: -2px -2px 0 0;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--transition), color var(--transition);
}

.toast-close:hover {
  opacity: 1;
  color: var(--text-primary);
}

.toast-spinner {
  display: block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-default);
  border-top-color: var(--brand-yellow);
  border-radius: 50%;
  animation: toast-spin 0.7s linear infinite;
}

@keyframes toast-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: var(--space-4);
    max-width: none;
  }
}

.config-cultivo-card {
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}
.config-cultivo-card h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-base);
}
.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.config-grid label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.config-grid input {
  padding: var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
}
.config-grid input:focus {
  outline: none;
  border-color: var(--brand-yellow);
  box-shadow: var(--focus-ring);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 200ms ease, visibility 200ms ease;
}

[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, 0.65);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

body.modal-open {
  overflow: hidden;
}

.modal-dialog {
  width: min(100%, 560px);
  max-height: min(90vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  transform: translateY(12px) scale(0.98);
  transition: transform 200ms ease;
}

.modal-overlay.open .modal-dialog {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.modal-subtitle {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.modal-close:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-4) var(--space-5);
  overflow-y: auto;
}

.modal-body .config-cultivo-card:last-child {
  margin-bottom: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) var(--space-5);
  border-top: 1px solid var(--border-subtle);
}

@media (max-width: 640px) {
  .header-params-btn span {
    display: none;
  }

  .modal-body .config-grid {
    grid-template-columns: 1fr;
  }
}

.sheets-api-row input {
  flex: 1;
  padding: var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  background: var(--bg-input);
  color: var(--text-primary);
}
.sheets-api-row input:focus {
  outline: none;
  border-color: var(--brand-yellow);
  box-shadow: var(--focus-ring);
}

/* ── Google Sheets sync ── */
.sheets-badge {
  display: inline-block;
  font-size: var(--text-xs);
  padding: 2px 8px;
  border-radius: var(--radius-full, 999px);
  font-weight: 600;
}
.sheets-badge.connected { background: #ecfdf5; color: #065f46; }
.sheets-badge.offline { background: var(--bg-input); color: var(--text-secondary); border: 1px solid var(--border-default); }
[data-theme="dark"] .sheets-badge.connected { background: rgba(74, 222, 128, 0.14); color: #86efac; }
[data-theme="dark"] .sheets-badge.offline { background: var(--bg-input); color: var(--text-secondary); }
.sheets-api-field { display: block; margin-bottom: var(--space-4); }
.sheets-api-field span { font-size: var(--text-xs); color: var(--text-secondary); display: block; margin-bottom: var(--space-1); }
.sheets-api-row { display: flex; gap: var(--space-2); }
.sheets-sync-grid { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }

/* ── Auth / sistema (admin) ── */
body:not(.auth-ready) [data-admin-only] {
  display: none !important;
}

.is-admin-hidden,
[data-admin-only][hidden] {
  display: none !important;
}

.sys-config-section {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.sys-config-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.sys-config-heading {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-3);
}

.sys-remember {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  margin-bottom: var(--space-2);
}

.sys-remember input {
  accent-color: var(--brand-yellow);
}

.config-modal-footer {
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.config-modal-footer-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
