/* ── Variables ────────────────────────────────────────────────── */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f7f8fa;
  --border: #e2e6ea;
  --text: #1a1d23;
  --text2: #6b7280;
  --accent: #2563eb;
  --accent-h: #1d4ed8;
  --accent-light: #dbeafe;
  --green: #059669;
  --red: #dc2626;
  --yellow: #d97706;
  --purple: #7c3aed;
  --sidebar-w: 230px;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --transition: .18s ease;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d26;
  --surface2: #22263a;
  --border: #2e3347;
  --text: #e8eaf0;
  --text2: #8b92a8;
  --accent: #3b82f6;
  --accent-h: #60a5fa;
  --accent-light: #1e3a5f;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --purple: #a78bfa;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; transition: background var(--transition), color var(--transition); }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Login ────────────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f1117 100%);
}
.login-card {
  background: var(--surface); border-radius: 18px; padding: 48px 40px;
  width: 380px; box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center; margin-bottom: 32px;
}
.login-logo .logo-icon {
  width: 56px; height: 56px; background: var(--accent);
  border-radius: 14px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 28px; margin-bottom: 12px;
}
.login-logo h1 { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.login-logo p { color: var(--text2); font-size: 13px; margin-top: 4px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius); background: var(--surface2); color: var(--text);
  font-size: 14px; outline: none; transition: border var(--transition);
  margin-bottom: 16px;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .error { color: var(--red); font-size: 13px; margin-bottom: 12px; display: none; }
.btn-primary {
  width: 100%; padding: 12px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); font-size: 15px; font-weight: 600;
  transition: background var(--transition), transform .1s;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { transform: scale(.98); }

/* ── App Shell ────────────────────────────────────────────────── */
#app { display: none; }
#app.visible { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100; transition: background var(--transition), transform .25s;
}
.sidebar-brand {
  padding: 20px 18px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.brand-icon {
  width: 36px; height: 36px; background: var(--accent); border-radius: 9px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; flex-shrink: 0;
}
.brand-text { font-weight: 700; font-size: 15px; letter-spacing: -.3px; }
.brand-sub { font-size: 11px; color: var(--text2); }

nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section { font-size: 10px; font-weight: 600; color: var(--text2); text-transform: uppercase;
  letter-spacing: .8px; padding: 10px 8px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--text2);
  cursor: pointer; transition: all var(--transition); margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.nav-item .icon { width: 18px; text-align: center; font-size: 16px; }

.sidebar-footer {
  padding: 12px 10px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.footer-user { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 6px; }
.avatar { width: 28px; height: 28px; background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; }
.btn-icon {
  background: none; border: none; padding: 6px 8px; border-radius: 7px;
  color: var(--text2); font-size: 16px; transition: all var(--transition);
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }

/* ── Main ─────────────────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}
.topbar {
  height: 58px; flex-shrink: 0; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 12px; z-index: 50;
}
.topbar h2 { font-size: 17px; font-weight: 700; flex: 1; }
.topbar .badge { background: var(--accent-light); color: var(--accent); font-size: 11px;
  font-weight: 600; padding: 3px 8px; border-radius: 20px; }

.content { padding: 24px; flex: 1; overflow-y: auto; overflow-x: hidden; }

/* ── Cards / Stats ────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.stat-card .stat-label { font-size: 12px; color: var(--text2); font-weight: 500; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; letter-spacing: -1px; }
.stat-card .stat-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }
.stat-green .stat-value { color: var(--green); }
.stat-red .stat-value { color: var(--red); }
.stat-blue .stat-value { color: var(--accent); }

/* ── Table ────────────────────────────────────────────────────── */
.table-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border); overflow: hidden;
}
.table-header {
  padding: 16px 20px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
}
.table-header h3 { font-size: 15px; font-weight: 600; flex: 1; }
.search-input {
  padding: 7px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface2); color: var(--text); font-size: 13px; outline: none;
  transition: border var(--transition); width: 200px;
}
.search-input:focus { border-color: var(--accent); }

.btn-add {
  padding: 8px 16px; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px;
  transition: background var(--transition);
}
.btn-add:hover { background: var(--accent-h); }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 11px 16px; font-size: 11.5px; font-weight: 600;
  color: var(--text2); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border); background: var(--surface2);
}
td { padding: 12px 16px; font-size: 13.5px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

.tag {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tag-green { background: #d1fae5; color: #065f46; }
.tag-red { background: #fee2e2; color: #991b1b; }
.tag-blue { background: #dbeafe; color: #1e40af; }
.tag-yellow { background: #fef3c7; color: #92400e; }
.tag-purple { background: #ede9fe; color: #5b21b6; }
.tag-gray { background: var(--surface2); color: var(--text2); }
.tag-pink { background: #fce7f3; color: #9d174d; }
[data-theme="dark"] .tag-green { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .tag-red { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .tag-blue { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .tag-yellow { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .tag-purple { background: #4c1d95; color: #c4b5fd; }
[data-theme="dark"] .tag-pink { background: #831843; color: #fbcfe8; }

.cal-event.ev-exclusividad { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .cal-event.ev-exclusividad { background: #78350f; color: #fcd34d; }
.cal-week-event.ev-exclusividad { background: #f59e0b; color: #fff; }

.action-btns { display: flex; gap: 4px; }
.btn-sm {
  padding: 5px 10px; border: 1.5px solid var(--border); border-radius: 7px;
  background: none; color: var(--text2); font-size: 12px; font-weight: 500;
  transition: all var(--transition);
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm.danger:hover { border-color: var(--red); color: var(--red); }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity var(--transition);
}
.modal-overlay.show { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  transform: translateY(16px); transition: transform var(--transition);
}
.modal-overlay.show .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; border-radius: 14px 14px 0 0;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0; border-radius: 0 0 14px 14px;
  background: var(--surface);
}

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; background: var(--surface2); color: var(--text); font-size: 14px;
  outline: none; transition: border var(--transition);
}
.form-control:focus { border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.btn-cancel {
  padding: 9px 20px; border: 1.5px solid var(--border); border-radius: 8px;
  background: none; color: var(--text); font-size: 14px; font-weight: 500;
  transition: all var(--transition);
}
.btn-cancel:hover { background: var(--surface2); }
.btn-save {
  padding: 9px 24px; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; font-size: 14px; font-weight: 600; transition: background var(--transition);
}
.btn-save:hover { background: var(--accent-h); }

/* ── Kanban ───────────────────────────────────────────────────── */
.kanban-board {
  display: flex; gap: 16px; overflow-x: auto; overflow-y: hidden;
  padding-bottom: 16px; flex: 1;
}
.kanban-col {
  min-width: 260px; max-width: 280px; flex-shrink: 0;
  background: var(--surface2); border-radius: var(--radius);
  border: 1px solid var(--border); display: flex; flex-direction: column;
}
.kanban-col-header {
  padding: 12px 14px; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border);
}
.kanban-col-header .col-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.kanban-col-header .col-count { margin-left: auto; font-size: 12px; color: var(--text2); font-weight: 500; }
.kanban-cards { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 80px; }
.kanban-card {
  background: var(--surface); border-radius: 9px; padding: 12px 14px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  cursor: grab; transition: box-shadow var(--transition), transform var(--transition);
  user-select: none;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: .5; transform: scale(.98); }
.kanban-card.drag-over { border: 2px dashed var(--accent); }
.kanban-col.drag-target { background: var(--accent-light); }
.k-address { font-size: 13.5px; font-weight: 600; margin-bottom: 6px; line-height: 1.3; }
.k-meta { font-size: 11.5px; color: var(--text2); display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.k-price { font-size: 13px; font-weight: 700; color: var(--green); }

/* ── Price history panel ──────────────────────────────────────── */
.price-history { margin-top: 16px; }
.price-entry {
  display: flex; align-items: center; gap: 12px; padding: 8px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.price-entry:last-child { border-bottom: none; }
.price-entry .p-val { font-weight: 700; color: var(--accent); }
.price-entry .p-date { color: var(--text2); font-size: 12px; }

/* ── Empty / Loading ──────────────────────────────────────────── */
.empty {
  text-align: center; padding: 60px 20px; color: var(--text2);
}
.empty .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty p { font-size: 14px; }

.loading { text-align: center; padding: 40px; color: var(--text2); font-size: 14px; }

/* ── Toast ────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 18px; font-size: 13.5px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px; min-width: 220px;
  animation: slideIn .25s ease; border-left: 4px solid var(--green);
}
.toast.error { border-left-color: var(--red); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── Responsive ───────────────────────────────────────────────── */
/* ── Hamburger button ─────────────────────────────────────── */
.btn-hamburger {
  display: none; /* shown via media query on mobile */
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 40px; height: 40px; padding: 0;
  background: transparent; border: none; cursor: pointer; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.btn-hamburger span {
  display: block; width: 22px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: all 0.2s;
}

/* ── Sidebar overlay ──────────────────────────────────────── */
#sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.45); z-index: 149;
}
#sidebar-overlay.active { display: block; }

/* ── MOBILE ────────────────────────────────────────────────── */
/* ════════════════════════════════════════════════════════
   RESPONSIVE — Mobile first
   ════════════════════════════════════════════════════════ */



/* ── Tablets y móviles (< 768px) ────────────────────── */
@media (max-width: 768px) {

  /* ── Sidebar deslizable ── */
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 150;
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 270px !important;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay.active { display: block; }
  #main { margin-left: 0 !important; }
  .btn-hamburger { display: flex; }

  /* ── Topbar ── */
  .topbar { padding: 0 14px; height: 54px; }
  .topbar h2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw; }

  /* ── Content ── */
  .content { padding: 12px 10px; }

  /* ── Stats: 2 col en tablet, 1 col en móvil pequeño ── */
  .stats-row { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; margin-bottom: 14px; }
  .stat-card { padding: 12px 10px; }
  .stat-value { font-size: 20px !important; }
  .stat-label { font-size: 11px !important; }

  /* ── Dashboard grid → columna única ── */
  #page-content > div[style*="grid-template-columns:1fr 1fr 1fr"],
  #page-content > div[style*="grid-template-columns: 1fr 1fr 1fr"],
  #page-content > div[style*="grid-template-columns:1fr 1fr"],
  #page-content > div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Tablas ── */
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
  table { min-width: 520px; font-size: 12px; }
  th, td { padding: 8px 9px; white-space: nowrap; }
  .col-hide-mobile { display: none !important; }
  .table-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .table-header h3 { font-size: 14px; }

  /* ── Filtros de búsqueda en tablas ── */
  .filter-row { flex-wrap: wrap; gap: 6px; }
  .filter-row .form-control { font-size: 14px; min-width: 0; flex: 1 1 120px; }

  /* ── Formularios ── */
  .form-row,
  .form-row-3 { grid-template-columns: 1fr !important; gap: 10px; }
  .form-group { width: 100% !important; }
  .form-control { font-size: 16px !important; } /* evita zoom en iOS */
  select.form-control { font-size: 16px !important; }
  label { font-size: 13px; }

  /* ── Modal bottom sheet ── */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    top: auto !important;
    max-height: 92vh;
    /* handle visual */
  }
  .modal::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 0;
  }
  .modal-header { padding: 10px 18px 12px; }
  .modal-body { padding: 14px 16px; }
  .modal-footer { padding: 10px 16px 18px; gap: 8px; }
  .modal-footer .btn-save,
  .modal-footer .btn-cancel { flex: 1; text-align: center; padding: 11px; font-size: 14px; }

  /* ── Kanban ── */
  .kanban-board { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
  .kanban-col { min-width: 220px; max-width: 240px; flex-shrink: 0; }
  .kanban-card { font-size: 12px; }

  /* ── Calendario ── */
  .cal-header { flex-wrap: wrap; gap: 6px; padding: 10px 10px 8px; }
  .cal-header h2 { font-size: 14px; flex: 1 1 100%; order: -1; text-align: center; }
  .cal-header-nav { gap: 4px; }
  .cal-view-btns .btn-cal { font-size: 11px; padding: 4px 8px; }
  .btn-add[onclick*="openEventModal"] { font-size: 12px; padding: 6px 10px; }
  /* Vista mes: texto de eventos más pequeño */
  .cal-event { font-size: 10px; padding: 1px 4px; }
  /* Vista semana: columnas más angostas */
  .cal-week-grid { font-size: 11px; }
  .cal-week-time { width: 36px; font-size: 10px; }

  /* ── Chat ── */
  .chat-sidebar { display: none; }
  .chat-main { border-radius: 0; }
  .chat-input-row { padding: 8px 10px; gap: 6px; }
  .chat-input { font-size: 15px; }

  /* ── Botones ── */
  .btn-add { font-size: 13px; padding: 7px 13px; }
  .btn-sm { font-size: 11px; padding: 4px 8px; }
  .tag { font-size: 10px; padding: 2px 7px; }

  /* ── Balance filtros ── */
  #bal-filters { flex-wrap: wrap; gap: 6px; }
  #bal-filters .form-control { flex: 1 1 120px; min-width: 0; }
}

/* ── Móviles pequeños (< 480px) ─────────────────────── */
@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr !important; gap: 8px; }
  .stat-value { font-size: 18px !important; }

  /* Topbar más compacto */
  .topbar { height: 50px; }
  .topbar h2 { font-size: 14px; }

  /* Calendario: forzar vista día en pantallas chicas */
  .cal-view-btns .btn-cal[onclick*="mes"] { display: none; }
  .cal-week-time { display: none; }
  .cal-event { max-width: 100%; }

  /* Modal casi pantalla completa */
  .modal { max-height: 96vh; }

  /* Balance stats en 2 col */
  #bal-stats { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
}

/* ── Pantallas muy pequeñas (< 360px) ───────────────── */
@media (max-width: 360px) {
  .stats-row { grid-template-columns: 1fr !important; }
  .content { padding: 8px 6px; }
  .topbar h2 { font-size: 13px; }
}

/* ── Chat ─────────────────────────────────────────────────────── */
#chat-panel-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 32px; flex-shrink: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 0 8px 8px 0; cursor: pointer; font-size: 15px;
  color: var(--text2); transition: background .15s;
  writing-mode: vertical-rl;
  padding: 12px 6px; letter-spacing: 1px;
}
#chat-panel-toggle:hover { background: var(--accent-light); color: var(--accent); }

.chat-wrap {
  display: flex; flex: 1; height: 100%; overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
  width: 240px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding: 18px 14px;
  display: flex; flex-direction: column; gap: 8px; overflow-y: auto;
}
.chat-sidebar-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text2); margin-top: 4px;
}
.chat-memory-text {
  font-size: 12px; color: var(--text2); line-height: 1.5;
  background: var(--surface2); border-radius: 8px; padding: 10px;
  min-height: 48px; max-height: 220px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}
.chat-sidebar-actions { display: flex; flex-direction: column; gap: 6px; }
.chat-examples { display: flex; flex-direction: column; gap: 4px; }
.chat-example {
  font-size: 12px; color: var(--accent); padding: 7px 10px;
  background: var(--accent-light); border-radius: 7px; cursor: pointer;
  transition: opacity var(--transition); line-height: 1.3;
}
.chat-example:hover { opacity: .75; }

/* Main */
.chat-main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 24px 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }

.chat-bubble {
  max-width: 72%; padding: 12px 16px; border-radius: 14px;
  font-size: 14px; line-height: 1.55; word-break: break-word;
}
.chat-msg.user .chat-bubble {
  background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.chat-bubble code {
  background: var(--surface2); padding: 1px 5px; border-radius: 4px;
  font-family: monospace; font-size: 13px;
}

/* Typing indicator */
.chat-typing-indicator {
  display: flex; gap: 5px; align-items: center; padding: 14px 18px;
}
.chat-typing-indicator span {
  width: 7px; height: 7px; background: var(--text2); border-radius: 50%;
  animation: typing-bounce .9s infinite ease-in-out;
}
.chat-typing-indicator span:nth-child(2) { animation-delay: .15s; }
.chat-typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Input */
.chat-input-area {
  padding: 14px 16px; border-top: 1px solid var(--border);
  background: var(--surface); display: flex; gap: 10px; align-items: flex-end;
}
.chat-input {
  flex: 1; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; background: var(--surface2); color: var(--text);
  font-size: 14px; outline: none; resize: none; line-height: 1.4;
  transition: border var(--transition); max-height: 120px; overflow-y: auto;
  font-family: inherit;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
  width: 40px; height: 40px; background: var(--accent); color: #fff;
  border: none; border-radius: 10px; font-size: 16px; flex-shrink: 0;
  transition: background var(--transition); display: flex;
  align-items: center; justify-content: center;
}
.chat-send:hover:not(:disabled) { background: var(--accent-h); }
.chat-send:disabled { opacity: .5; cursor: not-allowed; }

/* Mic button — expands when recording */
.chat-mic {
  height: 40px; width: 40px; border-radius: 20px;
  background: var(--surface2); border: 1.5px solid var(--border);
  color: var(--text2); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; gap: 0; padding: 0;
  transition: width .3s cubic-bezier(.4,0,.2,1), border-radius .3s cubic-bezier(.4,0,.2,1),
              background .2s, border-color .2s, color .2s, gap .3s, padding .3s;
  overflow: hidden; white-space: nowrap;
  font-size: 18px; user-select: none; -webkit-user-select: none;
}
.chat-mic:hover { border-color: var(--accent); }
.chat-mic.recording {
  width: 148px; background: #ef4444; border-color: #ef4444; color: #fff;
  gap: 7px; padding: 0 14px 0 10px; justify-content: flex-start;
  animation: micGlow .9s ease-in-out infinite;
}
.chat-mic svg { width: 18px; height: 18px; flex-shrink: 0; }
.chat-mic.recording svg { animation: micPulse .7s ease-in-out infinite; }
.mic-label {
  font-size: 13px; font-weight: 600; letter-spacing: .01em;
  max-width: 0; opacity: 0; overflow: hidden;
  transition: max-width .3s cubic-bezier(.4,0,.2,1), opacity .2s .1s;
}
.chat-mic.recording .mic-label { max-width: 100px; opacity: 1; }
@keyframes micGlow {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
  50%      { box-shadow: 0 0 0 7px rgba(239,68,68,0); }
}
@keyframes micPulse {
  0%,100% { transform: scale(1);    opacity: 1; }
  50%      { transform: scale(1.25); opacity: .5; }
}

/* ── Agenda / Calendar ───────────────────────────────────────────── */
.cal-wrap {
  display: flex; flex-direction: column; height: 100%; overflow: hidden;
}
.cal-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
.cal-toolbar h3 { font-size: 16px; font-weight: 700; flex: 1; min-width: 160px; }
.cal-nav { display: flex; gap: 4px; }
.cal-nav button {
  padding: 6px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  background: none; color: var(--text); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
}
.cal-nav button:hover { border-color: var(--accent); color: var(--accent); }
.cal-nav button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.cal-body { flex: 1; overflow: auto; padding: 0; }

/* Month */
.cal-month { display: flex; flex-direction: column; height: 100%; }
.cal-month-head {
  display: grid; grid-template-columns: repeat(7,1fr);
  background: var(--surface2); border-bottom: 1px solid var(--border);
}
.cal-month-head span {
  text-align: center; padding: 8px 0; font-size: 11.5px;
  font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px;
}
.cal-month-grid {
  display: grid; grid-template-columns: repeat(7,1fr);
  grid-auto-rows: minmax(90px, 1fr); flex: 1;
}
.cal-day {
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 6px; min-height: 90px; cursor: pointer; transition: background var(--transition);
  overflow: hidden;
}
.cal-day:hover { background: var(--surface2); }
.cal-day.other-month { opacity: .35; }
.cal-day.today .cal-day-num {
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
}
.cal-day-num { font-size: 12px; font-weight: 600; margin-bottom: 4px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.cal-event {
  font-size: 11px; padding: 2px 6px; border-radius: 4px; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
  font-weight: 500; line-height: 1.6;
}
.cal-event.ev-agenda  { background: #dbeafe; color: #1e40af; }
.cal-event.ev-birthday { background: #fce7f3; color: #9d174d; }
.cal-event.ev-visit   { background: #d1fae5; color: #065f46; }
[data-theme="dark"] .cal-event.ev-agenda   { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .cal-event.ev-birthday { background: #831843; color: #fbcfe8; }
[data-theme="dark"] .cal-event.ev-visit    { background: #064e3b; color: #6ee7b7; }

/* Week */
.cal-week { display: flex; flex-direction: column; height: 100%; min-width: 600px; }
.cal-week-head {
  display: grid; grid-template-columns: 52px repeat(7,1fr);
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.cal-week-head-cell {
  text-align: center; padding: 8px 4px; border-left: 1px solid var(--border);
}
.cal-week-head-cell .wday { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.cal-week-head-cell .wnum { font-size: 20px; font-weight: 700; }
.cal-week-head-cell.today .wnum {
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
}
.cal-week-body { flex: 1; overflow-y: auto; display: flex; }
.cal-week-times { width: 52px; flex-shrink: 0; }
.cal-week-times div {
  height: 48px; font-size: 10px; color: var(--text2); text-align: right;
  padding-right: 6px; line-height: 0; position: relative; top: -6px;
}
.cal-week-cols { flex: 1; display: grid; grid-template-columns: repeat(7,1fr); position: relative; }
.cal-week-col {
  border-left: 1px solid var(--border); position: relative;
}
.cal-week-col-hour {
  height: 48px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--transition);
}
.cal-week-col-hour:hover { background: var(--accent-light); }
.cal-week-event {
  position: absolute; left: 2px; right: 2px; border-radius: 5px; padding: 2px 5px;
  font-size: 11px; font-weight: 600; overflow: hidden; cursor: pointer; z-index: 1;
  line-height: 1.3;
}
.cal-week-event.ev-agenda   { background: #3b82f6; color: #fff; }
.cal-week-event.ev-birthday  { background: #ec4899; color: #fff; }
.cal-week-event.ev-visit     { background: #10b981; color: #fff; }
.cal-week-allday-row {
  display: grid; grid-template-columns: 52px repeat(7,1fr);
  border-bottom: 2px solid var(--border); background: var(--surface2); flex-shrink: 0;
}
.cal-week-allday-label {
  font-size: 10px; color: var(--text2); padding: 4px 6px; text-align: right; align-self: center;
}
.cal-week-allday-cell {
  border-left: 1px solid var(--border); padding: 2px 3px; min-height: 24px;
}

/* Day */
.cal-day-view { display: flex; flex-direction: column; height: 100%; }
.cal-day-head {
  text-align: center; padding: 12px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.cal-day-head .dname { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; font-weight:600; }
.cal-day-head .dnum  { font-size: 32px; font-weight: 700; }
.cal-day-body { flex: 1; overflow-y: auto; display: flex; }
.cal-day-times { width: 52px; flex-shrink: 0; }
.cal-day-times div { height: 48px; font-size: 10px; color: var(--text2); text-align: right; padding-right: 6px; line-height: 0; position: relative; top: -6px; }
.cal-day-col { flex: 1; border-left: 1px solid var(--border); position: relative; }
.cal-day-col-hour { height: 48px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--transition); }
.cal-day-col-hour:hover { background: var(--accent-light); }

/* ════════════════════════════════════════════════════════
   BOTTOM NAV — solo mobile
   ════════════════════════════════════════════════════════ */
#mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 60px; background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100; padding: 0 4px;
  align-items: center; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
}

@media (max-width: 768px) {
  #mobile-nav { display: flex; }
  /* Espacio para la bottom nav */
  .content { padding-bottom: 70px !important; }
  /* Ocultar sidebar en mobile — solo usamos bottom nav */
  .btn-hamburger { display: none !important; }
}

.mobile-nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; flex: 1; height: 100%; border: none; background: transparent;
  color: var(--text2); cursor: pointer; padding: 6px 4px;
  border-radius: 8px; transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  font-size: 10px; font-weight: 500;
}
.mobile-nav-btn span { font-size: 10px; font-weight: 500; }
.mobile-nav-btn.active { color: var(--accent); }
.mobile-nav-btn svg { flex-shrink: 0; }

/* Sheet "Más" */
#mobile-more-sheet {
  position: fixed; bottom: 60px; left: 0; right: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  z-index: 300; padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%);
  animation: slideUp .25s ease forwards;
}
@keyframes slideUp { to { transform: translateY(0); } }

.mobile-more-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 10px; padding: 16px 14px 20px;
}
.mobile-more-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 14px 8px; border-radius: 12px;
  background: var(--surface2); border: none;
  color: var(--text); cursor: pointer; font-size: 13px; font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
.mobile-more-item span { font-size: 11px; }
.mobile-more-item:active { opacity: .7; }
/* ── Cobranzas toggle buttons ─────────────────────────────────── */
.btn-toggle-estado {
  border: none; border-radius: 20px; padding: 5px 14px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn-toggle-estado:active { transform: scale(.96); }
.btn-toggle-pend {
  background: #fef3c7; color: #92400e;
}
.btn-toggle-pend:hover { background: #fde68a; }
.btn-toggle-cob {
  background: #d1fae5; color: #065f46;
}
.btn-toggle-cob:hover { background: #a7f3d0; }
.btn-toggle-estado:disabled { opacity: .5; cursor: wait; }
.stat-yellow { border-top: 3px solid #f59e0b; }