:root {
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --surface2: #F0F2F5;
  --border: #E4E7EC;
  --text: #111827;
  --text2: #6B7280;
  --text3: #9CA3AF;
  --primary: #00338D;
  --primary-soft: #E8EDF9;
  --primary-mid: #8099C4;
  --green: #059669;
  --green-soft: #ECFDF5;
  --amber: #D97706;
  --amber-soft: #FFFBEB;
  --red: #DC2626;
  --red-soft: #FEF2F2;
  --purple: #7C3AED;
  --purple-soft: #F5F3FF;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --nav-h: 64px;
  --bottom-h: 68px;
  /* === VARIABLES FALTANTES === */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F0F2F5;
  --text-primary: #111827;
  --text-secondary: #6B7280;
  --accent-color: #00338D;
  --border-color: #E4E7EC;
}

/* Modo oscuro */
body.dark-mode {
  --bg: #111827;
  --surface: #1F2937;
  --surface2: #2D3748;
  --border: #374151;
  --text: #F9FAFB;
  --text2: #9CA3AF;
  --text3: #6B7280;
  --primary: #00338D;
  --primary-soft: #1E3A5F;
  --primary-mid: #4A6A8F;
  --green: #34D399;
  --green-soft: #1A3A2A;
  --amber: #FBBF24;
  --amber-soft: #3A2E1A;
  --red: #F87171;
  --red-soft: #3A1A1A;
  --purple: #A78BFA;
  --purple-soft: #2A1A3A;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  /* === VARIABLES FALTANTES MODO OSCURO === */
  --bg-primary: #1F2937;
  --bg-secondary: #2D3748;
  --text-primary: #F9FAFB;
  --text-secondary: #9CA3AF;
  --accent-color: #4A6A8F;
  --border-color: #374151;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; max-width: 430px; margin: 0 auto; position: relative; overflow-x: hidden; transition: background 0.3s, color 0.3s; }

/* TOP NAV */
.top-nav {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px; height: var(--nav-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; z-index: 100;
  backdrop-filter: blur(10px);
  transition: background 0.3s, border-color 0.3s;
}
.nav-logo { font-weight: 800; font-size: 18px; color: var(--primary); letter-spacing: -0.5px; }
.nav-logo span { color: var(--text); }
.nav-right { display: flex; gap: 8px; align-items: center; }
.nav-icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--surface2); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: var(--text2); transition: background 0.15s;
}
.nav-icon-btn:active { background: var(--border); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; cursor: pointer; }

/* BOTTOM NAV */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px; height: var(--bottom-h);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  padding: 0 8px 8px; z-index: 100;
  transition: background 0.3s, border-color 0.3s;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer; padding: 6px 0; border-radius: var(--radius-sm);
  transition: all .15s;
}
.nav-item .nav-icon { font-size: 22px; line-height: 1; }
.nav-item .nav-label { font-size: 10px; font-weight: 500; color: var(--text3); letter-spacing: 0.2px; }
.nav-item.active .nav-label { color: var(--primary); }
.nav-item.active .nav-icon { filter: none; }
.nav-item:not(.active) { opacity: 0.6; }
.nav-item:active { opacity: 0.4; }

/* FAB */
.fab {
  position: fixed; bottom: calc(var(--bottom-h) + 12px); right: calc(50% - 215px + 16px);
  width: 52px; height: 52px; border-radius: 50%; background: var(--primary);
  color: #fff; font-size: 26px; border: none; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,51,141,0.4); display: flex; align-items: center; justify-content: center;
  z-index: 99; transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(0.93); box-shadow: 0 2px 8px rgba(0,51,141,0.3); }

/* Ocultar elementos para cliente (se aplica con JavaScript) */
.hidden-cliente {
  display: none !important;
}

/* SCREENS */
.screen { display: none; padding: calc(var(--nav-h) + 16px) 16px calc(var(--bottom-h) + 20px); min-height: 100vh; }
.screen.active { display: block; }

/* CARDS */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); transition: background 0.3s, box-shadow 0.3s; }
.card + .card { margin-top: 12px; }

/* DASHBOARD */
.greeting { margin-bottom: 16px; }
.greeting h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.greeting p { font-size: 13px; color: var(--text2); margin-top: 2px; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); border-left: 3px solid transparent;
  transition: background 0.3s, box-shadow 0.3s;
}
.kpi-card.blue { border-left-color: var(--primary); }
.kpi-card.green { border-left-color: var(--green); }
.kpi-card.amber { border-left-color: var(--amber); }
.kpi-card.purple { border-left-color: var(--purple); }
.kpi-label { font-size: 11px; color: var(--text2); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 800; letter-spacing: -1px; font-family: 'JetBrains Mono', monospace; }
.kpi-value.blue { color: var(--primary); }
.kpi-value.green { color: var(--green); }
.kpi-value.amber { color: var(--amber); }
.kpi-value.purple { color: var(--purple); }
.kpi-sub { font-size: 11px; color: var(--text3); margin-top: 3px; }

#chart-ventas {
  height: 220px !important;
  max-height: 220px;
  width: 100% !important;
}

/* SECTION HEADER */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--text); }
.section-link { font-size: 12px; color: var(--primary); font-weight: 500; cursor: pointer; }

/* ACTIVITY ITEMS */
.activity-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; padding-bottom: 0; }
.act-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.act-info { flex: 1; }
.act-name { font-size: 13px; font-weight: 600; }
.act-sub { font-size: 11px; color: var(--text3); margin-top: 1px; }
.act-amount { font-size: 13px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }

/* CHART */
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 60px; padding: 0 2px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; border-radius: 4px 4px 0 0; background: var(--primary-mid); transition: height .3s; cursor: pointer; }
.bar.highlight { background: var(--primary); }
.bar-label { font-size: 9px; color: var(--text3); font-weight: 500; }

/* SEARCH & FILTERS */
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-input { flex: 1; height: 42px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 0 12px; font-size: 14px; font-family: 'Inter', sans-serif; background: var(--surface); color: var(--text); outline: none; transition: border-color .15s, background 0.3s; }
.search-input:focus { border-color: var(--primary); }
.filter-btn { height: 42px; width: 42px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 17px; transition: background 0.3s, border-color 0.3s; }

.chips { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; padding-bottom: 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 500; border: 1.5px solid var(--border); background: var(--surface); color: var(--text2); cursor: pointer; transition: all .15s; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* VENTAS */
.sale-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); margin-bottom: 10px; transition: background 0.3s, box-shadow 0.3s;
}
.sale-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sale-id { font-size: 11px; color: var(--text3); font-family: 'JetBrains Mono', monospace; }
.sale-status { font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: 20px; }
.sale-status.pagado { background: var(--green-soft); color: var(--green); }
.sale-status.pendiente { background: var(--amber-soft); color: var(--amber); }
.sale-status.cancelado { background: var(--red-soft); color: var(--red); }
.sale-client { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.sale-meta { font-size: 12px; color: var(--text2); }
.sale-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.sale-items { font-size: 12px; color: var(--text3); }
.sale-total { font-size: 17px; font-weight: 800; color: var(--text); font-family: 'JetBrains Mono', monospace; }

/* INVENTARIO */
.inv-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
  transition: background 0.3s, box-shadow 0.3s;
}
.inv-img { width: 48px; height: 48px; border-radius: 10px; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.inv-info { flex: 1; }
.inv-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.inv-cat { font-size: 11px; color: var(--text3); }
.inv-right { text-align: right; }
.inv-price { font-size: 15px; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--primary); }
.inv-stock { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 20px; margin-top: 4px; display: inline-block; }
.inv-stock.ok { background: var(--green-soft); color: var(--green); }
.inv-stock.low { background: var(--amber-soft); color: var(--amber); }
.inv-stock.out { background: var(--red-soft); color: var(--red); }

/* CLIENTES */
.client-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
  transition: background 0.3s, box-shadow 0.3s;
}
.client-avatar { width: 44px; height: 44px; border-radius: 50%; font-size: 15px; font-weight: 700; color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.client-info { flex: 1; }
.client-name { font-size: 14px; font-weight: 600; }
.client-phone { font-size: 12px; color: var(--text3); margin-top: 1px; font-family: 'JetBrains Mono', monospace; }
.client-right { text-align: right; }
.client-spent { font-size: 14px; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--green); }
.client-orders { font-size: 11px; color: var(--text3); margin-top: 2px; }
.client-tag { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 20px; margin-top: 5px; display: inline-block; }
.client-tag.vip { background: var(--purple-soft); color: var(--purple); }
.client-tag.regular { background: var(--primary-soft); color: var(--primary); }
.client-tag.nuevo { background: var(--green-soft); color: var(--green); }

/* REPORTES */
.report-tabs { display: flex; gap: 4px; margin-bottom: 14px; background: var(--surface2); padding: 4px; border-radius: var(--radius-sm); }
.report-tab { flex: 1; padding: 8px 4px; text-align: center; font-size: 12px; font-weight: 600; color: var(--text2); border-radius: 6px; cursor: pointer; transition: all .15s; }
.report-tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-label { font-size: 13px; color: var(--text2); }
.stat-value { font-size: 14px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.stat-value.up { color: var(--green); }
.stat-value.down { color: var(--red); }

.top-product { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.top-product:last-child { border-bottom: none; }
.top-rank { font-size: 12px; font-weight: 700; color: var(--text3); width: 20px; }
.top-name { flex: 1; font-size: 13px; font-weight: 600; }
.top-bar-wrap { width: 80px; height: 6px; background: var(--surface2); border-radius: 3px; }
.top-bar { height: 6px; background: var(--primary); border-radius: 3px; }
.top-val { font-size: 12px; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--primary); width: 45px; text-align: right; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200;
  display: none; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 20px 18px 32px;
  width: 100%; max-width: 430px; max-height: 80vh; overflow-y: auto;
  animation: slideUp .25s ease;
  transition: background 0.3s;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 16px; }
.sheet-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }

/* FORM */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.4px; }
.field input, .field select, .field textarea {
  width: 100%; height: 44px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 0 12px; font-size: 14px; font-family: 'Inter', sans-serif; color: var(--text);
  background: var(--surface); outline: none; transition: border-color .15s, background 0.3s, color 0.3s;
}
.field textarea { height: 80px; padding: 10px 12px; resize: none; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }

.btn { width: 100%; height: 48px; border-radius: var(--radius-sm); border: none; font-size: 15px; font-weight: 700; cursor: pointer; transition: all .15s; font-family: 'Inter', sans-serif; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: #00266A; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text2); margin-top: 8px; }
.btn-outline:active { background: var(--surface2); }

/* TOAST */
.toast {
  position: fixed; top: calc(var(--nav-h) + 8px); left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; font-weight: 500; z-index: 300; opacity: 0;
  transition: opacity .2s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }

/* BADGE */
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; padding: 0 5px; }

/* EMPTY STATE */
.empty { text-align: center; padding: 48px 20px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-text { font-size: 14px; color: var(--text2); }

/* MISC */
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.row { display: flex; gap: 8px; }
.row .field { flex: 1; }

/* BOTONES DE ACCIÓN EN TARJETAS */
.sale-header > div:last-child, .inv-card .acciones, .client-card .acciones {
  display: flex;
  gap: 4px;
  align-items: center;
}
.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  color: var(--text3);
}
.btn-icon:hover { background: var(--surface2); }
.btn-icon.danger:hover { background: var(--red-soft); color: var(--red); }
.btn-icon.edit:hover { background: var(--primary-soft); color: var(--primary); }

/* Estilos extra para módulo cliente */
#screen-cliente .inv-card {
  cursor: default;
}
#screen-cliente .inv-card .btn {
  height: 36px;
  font-size: 12px;
  padding: 0 12px;
}
#cliente-panel h2 {
  font-size: 20px;
}

#screen-configuracion .card {
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border-color, #e5e7eb);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ============================================================
   CONFIGURACIÓN - GESTIÓN DE DATOS
   ============================================================ */
#screen-configuracion {
  padding: 16px;
  padding-bottom: 80px;
}

.config-container {
  max-width: 1200px;
  margin: 0 auto;
}

.config-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.config-header h2 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.config-sub {
  font-size: 14px;
  color: var(--text-secondary, #64748b);
  margin: 4px 0 0;
}

.config-user {
  text-align: right;
  font-size: 14px;
}

.config-empresa {
  display: block;
  font-weight: 700;
  color: var(--text-primary);
}

.config-usuario {
  display: block;
  color: var(--text-secondary, #64748b);
}

/* TABS */
.config-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-secondary, #f1f5f9);
  border-radius: 12px;
  padding: 4px;
}

.config-tab {
  flex: 1 1 auto;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary, #64748b);
  cursor: pointer;
  transition: 0.2s;
  text-align: center;
}

.config-tab:hover {
  background: rgba(255,255,255,0.5);
  color: var(--text-primary);
}

.config-tab.active {
  background: var(--bg-primary, white);
  color: var(--accent-color, #2c7be5);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* PANELES */
.config-panel {
  display: none;
  animation: fadeIn 0.3s ease;
}

.config-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* TARJETAS DE RESUMEN */
.config-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.config-card {
  background: var(--bg-primary, white);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.config-card-icon {
  font-size: 28px;
  margin-bottom: 6px;
}

.config-card-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.config-card-label {
  font-size: 13px;
  color: var(--text-secondary, #64748b);
}

/* TOOLBAR */
.config-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.config-toolbar h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

/* TABLA */
.config-table-wrap {
  overflow-x: auto;
  background: var(--bg-primary, white);
  border-radius: 12px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.config-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.config-table thead {
  background: var(--bg-secondary, #f8fafc);
}

.config-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary, #475569);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.config-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #f1f5f9);
  color: var(--text-primary);
}

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

.config-empty {
  text-align: center !important;
  color: var(--text-secondary, #94a3b8);
  padding: 30px 16px !important;
}

/* BOTONES DE ACCIÓN EN TABLA */
.config-actions-cell {
  display: flex;
  gap: 6px;
}

.config-actions-cell .btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: 0.2s;
}

.btn-sm-edit {
  background: #dbeafe;
  color: #1e40af;
}
.btn-sm-edit:hover {
  background: #bfdbfe;
}

.btn-sm-delete {
  background: #fee2e2;
  color: #991b1b;
}
.btn-sm-delete:hover {
  background: #fecaca;
}

/* JSON SECTION */
.config-json-section {
  background: var(--bg-primary, white);
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.config-json-section h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
}

.config-hint {
  font-size: 14px;
  color: var(--text-secondary, #64748b);
  margin-bottom: 16px;
}

.config-json-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.config-json-buttons .btn {
  flex: 1 1 auto;
  min-width: 160px;
}

/* BOTONES GENERALES */
.config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

.config-actions .btn {
  flex: 1 1 auto;
  min-width: 160px;
}

/* RESPONSIVE */
@media (max-width: 600px) {
  .config-header {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .config-user {
    text-align: center;
  }
  .config-tabs {
    flex-wrap: wrap;
  }
  .config-tab {
    flex: 1 1 45%;
    font-size: 13px;
    padding: 8px 10px;
  }
  .config-cards {
    grid-template-columns: 1fr 1fr;
  }
  .config-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .config-toolbar .btn {
    width: 100%;
  }
}

/* ==================== PANTALLA DE BIENVENIDA ==================== */
#screen-bienvenida {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--primary-soft) 100%);
}

.welcome-container {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.welcome-logo {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.welcome-logo-icon {
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: white;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.welcome-logo span { color: var(--text); }

.welcome-subtitle {
  font-size: 15px;
  color: var(--text2);
  margin-bottom: 32px;
}

.welcome-options {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.welcome-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
}

.welcome-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  border-color: var(--primary-soft);
}

.welcome-card-cliente:hover {
  border-color: var(--green-soft);
}

.welcome-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.welcome-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.welcome-desc {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.5;
  margin-bottom: 16px;
}

.welcome-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.welcome-btn.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text2);
}

.divider-o {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text3);
  font-size: 13px;
  font-weight: 600;
}

.divider-o::before,
.divider-o::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.welcome-login {
  font-size: 14px;
  color: var(--text2);
}

.welcome-login span {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.welcome-footer {
  margin-top: 32px;
  font-size: 12px;
  color: var(--text3);
}

/* Modales de registro */
#modal-registro-empresa,
#modal-registro-cliente,
#modal-login,
#modal-codigo {
  z-index: 250;
}

/* NUCLEAR: cualquier modal sin .open debe estar OCULTO */
.modal-overlay:not(.open) {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* ============================================================
   REGLAS NUCLEAR PARA CIERRE DE MODALES
   ============================================================ */

/* Modales de registro: z-index superior */
#modal-registro-empresa,
#modal-registro-cliente,
#modal-login,
#modal-codigo {
  z-index: 250;
}

/* CUALQUIER modal-overlay sin .open debe estar COMPLETAMENTE OCULTO */
.modal-overlay:not(.open) {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  position: fixed !important;
  top: -9999px !important;
  left: -9999px !important;
  z-index: -9999 !important;
}

/* Prevención: si algo fuerza display:flex con !important, anularlo */
.modal-overlay:not(.open)[style*="display: flex"],
.modal-overlay:not(.open)[style*="display:flex"] {
  display: none !important;
}

/* Animación de entrada solo cuando tiene .open */
.modal-overlay.open .modal-sheet {
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==================== MODAL DE DESPACHO ==================== */
#modal-despacho .modal-sheet {
  max-height: 85vh;
}

.alertas-cliente {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 16px;
  border-left: 4px solid var(--green);
}

.alertas-cliente.alerta-roja {
  border-left-color: var(--red);
}

.alertas-cliente.alerta-amarilla {
  border-left-color: var(--amber);
}

.alertas-cliente .alerta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 4px 0;
}

.alertas-cliente .alerta-item .icono {
  font-size: 18px;
}

.alertas-cliente .alerta-item.rojo {
  color: var(--red);
}

.alertas-cliente .alerta-item.amarillo {
  color: var(--amber);
}

.alertas-cliente .alerta-item.verde {
  color: var(--green);
}

.tabla-envases-despacho {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

.tabla-envases-despacho th {
  background: var(--bg-secondary);
  padding: 8px 6px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.tabla-envases-despacho td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tabla-envases-despacho input[type="number"] {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.tabla-envases-despacho .saldo-display {
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}

.tabla-envases-despacho .saldo-positivo {
  color: var(--green);
}

.tabla-envases-despacho .saldo-negativo {
  color: var(--red);
}

/* Resumen de productos en el modal */
.resumen-productos-despacho {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 14px;
}

.resumen-productos-despacho .producto-item {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}

.resumen-productos-despacho .producto-item:last-child {
  border-bottom: none;
}

/* ============================================================
   CATEGORÍAS
   ============================================================ */
#panel-categorias .config-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

#panel-categorias .config-toolbar h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

/* Badge de estado */
.categoria-estado {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.categoria-estado.activa {
  background: var(--green-soft);
  color: var(--green);
}
.categoria-estado.inactiva {
  background: var(--red-soft);
  color: var(--red);
}

/* Botones en tabla de categorías */
.config-actions-cell .btn-sm-toggle {
  background: #f3f4f6;
  color: #374151;
}
.config-actions-cell .btn-sm-toggle:hover {
  background: #e5e7eb;
}
.config-actions-cell .btn-sm-toggle.activa {
  background: #dbeafe;
  color: #1e40af;
}
.config-actions-cell .btn-sm-toggle.inactiva {
  background: #fee2e2;
  color: #991b1b;
}


/* ============================================================
   LIQUIDACIONES (NUEVO)
   ============================================================ */
#historial-liquidaciones .sale-card {
  cursor: default;
}
.liquidacion-cantidad {
  font-weight: 700;
  color: var(--green);
}
.liquidacion-producto {
  font-size: 13px;
  color: var(--text2);
}
.liquidacion-observaciones {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
}

/* ================================================================
   AGENTE FLOTANTE (COMPACTO Y ARRASTRABLE)
   ================================================================ */

#chat-toggle {
  position: fixed;
  bottom: 90px;
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #00338D;
  color: white;
  font-size: 20px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,51,141,0.3);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  touch-action: none;
}

#chat-toggle:active {
  transform: scale(0.9);
}

.agent-panel {
  display: none;
  position: fixed;
  bottom: 150px;
  right: 16px;
  width: 300px;
  max-height: 400px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  z-index: 160;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-direction: column;
}

.agent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #00338D;
  color: white;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.agent-header:active {
  cursor: grabbing;
}

.agent-messages {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
  max-height: 260px;
  min-height: 120px;
  background: var(--bg);
}

.agent-input-area {
  padding: 6px 8px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
  align-items: center;
}

.agent-mic-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text2);
  padding: 2px 4px;
}

.agent-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.agent-send-btn {
  background: #00338D;
  color: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mensajes tipo burbuja */
.chat-bubble {
  display: flex;
  margin-bottom: 6px;
}

.chat-bubble.user {
  justify-content: flex-end;
}

.chat-bubble.agent {
  justify-content: flex-start;
}

.chat-bubble-inner {
  max-width: 85%;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 13px;
  word-wrap: break-word;
  line-height: 1.4;
}

.chat-bubble.user .chat-bubble-inner {
  background: #00338D;
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble.agent .chat-bubble-inner {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* RESPONSIVE: en pantallas pequeñas, el panel se hace más compacto */
@media (max-width: 500px) {
  .agent-panel {
    width: 280px;
    max-height: 350px;
  }
  
  .agent-messages {
    max-height: 220px;
  }
  
  #chat-toggle {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
}
