/* ================================
   CHERRY COUNTING · Estilos
   ================================ */

:root {
  --bg: #F5F1E8;
  --surface: #FFFFFF;
  --surface-2: #FBF8F0;
  --border: #E5DFD0;
  --border-strong: #C9C0A8;

  --text: #1A1F14;
  --text-muted: #6B6B6B;

  --primary: #2D3F1E;
  --primary-soft: #4A5F33;
  --primary-tint: #E8EBE2;

  --accent: #C7522A;
  --accent-soft: #E68961;
  --accent-tint: #FBE5DA;

  --danger: #B23A30;

  --shadow-sm: 0 1px 2px rgba(26, 31, 20, 0.06);
  --shadow: 0 1px 3px rgba(26, 31, 20, 0.08), 0 4px 12px rgba(26, 31, 20, 0.04);
  --shadow-lg: 0 4px 20px rgba(26, 31, 20, 0.12);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;

  --header-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

/* =========== HEADER =========== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  position: relative;
  z-index: 10;
}

.app-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.app-logo {
  height: 32px;
  width: auto;
  flex-shrink: 0;
  filter: brightness(0) saturate(100%) invert(17%) sepia(15%) saturate(1893%) hue-rotate(56deg) brightness(95%) contrast(91%);
}

.app-logo[hidden] { display: none; }

#app-title {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.btn-back, .btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 40px;
  height: 40px;
  font-size: 20px;
  color: var(--text);
  display: grid;
  place-items: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.btn-back:hover, .btn-icon:hover { background: var(--surface-2); }
.btn-back[hidden] { display: none; }

/* =========== MAIN / VIEWS =========== */
.app-main {
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow-y: auto;
  position: relative;
}

.view {
  padding: 24px 18px 110px;
  min-height: 100%;
  animation: fade-in 0.2s ease;
}

.view.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header { margin-bottom: 22px; }

.view-title {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -0.025em;
  color: var(--primary);
  line-height: 1.1;
}

.view-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 6px;
}

/* =========== LISTS =========== */
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}

.list-item:active { transform: scale(0.99); }
.list-item:hover {
  border-color: var(--primary-soft);
  box-shadow: var(--shadow-sm);
}

.list-item-content { flex: 1; min-width: 0; }
.list-item-title {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

.list-item-meta .variedad-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary-tint);
  color: var(--primary);
  font-weight: 600;
  font-size: 11px;
  margin-right: 4px;
}

.list-item-action {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 22px;
  line-height: 1;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.list-item-action:hover { color: var(--danger); background: var(--accent-tint); }

.list-empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-muted);
  font-style: italic;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
}

/* =========== BUTTONS =========== */
.btn-primary, .btn-accent, .btn-secondary, .btn-ghost {
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  padding: 14px 22px;
  border: 1px solid transparent;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, opacity 0.15s;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary { background: var(--primary); color: var(--bg); }
.btn-primary:hover { background: var(--primary-soft); }

.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-soft); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--primary-soft); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-primary:active, .btn-accent:active,
.btn-secondary:active, .btn-ghost:active { transform: scale(0.98); }

.btn-primary:disabled, .btn-accent:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-large { padding: 18px 22px; font-size: 17px; }

.action-stack { display: flex; flex-direction: column; gap: 10px; }

.btn-fab {
  position: fixed;
  bottom: 20px;
  left: 18px;
  right: 18px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 5;
  transition: transform 0.08s;
}
.btn-fab:active { transform: scale(0.98); }

/* =========== MAP =========== */
#view-map { padding: 0; }

.map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  height: 46px;
}

.map-status { color: var(--text-muted); }
.map-counter { font-weight: 600; color: var(--primary); }

.map {
  height: calc(100vh - var(--header-h) - 46px - 132px);
  height: calc(100dvh - var(--header-h) - 46px - 132px);
  width: 100%;
  background: var(--surface-2);
}

.map-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.map-actions button {
  padding: 12px 10px;
  font-size: 14px;
  width: 100%;
}

/* =========== COUNTER =========== */
.counter-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
}

.tab {
  background: transparent;
  border: none;
  padding: 12px 8px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: all 0.15s;
  touch-action: manipulation;
}

.tab small {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}

.tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.counter-display {
  text-align: center;
  margin: 24px 0 16px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.counter-number {
  display: block;
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-size: 96px;
  font-weight: 500;
  color: var(--primary);
  line-height: 1;
  letter-spacing: -0.04em;
  cursor: pointer;
  user-select: none;
  padding: 0 16px;
  border-radius: 12px;
  transition: background 0.15s;
}

.counter-number:active {
  background: var(--primary-tint);
}

.counter-number.hidden { display: none; }

.counter-input {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-size: 96px;
  font-weight: 500;
  color: var(--primary);
  line-height: 1;
  letter-spacing: -0.04em;
  text-align: center;
  width: 280px;
  max-width: 100%;
  border: none;
  background: var(--surface-2);
  outline: 2px solid var(--primary);
  border-radius: 12px;
  padding: 4px 12px;
  -moz-appearance: textfield;
  appearance: textfield;
}

.counter-input::-webkit-outer-spin-button,
.counter-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.counter-input.hidden { display: none; }

.counter-label {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.counter-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 20px 0 22px;
}

.btn-counter {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-size: 56px;
  font-weight: 500;
  height: 110px;
  border-radius: var(--radius);
  border: none;
  transition: transform 0.08s, background 0.15s;
  touch-action: manipulation;
}

.btn-minus {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-minus:hover { background: var(--surface-2); }

.btn-plus {
  background: var(--primary);
  color: var(--bg);
}
.btn-plus:hover { background: var(--primary-soft); }

.btn-counter:active { transform: scale(0.96); }

.counter-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 14px 0 18px;
  overflow: hidden;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  font-size: 14px;
  gap: 12px;
}

.info-row + .info-row {
  border-top: 1px solid var(--border);
}

.meta-label {
  color: var(--text-muted);
  font-size: 13px;
}

.meta-value {
  font-weight: 600;
  color: var(--text);
  text-align: right;
  word-break: break-word;
}

.info-edit {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.info-edit-icon {
  font-size: 12px;
  opacity: 0.6;
}

.info-edit:active { opacity: 0.6; }

/* =========== RECORDS =========== */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.filters select {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
}

.filters .btn-ghost {
  width: auto;
  padding: 11px 16px;
  font-size: 14px;
  white-space: nowrap;
}

.records-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.records-table th {
  text-align: left;
  padding: 12px 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}

.records-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.records-table tr:last-child td { border-bottom: none; }

.records-table .col-cuartel {
  font-weight: 600;
  color: var(--text);
}

.records-table .col-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

.tipo-badge {
  display: inline-block;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  white-space: nowrap;
}
.tipo-badge.dardos { color: var(--primary); background: var(--primary-tint); }
.tipo-badge.frutos { color: var(--accent); background: var(--accent-tint); }

.btn-row-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 18px;
  line-height: 1;
  border-radius: 6px;
}
.btn-row-delete:hover { color: var(--danger); background: var(--accent-tint); }

/* =========== PRODUCCIÓN ===========  */
.prod-total {
  background: var(--primary);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: center;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.prod-total-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  opacity: 0.75;
  margin-bottom: 6px;
}

.prod-total-value {
  display: block;
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-weight: 600;
  font-size: 44px;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.prod-section-title {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-weight: 600;
  font-size: 18px;
  color: var(--primary);
  margin: 24px 0 12px;
  letter-spacing: -0.01em;
}

.prod-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prod-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.prod-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.prod-card-title {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-weight: 600;
  font-size: 20px;
  color: var(--primary);
}

.prod-card-kg {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  white-space: nowrap;
}

.prod-card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.prod-card-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.prod-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.prod-row-label { color: var(--text-muted); }
.prod-row-value { font-weight: 600; }

.prod-card-constants {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
}

.prod-constants-edit {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--primary);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.prod-constants-edit:hover { background: var(--primary-tint); }

.prod-cuartel-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  gap: 10px;
}

.prod-cuartel-info { min-width: 0; flex: 1; }
.prod-cuartel-name { font-weight: 600; color: var(--text); }
.prod-cuartel-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.prod-cuartel-kg { font-weight: 700; color: var(--accent); white-space: nowrap; }

/* =========== MODAL =========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(26, 31, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  animation: fade-in 0.18s ease;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144;
  font-weight: 600;
  font-size: 22px;
  color: var(--primary);
  margin-bottom: 6px;
}

.modal-body {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-fields:empty { display: none; margin: 0; }

.modal-field { display: flex; flex-direction: column; gap: 6px; }

.modal-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.modal-input, .modal-select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.modal-input:focus, .modal-select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button { flex: 1; padding: 12px; }

/* =========== TOAST =========== */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  max-width: calc(100% - 40px);
  text-align: center;
  animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.hidden { display: none; }
.toast.error { background: var(--danger); color: white; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* =========== LEAFLET OVERRIDES =========== */
.leaflet-container {
  font-family: 'DM Sans', sans-serif !important;
  background: #1a1a1a;
}

.leaflet-bar a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-bottom-color: var(--border) !important;
}

.leaflet-tooltip {
  background: var(--primary);
  color: var(--bg);
  border: none;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.leaflet-tooltip-top:before { border-top-color: var(--primary); }

.leaflet-control-layers {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-layers-toggle {
  width: 40px !important;
  height: 40px !important;
  background-size: 22px 22px !important;
}

.leaflet-control-layers-expanded {
  padding: 12px 14px !important;
  font-family: 'DM Sans', sans-serif !important;
  font-size: 14px !important;
  color: var(--text) !important;
  min-width: 130px;
}

.leaflet-control-layers-list label {
  padding: 5px 0 !important;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.leaflet-control-layers-separator {
  border-top: 1px solid var(--border) !important;
  margin: 8px 0 !important;
}

/* =========== SAFE AREA =========== */
@supports (padding: env(safe-area-inset-top)) {
  .app-header { padding-top: max(12px, env(safe-area-inset-top)); height: auto; min-height: var(--header-h); }
  .btn-fab { bottom: max(20px, env(safe-area-inset-bottom)); }
}

@media (max-width: 360px) {
  #app-title { font-size: 19px; }
  .app-logo { height: 28px; }
  .counter-number, .counter-input { font-size: 80px; }
  .prod-total-value { font-size: 38px; }
}
