/* =================================================================
   EL GAUCHO ARGENTINO — Hoja de estilos
   Paleta: blanco + navy (del logo)
================================================================= */

:root {
  --bg: #ffffff;
  --surface: #f7f9fc;
  --surface2: #eef2f7;
  --surface3: #e3e9f1;
  --border: #dde3eb;
  --border2: #b8c2d0;
  --primary: #1a3258;
  --primary-hover: #234782;
  --primary-light: #e8eef7;
  --accent: #4a7bc8;
  --accent-light: #d6e3f5;
  --text: #1a3258;
  --text2: #4a5468;
  --text3: #8895a8;
  --green: #2e7a4f;
  --green-light: #e2f1e9;
  --red: #c43d3d;
  --red-light: #fbe5e5;
  --orange: #c47a1a;
  --orange-light: #faf0dc;
  --shadow: 0 1px 3px rgba(26,50,88,0.06), 0 4px 12px rgba(26,50,88,0.04);
  --shadow-md: 0 4px 12px rgba(26,50,88,0.08), 0 12px 32px rgba(26,50,88,0.06);
  --radius: 8px;
  --radius-sm: 4px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ HEADER ============ */
.header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}
.brand-logo img, .brand-logo svg {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.brand-text { line-height: 1.15; }
.brand-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--primary);
  letter-spacing: 0.3px;
}
.brand-sub {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.user-menu { display: flex; align-items: center; gap: 12px; }
.user-info { text-align: right; line-height: 1.2; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-role { font-size: 11px; color: var(--text3); font-family: var(--font-mono); }

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  cursor: pointer;
  color: var(--text2);
  font-size: 13px;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--surface2); color: var(--primary); border-color: var(--border2); }

/* ============ TABS ============ */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  background: var(--bg);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
  white-space: nowrap;
}
.tab:hover { color: var(--primary); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab .tab-count {
  background: var(--surface2);
  color: var(--text3);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  margin-left: 6px;
  font-family: var(--font-mono);
}

/* ============ MAIN CONTAINER ============ */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}
@media (max-width: 640px) {
  .main { padding: 16px 12px 80px; }
  .header { padding: 0 12px; }
  .tabs { padding: 0 12px; }
}

/* ============ PANELS / CARDS ============ */
.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.panel-title::before {
  content: '';
  display: block;
  width: 3px;
  height: 18px;
  background: var(--primary);
  border-radius: 2px;
}

/* ============ FORMS ============ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.form-input, .form-select, .form-textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-input::placeholder { color: var(--text3); }
.form-textarea { resize: vertical; min-height: 60px; }
.form-help { font-size: 12px; color: var(--text3); }

/* ============ BUTTONS ============ */
.btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: var(--surface3); color: var(--text3); cursor: not-allowed; }
.btn-secondary {
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface); border-color: var(--primary); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #a83333; }
.btn-success { background: var(--green); }
.btn-success:hover { background: #246039; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* ============ TIPO MOVIMIENTO SELECTOR ============ */
.tipo-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.tipo-opt {
  padding: 11px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text2);
  transition: all 0.15s;
}
.tipo-opt:hover { border-color: var(--border2); }
.tipo-opt.sel-entrega {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.tipo-opt.sel-cobro {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-light);
}
.tipo-opt.sel-venta {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* ============ AUTOCOMPLETE ============ */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  z-index: 200;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  display: none;
}
.autocomplete-list.show { display: block; }
.ac-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--surface); }
.ac-item-name { color: var(--text); font-weight: 500; font-size: 13px; }
.ac-item-sub { color: var(--text3); font-size: 11px; font-family: var(--font-mono); }
.ac-add {
  color: var(--primary);
  font-size: 13px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  background: var(--surface);
}
.ac-add:hover { background: var(--surface2); }

/* ============ TOTAL PREVIEW ============ */
.total-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.total-label { font-size: 11px; color: var(--text3); letter-spacing: 0.4px; text-transform: uppercase; }
.total-val { font-size: 22px; font-weight: 700; color: var(--primary); font-family: var(--font-mono); }
.total-val.consig { color: var(--text3); font-size: 14px; }

/* ============ TABLAS ============ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 700px; }
thead { background: var(--surface); }
th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--text3);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(26,50,88,0.02); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-entrega { background: var(--accent-light); color: var(--accent); }
.badge-cobro { background: var(--green-light); color: var(--green); }
.badge-venta { background: var(--primary-light); color: var(--primary); }
.badge-region { background: var(--surface2); color: var(--text2); font-family: var(--font-mono); font-size: 10px; padding: 2px 6px; }

.money { font-family: var(--font-mono); }
.money-zero { color: var(--text3); }

/* ============ STATS ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label {
  font-size: 11px;
  color: var(--text3);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-weight: 600;
}
.stat-val {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
}
.stat-val.primary { color: var(--primary); }
.stat-val.green { color: var(--green); }
.stat-val.accent { color: var(--accent); }
.stat-val.muted { color: var(--text2); font-weight: 500; }
.stat-val.red { color: var(--red); }

/* ============ FILTERS ============ */
.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-btn {
  padding: 6px 12px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--border2); color: var(--primary); }
.filter-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.table-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text3);
  font-size: 14px;
}

/* ============ FILTROS EXCEL-STYLE ============ */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.filter-bar-cell { display: flex; flex-direction: column; gap: 4px; }
.fb-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.filter-bar input, .filter-bar select { padding: 7px 9px; font-size: 12px; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); background: var(--surface2); }

/* ============ RUTA DEL DÍA ============ */
.ruta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
}
.ruta-cli {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s;
}
.ruta-cli:hover { border-color: var(--border2); background: var(--surface); }
.ruta-cli.sel { background: var(--primary-light); border-color: var(--primary); }
.ruta-cli input { cursor: pointer; }

/* Producto selector */
.tipo-opt.producto-opt.sel {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}
@media (max-width: 640px) {
  .filter-bar { grid-template-columns: 1fr; }
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,50,88,0.55);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--primary); }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text3);
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--primary); }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--green);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transition: all 0.3s;
  box-shadow: var(--shadow-md);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: var(--red); }
.toast.warn { background: var(--orange); }

/* ============ AUTH (login / signup) ============ */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #f7f9fc 0%, #eef2f7 100%);
  padding: 20px;
}
.auth-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
}
.auth-logo {
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.auth-logo img, .auth-logo svg { width: 100%; height: 100%; }
.auth-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}
.auth-sub {
  text-align: center;
  font-size: 13px;
  color: var(--text3);
  margin-bottom: 24px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-link {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text3);
}
.auth-error {
  background: var(--red-light);
  color: var(--red);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}
.auth-error.show { display: block; }
.auth-info {
  background: var(--primary-light);
  color: var(--primary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ============ MAPA ============ */
#map {
  width: 100%;
  height: 70vh;
  min-height: 480px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: 1;
}
.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.leaflet-popup-content { font-family: var(--font); font-size: 13px; }
.leaflet-popup-content b { color: var(--primary); }

/* ============ INVITE LINK BLOCK ============ */
.invite-link-box {
  background: var(--surface);
  border: 1px dashed var(--border2);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============ VISIBILIDAD POR ROL ============ */
.role-only { display: none; }
body[data-role="super_admin"] .role-only,
body[data-role="socio"] .role-only { display: revert; }
body[data-role="socio"] .role-super-admin-only,
body[data-role="gerente"] .role-super-admin-only,
body[data-role="empleado"] .role-super-admin-only { display: none; }
body[data-role="super_admin"] .role-super-admin-only { display: revert; }
body:not([data-role="empleado"]) .role-empleado-only { display: none; }
body[data-role="empleado"] .hide-for-empleado { display: none !important; }

/* Columna ganancia: solo super_admin y socio */
body:not([data-role="super_admin"]):not([data-role="socio"]) .col-ganancia { display: none; }

/* Tab Movimientos / Clientes / Usuarios — empleado solo ve Cargar y Mapa */
body[data-role="empleado"] .tab-gerente,
body[data-role="empleado"] .tab-admin { display: none; }
body[data-role="gerente"] .tab-admin { display: none; }

/* ============ MOBILE TWEAKS ============ */
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .tipo-selector { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { max-width: 100%; }
  .user-info { display: none; }
  .panel { padding: 16px; }
  .brand-sub { display: none; }
}


/* ============ LOADING ============ */
.loading {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 9999;
}
.loading-screen .loading { width: 32px; height: 32px; border-width: 3px; }
.loading-screen p { color: var(--text3); font-size: 13px; }

/* ============ HIDDEN / PAGE ============ */
.hidden { display: none !important; }
.page { display: none; }
.page.active { display: block; }
