/* ── CIMSA BRAND COLORS ─────────────────────────── */
:root {
  --green:       #1B6B5A;
  --green-dark:  #134F43;
  --green-mid:   #2A8870;
  --green-light: #E8F3F0;
  --gray-dark:   #4D4D4D;
  --gray-mid:    #7A7A7A;
  --gray-light:  #D9D9D9;
  --gray-bg:     #F2F2F2;
  --white:       #FFFFFF;
  --error:       #C0392B;
  --sidebar-w:   220px;
}

/* ── RESET ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; 
  font-size: 15px; 
  color: var(--gray-dark); 
  background: var(--gray-bg);
  height: 100%;
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
input, select, button, textarea { font-family: inherit; font-size: inherit; }

/* ── LOGIN ──────────────────────────────────────── */
.login-body { 
  display: flex; align-items: center; justify-content: center; 
  min-height: 100vh; background: var(--green); 
  overflow: auto;
}
.login-wrap { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; padding: 2rem; width: 100%; }
.login-logo { text-align: center; }
.login-logo-text { font-size: 32px; font-weight: 600; color: var(--white); letter-spacing: 0.08em; }
.login-logo-sub { font-size: 12px; color: rgba(255,255,255,0.6); letter-spacing: 0.12em; margin-top: 2px; }
.login-card { background: var(--white); border-radius: 12px; padding: 2rem; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; box-shadow: 0 4px 24px rgba(0,0,0,0.15); }
.login-card h2 { font-size: 16px; font-weight: 500; color: var(--green); text-align: center; margin-bottom: 0.25rem; }
.login-footer { font-size: 11px; color: rgba(255,255,255,0.4); text-align: center; }
.error-msg { background: #FDECEA; color: var(--error); border: 1px solid #F5C6CB; border-radius: 6px; padding: 8px 12px; font-size: 13px; }

/* ── FORM FIELDS ────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; color: var(--gray-dark); }
.field input, .field select { height: 40px; border: 1px solid var(--gray-light); border-radius: 8px; padding: 0 12px; color: var(--gray-dark); background: var(--gray-bg); outline: none; transition: border-color 0.15s; font-size: 15px; }
.field input:focus, .field select:focus { border-color: var(--green); background: var(--white); }

/* ── BUTTONS ────────────────────────────────────── */
.btn-primary { height: 42px; background: var(--green); color: var(--white); border: none; border-radius: 8px; font-size: 15px; font-weight: 500; cursor: pointer; transition: background 0.15s; }
.btn-primary:hover { background: var(--green-dark); }
.btn-primary.btn-sm { height: 32px; padding: 0 14px; font-size: 13px; }
.btn-secondary { height: 42px; background: transparent; color: var(--gray-dark); border: 1px solid var(--gray-light); border-radius: 8px; font-size: 15px; cursor: pointer; }
.btn-secondary:hover { background: var(--gray-bg); }

/* ── APP LAYOUT ─────────────────────────────────── */
.app-body { background: var(--white); height: 100%; overflow: hidden; }
.app-layout { 
  display: flex; 
  height: 100%; 
  height: 100dvh; /* dynamic viewport height — clave en móvil */
  overflow: hidden; 
  position: relative;
}

/* ── SIDEBAR OVERLAY (móvil) ────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}
.sidebar-overlay.active { display: block; }

/* ── SIDEBAR ────────────────────────────────────── */
.sidebar { 
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--gray-bg); 
  border-right: 1px solid var(--gray-light); 
  display: flex; 
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header { padding: 16px; border-bottom: 1px solid var(--gray-light); display: flex; align-items: center; justify-content: space-between; }
.sidebar-logo { font-size: 16px; font-weight: 600; color: var(--green); }
.sidebar-logo-sub { font-size: 11px; color: var(--gray-mid); margin-top: 1px; }
.sidebar-close { background: none; border: none; cursor: pointer; color: var(--gray-mid); padding: 4px; display: flex; align-items: center; justify-content: center; }
.sidebar-close:hover { color: var(--gray-dark); }

.sidebar-menu { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.menu-item { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 7px; font-size: 14px; color: var(--gray-dark); cursor: pointer; transition: background 0.1s; }
.menu-item:hover { background: var(--gray-light); }
.menu-item.active { background: var(--green); color: var(--white); }

.sidebar-bottom { border-top: 1px solid var(--gray-light); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--green); color: var(--white); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 500; color: var(--gray-dark); }
.user-role { font-size: 11px; color: var(--gray-mid); }
.sidebar-links { display: flex; flex-direction: column; padding: 0 16px 14px; gap: 4px; }
.sidebar-link { font-size: 13px; color: var(--gray-mid); cursor: pointer; padding: 4px 0; }
.sidebar-link:hover { color: var(--green); }

/* ── CHAT MAIN ──────────────────────────────────── */
.chat-main { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  overflow: hidden; 
  min-width: 0;
  height: 100%;
  height: 100dvh;
}

.chat-topbar { 
  padding: 10px 14px; 
  border-bottom: 1px solid var(--gray-light); 
  display: flex; 
  align-items: center; 
  gap: 10px;
  background: var(--white);
  flex-shrink: 0;
}
.hamburger { 
  background: none; border: none; cursor: pointer; 
  color: var(--gray-dark); padding: 4px; 
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hamburger:hover { color: var(--green); }
.chat-topbar-title { font-size: 15px; font-weight: 500; color: var(--gray-dark); flex: 1; }
.badge { font-size: 11px; padding: 3px 10px; border-radius: 99px; background: var(--green-light); color: var(--green-dark); font-weight: 500; white-space: nowrap; }

/* ── MESSAGES ───────────────────────────────────── */
.messages { 
  flex: 1; 
  overflow-y: auto; 
  padding: 14px 14px 8px;
  display: flex; 
  flex-direction: column; 
  gap: 14px; 
  background: var(--white);
  -webkit-overflow-scrolling: touch;
}
.msg { display: flex; gap: 9px; align-items: flex-start; max-width: 88%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; margin-top: 2px; }
.msg-avatar.bot { background: var(--green); color: var(--white); }
.msg-avatar.usr { background: var(--green-light); color: var(--green); }
.msg-bubble { padding: 10px 14px; border-radius: 12px; font-size: 15px; line-height: 1.55; max-width: 100%; word-wrap: break-word; }
.msg.bot .msg-bubble { background: var(--gray-bg); color: var(--gray-dark); border: 1px solid var(--gray-light); border-radius: 2px 12px 12px 12px; }
.msg.user .msg-bubble { background: var(--green); color: var(--white); border-radius: 12px 2px 12px 12px; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble br + br { display: none; }

/* Typing indicator */
.typing { display: flex; gap: 4px; align-items: center; padding: 10px 14px; }
.typing span { width: 7px; height: 7px; background: var(--gray-mid); border-radius: 50%; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity:.3 } 40% { opacity:1 } }

/* ── INPUT ROW ──────────────────────────────────── */
.chat-input-row { 
  padding: 10px 14px 12px;
  border-top: 1px solid var(--gray-light); 
  display: flex; 
  gap: 10px; 
  align-items: center; 
  background: var(--white);
  flex-shrink: 0;
}
.chat-input { 
  flex: 1; 
  height: 44px; 
  border: 1px solid var(--gray-light); 
  border-radius: 99px; 
  padding: 0 18px; 
  font-size: 15px; 
  color: var(--gray-dark); 
  background: var(--gray-bg); 
  outline: none; 
  transition: border-color 0.15s;
}
.chat-input:focus { border-color: var(--green); background: var(--white); }
.send-btn { 
  width: 40px; height: 40px; 
  border-radius: 50%; 
  background: var(--green); 
  border: none; 
  display: flex; align-items: center; justify-content: center; 
  cursor: pointer; 
  flex-shrink: 0; 
  transition: background 0.15s;
}
.send-btn:hover { background: var(--green-dark); }

/* ── ADMIN ──────────────────────────────────────── */
.admin-layout { min-height: 100vh; background: var(--gray-bg); overflow: auto; }
.admin-topbar { padding: 12px 24px; background: var(--green); display: flex; align-items: center; justify-content: space-between; }
.admin-title { font-size: 15px; font-weight: 500; color: var(--white); }
.badge-admin { font-size: 11px; padding: 3px 10px; border-radius: 99px; background: rgba(255,255,255,0.2); color: var(--white); }
.admin-link { font-size: 13px; color: rgba(255,255,255,0.8); }
.admin-link:hover { color: var(--white); }
.admin-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; max-width: 1100px; }
.admin-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card { background: var(--white); border: 1px solid var(--gray-light); border-radius: 8px; padding: 14px 16px; }
.stat-label { font-size: 11px; color: var(--gray-mid); margin-bottom: 4px; }
.stat-val { font-size: 26px; font-weight: 500; color: var(--gray-dark); }
.stat-val.green { color: var(--green); }
.admin-section { background: var(--white); border: 1px solid var(--gray-light); border-radius: 10px; overflow: hidden; }
.admin-section-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--gray-light); }
.admin-section-header h3 { font-size: 14px; font-weight: 500; color: var(--gray-dark); }
.table-header { display: grid; grid-template-columns: 2fr 1.2fr 1fr 1fr 0.7fr 1fr; gap: 8px; padding: 9px 16px; background: var(--gray-bg); border-bottom: 1px solid var(--gray-light); }
.table-header span { font-size: 11px; font-weight: 500; color: var(--gray-mid); }
.table-row { display: grid; grid-template-columns: 2fr 1.2fr 1fr 1fr 0.7fr 1fr; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--gray-light); align-items: center; }
.table-row:last-child { border-bottom: none; }
.table-row:nth-child(even) { background: var(--gray-bg); }
.table-row span { font-size: 13px; color: var(--gray-dark); }
.role-pill { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 99px; font-weight: 500; }
.role-comercial { background: var(--green-light); color: var(--green-dark); }
.role-caja { background: #F2F2F2; color: var(--gray-dark); border: 1px solid var(--gray-light); }
.role-admin { background: var(--gray-dark); color: var(--white); }
.role-direccion { background: #EEE; color: var(--gray-dark); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); }
.dot.gray { background: var(--gray-light); }
.btn-edit { font-size: 12px; padding: 3px 10px; border: 1px solid var(--gray-light); border-radius: 6px; background: var(--white); color: var(--gray-dark); cursor: pointer; }
.btn-edit:hover { border-color: var(--green); color: var(--green); }

/* ── MODAL ──────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-card { background: var(--white); border-radius: 12px; padding: 24px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; }
.modal-card h3 { font-size: 15px; font-weight: 500; color: var(--green); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ── RESPONSIVE MÓVIL ───────────────────────────── */
@media (max-width: 640px) {
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
  .table-header { grid-template-columns: 2fr 1fr 1fr; }
  .table-row { grid-template-columns: 2fr 1fr 1fr; }
  .table-header span:nth-child(n+4), .table-row span:nth-child(n+4) { display: none; }
  .msg { max-width: 95%; }
  .chat-input-row { padding: 8px 10px 10px; }
}

/* Evitar que el teclado virtual empuje el layout en iOS */
@supports (-webkit-touch-callout: none) {
  .app-layout, .chat-main { height: -webkit-fill-available; }
}

/* ── BOTÓN DESCARGA EXCEL ───────────────────────── */
.excel-download { margin: 8px 0; }
.excel-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--green); color: var(--white);
  padding: 8px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
}
.excel-btn:hover { background: var(--green-dark); }

/* ── TABLAS EN CHAT ─────────────────────────────── */
.msg-table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; table-layout: auto; }
.msg-table th { background: var(--green); color: var(--white); padding: 6px 10px; text-align: left; font-weight: 500; }
.msg-table td { padding: 5px 10px; border-bottom: 1px solid var(--gray-light); text-align: left; }
.msg-table tr:nth-child(even) td { background: var(--gray-bg); }
.msg-h2 { font-size: 15px; font-weight: 600; color: var(--green); margin: 10px 0 4px; }
.msg-h3 { font-size: 14px; font-weight: 600; color: var(--gray-dark); margin: 8px 0 4px; }
.msg-bubble ul { padding-left: 18px; margin: 4px 0; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble br + ul,
.msg-bubble ul + br { display: none; }
.msg-bubble hr { border: none; border-top: 1px solid var(--gray-light); margin: 8px 0; }