/* ==========================================
   LimónMDT — Prototipo 5
   Fase 0 · Fase 1 · Fase 2
   ========================================== */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --card: #1c2333;
  --border: #30363d;
  --green: #22c55e;
  --green-dark: #16a34a;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --sidebar-w: 240px;
  --radius: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* ---- LAYOUT ---- */
.app { display: flex; min-height: 100vh; }
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.page { padding: 28px; flex: 1; }

/* ---- CARD (Fase 2 fix: clase base que faltaba) ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title {
  font-size: 16px;
  font-weight: 700;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.logo-icon {
  width: 42px; height: 42px;
  background: var(--green);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.logo-text { font-weight: 800; font-size: 16px; }
.logo-sub { font-size: 11px; color: var(--text-muted); }
.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 15px;
  transition: all 0.2s;
  position: relative;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(34,197,94,0.08); color: var(--text); }
.nav-item.active {
  background: rgba(34,197,94,0.12);
  color: var(--green);
  border-left-color: var(--green);
}
.nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}
.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-avatar {
  width: 36px; height: 36px;
  background: var(--green-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 700; }
.user-role { font-size: 11px; color: var(--text-muted); }
.logout-btn {
  margin-left: auto;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.logout-btn:hover { color: var(--red); }

/* ---- TOPBAR ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left h1 { font-size: 20px; font-weight: 800; }
.topbar-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.data-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: 8px;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.data-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #93c5fd;
}
.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  font-family: inherit;
}

/* ---- UTILITY ---- */
.tc { text-align: center; }
.tr { text-align: right; }
.green { color: var(--green); }
.red { color: var(--red); }
.yellow { color: var(--yellow); }
.muted { color: var(--text-muted); }
.fw7 { font-weight: 700; }
.fw8 { font-weight: 800; }
.fw9 { font-weight: 900; }
.mb8 { margin-bottom: 8px; }
.mb12 { margin-bottom: 12px; }
.mb16 { margin-bottom: 16px; }
.mb20 { margin-bottom: 20px; }
.mb24 { margin-bottom: 24px; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.mt24 { margin-top: 24px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-c { align-items: center; }
.items-s { align-items: flex-start; }
.jbet { justify-content: space-between; }
.g8 { gap: 8px; }
.g12 { gap: 12px; }
.g16 { gap: 16px; }
.g20 { gap: 20px; }
.w100 { width: 100%; }
.flex-1 { flex: 1; }
.justify-center { justify-content: center; }
.fs11 { font-size: 11px; }
.fs12 { font-size: 12px; }
.fs13 { font-size: 13px; }
.fs14 { font-size: 14px; }
.fs16 { font-size: 16px; }
.fs18 { font-size: 18px; }
.fs20 { font-size: 20px; }
.fs22 { font-size: 22px; }
.up { color: var(--green); font-weight: 700; }
.dn { color: var(--red); font-weight: 700; }
.fl { color: var(--text-muted); font-weight: 700; }

/* ---- STAT CARD ---- */
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-card-value { font-size: 28px; font-weight: 900; }
.stat-card-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ---- PENDING ORDER ROW ---- */
.pending-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
}
.co-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}
.pending-info { flex: 1; }
.pending-name { font-weight: 700; font-size: 14px; }
.pending-meta { font-size: 12px; color: var(--text-muted); }
.pending-val { font-size: 16px; font-weight: 800; text-align: right; }
.pending-actions { display: flex; gap: 8px; }

/* ---- ORDER CARDS ---- */
.order-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}
.order-card:hover { border-color: var(--green); }
.order-card-mine { border-left: 3px solid var(--green); }
.order-card-inactive { opacity: 0.6; }
.order-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}
.order-name { font-weight: 700; font-size: 17px; }
.order-loc { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.order-stats { display: flex; gap: 28px; margin-bottom: 14px; }
.order-actions { display: flex; gap: 10px; }

/* ---- MERCADO TABS ---- */
.mercado-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border-radius: 10px;
  padding: 4px;
  border: 1px solid var(--border);
}
.mercado-tab {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
  border: none;
  background: transparent;
  font-family: inherit;
}
.mercado-tab.active { background: var(--green); color: #000; }
.mercado-tab-spacer { flex: 1; }

/* ---- FILTER CHIPS ---- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.2s;
  font-family: inherit;
}
.chip.on, .chip:hover { background: var(--green); color: #000; border-color: var(--green); }

/* ---- Fase 2: BARRA DE BÚSQUEDA + FILTROS ---- */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.search-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  font-size: 14px;
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}
.search-input:focus { outline: none; border-color: var(--green); }
.search-input::placeholder { color: var(--text-muted); }

/* ---- Fase 2: VALIDACIÓN INLINE DE CAMPOS ---- */
.field-hint {
  font-size: 12px;
  margin-top: 4px;
  padding: 3px 0;
  min-height: 18px;
  transition: color 0.2s;
}
.hint-ok    { color: var(--green); }
.hint-error { color: var(--red); }

/* ---- TABS ---- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: 8px;
  padding: 4px;
  border: 1px solid var(--border);
}
.tab {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
  border: none;
  background: transparent;
  font-family: inherit;
}
.tab.on { background: var(--green); color: #000; }

/* ---- ROLE TABS ---- */
.role-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}
.role-tab {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.role-tab.active {
  background: rgba(34,197,94,0.15);
  border-color: var(--green);
  color: var(--green);
}
.role-tab[data-role="empacadora"].active {
  background: rgba(59,130,246,0.15);
  border-color: var(--blue);
  color: var(--blue);
}

/* ---- MODE TOGGLE ---- */
.mode-toggle {
  display: flex;
  background: var(--card);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}
.mode-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.mode-btn.active { background: var(--green); color: #000; }

/* ---- DEMO HINT ---- */
.demo-hint {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
}
.demo-hint code {
  background: rgba(34,197,94,0.12);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ---- PRICE DISPLAY ---- */
.price-hero { font-size: 64px; font-weight: 900; line-height: 1; }
.price-unit { font-size: 20px; color: var(--text-muted); font-weight: 400; }

/* ---- FORECAST ---- */
.forecast-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.forecast-day {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 8px;
  text-align: center;
}
.forecast-day.today { border-color: var(--green); }
.fc-lbl { font-size: 12px; color: var(--text-muted); font-weight: 700; margin-bottom: 8px; }
.fc-icon { font-size: 28px; margin-bottom: 8px; }
.fc-max { font-size: 16px; font-weight: 800; }
.fc-min { font-size: 13px; color: var(--text-muted); }
.fc-rain { font-size: 12px; color: var(--blue); margin-top: 6px; }

/* ---- REC CARDS ---- */
.rec-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}
.rec-emoji {
  padding: 20px;
  font-size: 40px;
  background: linear-gradient(135deg, #0f2d0f, #1a4d1a);
  text-align: center;
}
.rec-body { padding: 16px; }
.rec-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.rec-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.rec-text { font-size: 13px; color: var(--text-muted); line-height: 1.6; }

/* ---- TABLE ---- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.tbl td { padding: 13px 14px; border-bottom: 1px solid rgba(48,54,61,0.5); font-size: 14px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: rgba(255,255,255,0.02); }

/* ---- FORM ---- */
.form-group { margin-bottom: 18px; }
.form-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--green); }
.form-input::placeholder { color: var(--text-muted); }
textarea.form-input { resize: vertical; min-height: 90px; }
select.form-input { cursor: pointer; }
.form-input.input-ok    { border-color: var(--green); }
.form-input.input-error { border-color: var(--red); }

/* ---- ALERTS ---- */
.alert {
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.alert-warn { background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.25); color: #fcd34d; }
.alert-ok   { background: rgba(34,197,94,0.12);  border: 1px solid rgba(34,197,94,0.25);  color: var(--green); }
.alert-info { background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.25); color: #93c5fd; }
.alert-err  { background: rgba(239,68,68,0.12);  border: 1px solid rgba(239,68,68,0.25);  color: #fca5a5; }

/* ---- BADGES ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.badge-green  { background: rgba(34,197,94,0.18);  color: var(--green); }
.badge-red    { background: rgba(239,68,68,0.18);   color: var(--red); }
.badge-yellow { background: rgba(245,158,11,0.18);  color: var(--yellow); }
.badge-blue   { background: rgba(59,130,246,0.18);  color: var(--blue); }
.badge-gray   { background: rgba(139,148,158,0.18); color: var(--text-muted); }

/* ---- PHOTO UPLOAD ---- */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.upload-area:hover, .upload-area.drag {
  border-color: var(--green);
  background: rgba(34,197,94,0.05);
}
.upload-icon { font-size: 56px; margin-bottom: 16px; }
.upload-img-preview {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* ---- DIAGNOSIS ---- */
.diag-severity {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 14px;
}
.sev-alto  { background: rgba(239,68,68,0.15);  color: var(--red); }
.sev-medio { background: rgba(245,158,11,0.15);  color: var(--yellow); }
.sev-bajo  { background: rgba(34,197,94,0.15);   color: var(--green); }

/* ---- DIAGNOSIS GALLERY ---- */
.diag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.diag-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.diag-card:hover { border-color: var(--green); transform: translateY(-2px); }
.diag-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}
.diag-thumb-empty {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
}
.diag-card-body { padding: 10px; }
.diag-card-title { font-size: 12px; font-weight: 700; line-height: 1.3; margin-bottom: 6px; }
.diag-card-meta  { font-size: 10px; color: var(--text-muted); margin-bottom: 6px; }
.diag-card-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.diag-card-actions { display: flex; gap: 6px; padding: 0 10px 10px; }

/* categoria badges */
.cat-plaga     { background: rgba(239,68,68,0.15);   color: var(--red); }
.cat-hongo     { background: rgba(245,158,11,0.15);  color: var(--yellow); }
.cat-nutricion { background: rgba(34,197,94,0.15);   color: var(--green); }
.cat-danio     { background: rgba(96,165,250,0.15);  color: var(--blue); }
.cat-otro      { background: rgba(139,148,158,0.15); color: var(--text-muted); }

/* estado badges */
.estado-obs { background: rgba(245,158,11,0.15); color: var(--yellow); }
.estado-ok  { background: rgba(34,197,94,0.15);  color: var(--green); }

/* detail modal */
.diag-detail-foto {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface2);
  margin-bottom: 16px;
}
.diag-save-form {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  border: 1px solid var(--border);
}

/* ---- MINI CALENDAR ---- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-header {
  font-size: 10px;
  text-align: center;
  color: var(--text-muted);
  font-weight: 700;
  padding: 4px 0;
}
.cal-day-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  position: relative;
}
.cal-day-cell:hover { background: rgba(255,255,255,0.06); }
.cal-day-cell.today { background: var(--green); color: #000; font-weight: 800; }
.cal-day-cell.event::after {
  content: '';
  width: 4px; height: 4px;
  background: var(--yellow);
  border-radius: 50%;
  position: absolute;
  bottom: 3px;
}
.cal-day-cell.other { opacity: 0.35; pointer-events: none; }
.cal-day-cell.selected { background: var(--blue); color: #fff; font-weight: 800; box-shadow: 0 0 0 2px rgba(96,165,250,0.6); }
.cal-day-cell.selected:hover { background: var(--blue); }

/* ---- SECTION HEADER ---- */
.section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 17px; font-weight: 700; }

/* ---- LOGIN ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo-ico {
  width: 68px; height: 68px;
  background: var(--green);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin: 0 auto 14px;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary { background: var(--green); color: #000; }
.btn-primary:hover { background: var(--green-dark); color: #000; }
.btn-green  { background: rgba(34,197,94,0.15); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.btn-green:hover  { background: rgba(34,197,94,0.25); }
.btn-blue   { background: rgba(59,130,246,0.15); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.btn-blue:hover   { background: rgba(59,130,246,0.25); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: rgba(255,255,255,0.05); }
.btn-ghost  { background: transparent; color: var(--text-muted); border: none; }
.btn-red    { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-wa     { background: #25d366; color: white; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- GRIDS ---- */
.g2    { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.g3    { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.g4    { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.g-side { display: grid; grid-template-columns: 1fr 300px; gap: 20px; }

/* ---- MODALS ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

/* ---- MAP PLACEHOLDER ---- */
.map-placeholder {
  background: #1a2535;
  border-radius: 8px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.map-tag {
  background: #22c55e22;
  border: 1px solid #22c55e44;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  color: #22c55e;
}

/* ---- PREMIUM CARD ---- */
.premium-card {
  background: linear-gradient(135deg,#0f2d1a,#1a4d2a);
  border-color: #22c55e44;
}

/* ---- DIVIDER ---- */
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ---- TASK ITEMS (dashboard) ---- */
.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
}
.task-item:hover { border-color: rgba(34,197,94,0.4); }
.task-date {
  min-width: 42px;
  padding: 7px 4px;
  text-align: center;
  background: var(--surface);
  border: 1px solid rgba(48,54,61,0.75);
  border-radius: 8px;
}
.task-day   { font-size: 18px; font-weight: 900; line-height: 1; }
.task-month { font-size: 10px; color: var(--text-muted); font-weight: 700; margin-top: 2px; }
.task-icon-wrap {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.task-body   { flex: 1; min-width: 0; }
.task-title  { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.task-detail { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ---- TASK CARDS (mi-huerta) ---- */
.task-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  transition: all 0.2s;
}
.task-card:hover { border-color: rgba(34,197,94,0.4); transform: translateY(-1px); }
.task-card.task-done { opacity: 0.6; }
.task-card.task-done .task-card-title { text-decoration: line-through; }
.task-card-date {
  text-align: center;
  min-width: 48px;
  padding: 8px 4px;
  border-radius: 10px;
  background: var(--surface);
}
.task-date-today    { background: rgba(34,197,94,0.15);  border: 1px solid rgba(34,197,94,0.3); }
.task-date-overdue  { background: rgba(239,68,68,0.12);  border: 1px solid rgba(239,68,68,0.35); }
.task-card.task-overdue { border-left: 3px solid var(--red); }
.task-card-day { font-size: 22px; font-weight: 900; line-height: 1; }
.task-card-mon { font-size: 10px; text-transform: uppercase; color: var(--text-muted); margin-top: 2px; }
.task-card-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.task-card-body  { flex: 1; }
.task-card-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task-card-detail { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.task-card-actions { display: flex; gap: 6px; }
.btn-check {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(34,197,94,0.3);
  background: rgba(34,197,94,0.1);
  color: var(--green);
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-check:hover { background: var(--green); color: #000; }
.btn-delete {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(239,68,68,0.3);
  background: rgba(239,68,68,0.1);
  color: var(--red);
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-delete:hover { background: var(--red); color: #fff; }

/* ---- SUMMARY ROWS ---- */
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.summary-row:last-child { border-bottom: none; }
.summary-lbl { font-size: 13px; color: var(--text-muted); }
.summary-val { font-size: 16px; font-weight: 800; }

/* ---- RANCHO CARDS ---- */
.rancho-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  transition: all 0.2s;
}
.rancho-card:hover { border-color: rgba(34,197,94,0.4); transform: translateY(-2px); }
.rancho-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.rancho-icon { font-size: 28px; }
.rancho-name { font-size: 17px; font-weight: 800; }
.rancho-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.rancho-stat {
  text-align: center;
  padding: 10px 6px;
  background: var(--surface);
  border-radius: 8px;
}
.rancho-stat-val { font-size: 14px; font-weight: 800; margin-bottom: 2px; }
.rancho-stat-lbl { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.rancho-loc   { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.rancho-notas {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 10px;
  background: var(--surface);
  border-radius: 6px;
  margin-bottom: 12px;
}
.rancho-actions { display: flex; gap: 8px; }

/* ---- MES LABEL ---- */
.mes-label { font-size: 17px; font-weight: 800; }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- MOBILE ---- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .g-side { grid-template-columns: 1fr; }
  .forecast-grid { grid-template-columns: repeat(4, 1fr); }
  .page { padding: 16px; }
  .topbar { padding: 14px 16px; gap: 12px; }
  .price-hero { font-size: 48px; }
  .menu-btn { display: flex !important; }
  .mercado-tabs { overflow-x: auto; }
  .mercado-tab { white-space: nowrap; }
  .order-top, .pending-row { align-items: flex-start; }
  .order-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .order-actions, .pending-actions { flex-wrap: wrap; }
  .tbl { display: block; overflow-x: auto; white-space: nowrap; }
  .modal-box { max-width: 100%; }
  .filter-bar { gap: 8px; }
  .search-wrap { min-width: 160px; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .login-box { padding: 28px 22px; }
  .topbar { align-items: flex-start; }
  .data-status { align-self: center; font-size: 11px; padding: 6px 8px; }
  .price-hero { font-size: 40px; }
  .price-unit { font-size: 15px; }
  .stat-card-value { font-size: 24px; }
  .order-top, .pending-row, .task-card, .task-item { gap: 10px; }
  .order-stats { grid-template-columns: 1fr; }
  .order-actions .btn, .pending-actions .btn { width: 100%; justify-content: center; }
  .forecast-grid { grid-template-columns: repeat(2, 1fr); }
  .rancho-stats { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-wrap { min-width: unset; }
}

/* ==========================================
   TOAST / SNACKBAR — Fase 2
   ========================================== */
#_toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: 340px;
}
._toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  pointer-events: all;
  cursor: pointer;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease;
  max-width: 340px;
  word-break: break-word;
}
._toast-show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
._toast-hide {
  opacity: 0;
  transform: translateY(8px) scale(0.95);
}
._toast-icon { font-size: 16px; flex-shrink: 0; }
._toast-ok    { background: rgba(22,163,74,0.92);  color: #fff; }
._toast-error { background: rgba(220,38,38,0.92);  color: #fff; }
._toast-warn  { background: rgba(217,119,6,0.92);  color: #fff; }
._toast-info  { background: rgba(37,99,235,0.92);  color: #fff; }

/* ==========================================
   INDICADOR OFFLINE — Fase 2
   ========================================== */
#_offline-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9998;
  background: #b45309;
  color: #fff;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 20px;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
#_offline-bar._offline-show {
  transform: translateY(0);
}

@media (max-width: 640px) {
  #_toast-container {
    bottom: 16px;
    right: 12px;
    left: 12px;
    max-width: unset;
  }
  ._toast { max-width: unset; }
}

/* ---- Fase 3: Historial stats ---- */
.hist-stat { display:flex; flex-direction:column; gap:2px; min-width:90px; }
.hist-stat-lbl { font-size:10px; font-weight:700; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.04em; }
.hist-stat-val { font-size:18px; font-weight:800; color:var(--text); }
.hist-stat-val.green { color:var(--green); }

/* ==========================================
   MOBILE OPTIMIZATIONS — v8.2
   iOS + Android
   ========================================== */

/* 1. Eliminar tap highlight en todos los elementos interactivos */
* { -webkit-tap-highlight-color: transparent; }

/* 2. Touch-action: elimina delay de 300ms en iOS */
button, a, [role="button"], .chip, .nav-item, .mercado-tab {
  touch-action: manipulation;
}

/* 3. Prevenir bounce/overscroll en iOS */
html { height: 100%; }
body { overscroll-behavior-y: none; }

/* 4. Safe area — topbar (iOS notch / Dynamic Island) */
.topbar {
  padding-top: max(16px, calc(16px + env(safe-area-inset-top)));
}

/* 5. Safe area — sidebar */
.sidebar {
  padding-top: env(safe-area-inset-top);
}

/* 6. Fix iOS zoom en inputs (font-size < 16px hace zoom automático) */
@media (max-width: 767px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

/* ==========================================
   BOTTOM NAVIGATION BAR
   Solo visible en móvil (< 768px)
   Reemplaza el drawer lateral
   ========================================== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--surface);
  border-top: 1px solid var(--border);
  /* Altura fija + safe area de iPhone (botón home / barra de gestos) */
  padding-bottom: env(safe-area-inset-bottom);
  flex-direction: row;
  align-items: stretch;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
}

.bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 0.15s;
  min-height: 56px;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
}

.bn-item.active {
  color: var(--green);
}

.bn-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--green);
  border-radius: 0 0 2px 2px;
}

.bn-icon {
  font-size: 22px;
  line-height: 1;
  display: block;
}

.bn-label {
  display: block;
  line-height: 1;
}

/* 6 tabs: reducir icono y label para que quepan sin apretarse */
.bottom-nav:has(.bn-item:nth-child(6)) .bn-icon {
  font-size: 19px;
}
.bottom-nav:has(.bn-item:nth-child(6)) .bn-item {
  font-size: 9px;
  padding: 10px 2px 8px;
  gap: 2px;
}

/* Badge en el icono del mercado */
.bn-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

@media (max-width: 767px) {
  /* Mostrar bottom nav, ocultar sidebar y hamburger */
  .bottom-nav { display: flex; }
  .sidebar { display: none !important; }
  .menu-btn { display: none !important; }

  /* El contenido principal NO tiene margin-left (ya resuelto en 900px) */
  /* pero necesita padding-bottom para no quedar detrás del bottom nav */
  .main {
    margin-left: 0;
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  /* Topbar ocupa todo el ancho */
  .topbar { padding-left: 20px; padding-right: 20px; }

  /* Toast sobre el bottom nav */
  #_toast-container {
    bottom: calc(72px + env(safe-area-inset-bottom));
  }

  /* Offline bar debajo del topbar con safe area */
  #_offline-bar {
    padding-top: calc(10px + env(safe-area-inset-top));
  }
}
.hist-stat-val.red   { color:var(--red); }
