:root {
      --primary: #1e3c72;
      --primary-light: #0284c7;
      --bg-main: #f1f5f9;
      --text-dark: #1e293b;
      --text-muted: #64748b;
      --success: #10b981;
      --whatsapp: #25d366;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: Arial, sans-serif;
      background-color: var(--bg-main);
      color: var(--text-dark);
      display: flex;
      height: 100vh;
      overflow: hidden;
    }

    .splash-screen {
      position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
      background-color: #090f1c; z-index: 99999;
      display: flex; flex-direction: column; justify-content: center; align-items: center;
      transition: opacity 0.8s ease, visibility 0.8s ease;
    }
    .splash-screen.fade-out { opacity: 0; visibility: hidden; pointer-events: none; }
    .splash-title {
      font-size: 3.8rem; font-weight: 900; color: white; letter-spacing: 6px;
      text-transform: uppercase; margin-bottom: 12px; opacity: 0;
      animation: flickerIntro 2.2s forwards cubic-bezier(0.11, 0.83, 0.43, 1.01);
    }
    .splash-title span { color: #38bdf8; text-shadow: 0 0 20px rgba(56, 189, 248, 0.6); }
    .splash-subtitle {
      font-size: 0.9rem; color: #64748b; font-weight: bold; letter-spacing: 3px;
      text-transform: uppercase; opacity: 0;
      animation: fadeInSubtitle 1.4s 1.2s forwards ease-in-out;
    }
    .splash-subtitle strong { color: #94a3b8; font-weight: bold; }
    @keyframes flickerIntro {
      0% { opacity: 0; transform: scale(0.93); filter: blur(8px); }
      25% { opacity: 0.4; filter: blur(3px); }
      30% { opacity: 0.1; }
      35% { opacity: 0.85; filter: none; }
      42% { opacity: 0.4; }
      100% { opacity: 1; transform: scale(1); filter: drop-shadow(0 0 25px rgba(56, 189, 248, 0.3)); }
    }
    @keyframes fadeInSubtitle {
      from { opacity: 0; transform: translateY(8px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .mobile-navbar {
      display: none;
      background-color: var(--primary);
      color: white;
      padding: 12px 20px;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid rgba(255,255,255,0.1);
      box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }
    .mobile-brand { font-size: 1.2rem; font-weight: bold; letter-spacing: 1px; }
    .mobile-brand span { color: #38bdf8; }
    .burger-btn {
      background: none; border: none; cursor: pointer;
      display: flex; flex-direction: column; gap: 5px; padding: 5px;
    }
    .burger-btn span { display: block; width: 24px; height: 3px; background-color: white; border-radius: 2px; transition: all 0.3s ease; }
    .burger-btn.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 6px); }
    .burger-btn.open span:nth-child(2) { opacity: 0; }
    .burger-btn.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -6px); }

    .sidebar-overlay {
      display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
      background: rgba(0,0,0,0.5); z-index: 9998; opacity: 0; transition: opacity 0.3s ease;
    }
    .sidebar-overlay.show { display: block; opacity: 1; }

    .sidebar {
      width: 260px; background-color: var(--primary); color: white;
      display: flex; flex-direction: column; padding: 20px 10px;
      box-shadow: 4px 0 10px rgba(0,0,0,0.1); z-index: 9999;
      overflow-y: auto;
    }
    .sidebar-brand {
      font-size: 1.25rem; font-weight: bold; text-align: center;
      margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.1); letter-spacing: 1px;
    }
    .sidebar-brand span { color: #38bdf8; }

    .search-container { position: relative; margin-bottom: 20px; }
    #search-input {
      width: 100%; padding: 10px 12px; border: 1px solid rgba(255,255,255,0.2);
      background-color: rgba(0,0,0,0.25); color: white; border-radius: 6px; font-size: 0.85rem;
    }
    #search-input::placeholder { color: #94a3b8; }
    #search-input:focus { outline: none; border-color: #38bdf8; background-color: rgba(0,0,0,0.4); }
    .search-results-box {
      position: absolute; top: 100%; left: 0; right: 0; background: white; border-radius: 6px;
      box-shadow: 0 10px 25px rgba(0,0,0,0.2); z-index: 10001; max-height: 220px; overflow-y: auto;
      display: none; margin-top: 5px; border: 1px solid #cbd5e1;
    }
    .search-item { padding: 10px 12px; color: var(--text-dark); cursor: pointer; font-size: 0.8rem; border-bottom: 1px solid #f1f5f9; transition: background 0.15s; }
    .search-item:last-child { border-bottom: none; }
    .search-item:hover { background-color: #e2f1ff; color: var(--primary); }
    .search-item strong { display: block; font-size: 0.85rem; color: #0f172a; }
    .search-item span { color: var(--text-muted); font-size: 0.75rem; }

    .menu-btn {
      background: none; border: none; color: #cbd5e1; text-align: left;
      padding: 11px 16px; margin-bottom: 5px; font-size: 0.85rem;
      font-weight: bold; cursor: pointer; border-radius: 6px; transition: all 0.2s ease; width: 100%;
    }
    .menu-btn:hover { background-color: rgba(255, 255, 255, 0.08); color: white; }
    .menu-btn.active { background-color: var(--primary-light); color: white; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }

    /* SEPARADOR MENÚ */
    .menu-separator {
      border: none; border-top: 1px solid rgba(255,255,255,0.12);
      margin: 10px 6px;
    }
    .menu-section-label {
      font-size: 0.68rem; font-weight: bold; color: #64748b;
      text-transform: uppercase; letter-spacing: 2px;
      padding: 6px 16px 4px;
    }

    .main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }

    .patient-header {
      background: white; padding: 15px 30px; border-bottom: 1px solid #e2e8f0;
      display: flex; justify-content: space-between; align-items: center;
    }
    .patient-title-area { display: flex; align-items: center; gap: 15px; }
    .patient-info h2 { font-size: 1.2rem; color: var(--primary); }
    .patient-meta { display: flex; gap: 20px; font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
    .patient-meta strong { color: var(--text-dark); }

    .btn-action-wa {
      display: inline-flex; align-items: center; justify-content: center;
      background-color: var(--whatsapp); color: white; border: none;
      width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
      transition: all 0.2s ease; box-shadow: 0 4px 8px rgba(37, 211, 102, 0.3);
    }
    .btn-action-wa:hover { transform: scale(1.1); background-color: #20ba5a; }
    .btn-action-wa svg { width: 20px; height: 20px; fill: white; }
    .btn-action-wa.disabled { background-color: #cbd5e1; box-shadow: none; cursor: not-allowed; opacity: 0.6; }

    .btn-save {
      background-color: var(--success); color: white; border: none;
      padding: 10px 20px; font-size: 0.85rem; font-weight: bold;
      border-radius: 6px; cursor: pointer; transition: background 0.2s;
      box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);
    }
    .btn-save:hover { background-color: #059669; }

    .tab-panel { padding: 25px 30px; animation: fadeIn 0.2s ease; }
    .tab-panel:not(.active) { display: none; }
    @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

    .card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); border: 1px solid #e2e8f0; margin-bottom: 15px; }
    .card-title { font-size: 0.95rem; font-weight: bold; color: var(--primary); margin-bottom: 15px; border-bottom: 2px solid #f1f5f9; padding-bottom: 6px; }

    .leyenda { display: flex; flex-wrap: wrap; gap: 15px; font-size: 0.8rem; margin-bottom: 15px; }
    .item-leyenda { display: flex; align-items: center; gap: 6px; font-weight: bold; }
    .cuadro { width: 14px; height: 14px; border: 1px solid #333; border-radius: 3px; }
    .maxilar-seccion { width: 100%; margin-bottom: 15px; }
    .seccion-titulo { background: var(--primary); color: white; padding: 4px 10px; border-radius: 4px; font-size: 0.8rem; margin-bottom: 6px; font-weight: bold; }
    .seccion-titulo.ninos { background: var(--primary-light); }
    .grilla-dientes { display: grid; grid-template-columns: repeat(16, 1fr); gap: 4px; }
    .pieza-dental { background: white; padding: 4px 2px; border-radius: 4px; text-align: center; border: 1px solid #e2e8f0; }
    .pieza-dental.vacio { background: transparent; border: none; }
    .numero-diente { font-weight: bold; font-size: 0.75rem; color: #334155; margin-bottom: 2px; }
    .letra-nino { font-size: 0.65rem; color: var(--primary-light); display: block; font-weight: normal; }
    .grilla-dientes svg { position: absolute; inset: 0; width: 100%; height: 100%; }
    .cara-dental { fill: #ffffff; stroke: #475569; stroke-width: 1.5; cursor: pointer; transition: fill 0.1s ease; }
    .cara-dental:hover { fill: #e2f1ff; }
    .existente { fill: #ef4444 !important; }
    .planeado { fill: #2563eb !important; }

    /* PIEZA DENTAL - 5 caras clickeables + tratamiento general por pieza */
    .pieza-dental { transition: transform 0.1s ease; }
    .numero-diente { cursor: pointer; }
    .numero-diente:hover { text-decoration: underline; }
    .pieza-caja {
      background: white; border: 1.5px solid #cbd5e1; border-radius: 6px;
      height: 50px; position: relative; overflow: hidden;
    }
    .pieza-overlay {
      position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
      gap: 3px; font-size: 1.5rem; font-weight: 900; pointer-events: none; line-height: 1;
    }
    .pieza-overlay:not(:empty) { background: rgba(255,255,255,0.9); }
    .pieza-icono-existente { color: #ef4444; }
    .pieza-icono-requerida { color: #2563eb; }

    /* REFERENCIA DE TRATAMIENTOS */
    .referencia-odonto { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; font-size: 0.82rem; }
    .ref-columna-titulo { font-weight: bold; margin-bottom: 8px; }
    .ref-item { display: flex; align-items: center; gap: 10px; padding: 4px 0; color: var(--text-dark); }
    .ref-simbolo { display: inline-block; width: 22px; text-align: center; font-weight: 900; font-size: 1rem; }
    @media (max-width: 768px) { .referencia-odonto { grid-template-columns: 1fr; } }

    /* MODAL ODONTOGRAMA */
    .modal-overlay {
      position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 9997;
      display: flex; align-items: center; justify-content: center; padding: 20px;
    }
    .modal-box {
      background: white; border-radius: 12px; padding: 30px; max-width: 480px; width: 100%;
      box-shadow: 0 20px 40px rgba(0,0,0,0.25); position: relative; text-align: center;
    }
    .modal-close {
      position: absolute; top: 12px; right: 14px; background: none; border: none;
      font-size: 1.2rem; cursor: pointer; color: var(--text-muted);
    }
    .modal-titulo { font-weight: bold; color: var(--primary); margin-bottom: 18px; font-size: 0.95rem; }
    .modal-diente-preview {
      width: 90px; height: 90px; margin: 0 auto 20px; border: 2px solid #475569; border-radius: 8px;
      display: flex; align-items: center; justify-content: center; font-size: 2.2rem; font-weight: 900;
    }
    .modal-selects { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; }
    @media (max-width: 500px) { .modal-selects { grid-template-columns: 1fr; } }

    .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
    .form-group { margin-bottom: 15px; font-size: 0.85rem; }
    .form-group label { display: block; font-weight: bold; margin-bottom: 6px; color: var(--text-dark); }
    .clinic-input { width: 100%; padding: 10px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; font-size: 0.9rem; color: var(--text-dark); transition: border 0.2s; }
    .clinic-input:focus { outline: none; border-color: var(--primary-light); }

    /* ================================================== */
    /* MÓDULO CAJA - ESTILOS                              */
    /* ================================================== */
    .caja-resumen {
      display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 20px;
    }
    .caja-kpi {
      background: white; border-radius: 10px; padding: 18px 20px;
      border: 1px solid #e2e8f0; box-shadow: 0 2px 6px rgba(0,0,0,0.04);
      text-align: center;
    }
    .caja-kpi .kpi-label { font-size: 0.75rem; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 8px; }
    .caja-kpi .kpi-valor { font-size: 1.6rem; font-weight: 900; }
    .kpi-verde { color: #059669; }
    .kpi-rojo { color: #dc2626; }
    .kpi-azul { color: var(--primary-light); }

    .caja-form-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 15px; }
    .caja-btn {
      background-color: var(--primary-light); color: white; border: none;
      padding: 10px 18px; border-radius: 6px; font-weight: bold; font-size: 0.85rem;
      cursor: pointer; transition: background 0.2s; white-space: nowrap;
    }
    .caja-btn:hover { background-color: #0369a1; }
    .caja-btn.egreso { background-color: #dc2626; }
    .caja-btn.egreso:hover { background-color: #b91c1c; }

    .caja-tabla { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
    .caja-tabla th { background: var(--primary); color: white; padding: 10px 12px; text-align: left; font-size: 0.78rem; letter-spacing: 0.5px; }
    .caja-tabla th:first-child { border-radius: 6px 0 0 0; }
    .caja-tabla th:last-child { border-radius: 0 6px 0 0; }
    .caja-tabla td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
    .caja-tabla tr:last-child td { border-bottom: none; }
    .caja-tabla tr:hover td { background-color: #f8fafc; }
    .badge-ingreso { background: #dcfce7; color: #15803d; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: bold; }
    .badge-egreso { background: #fee2e2; color: #b91c1c; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: bold; }
    .monto-pos { color: #059669; font-weight: bold; }
    .monto-neg { color: #dc2626; font-weight: bold; }
    .btn-icon-mov { background: none; border: none; cursor: pointer; font-size: 0.95rem; padding: 2px 4px; transition: transform 0.15s; }
    .btn-icon-mov:hover { transform: scale(1.2); }

    /* ================================================== */
    /* MÓDULO MOVIMIENTO EN CAJA - ESTILOS                */
    /* ================================================== */
    .mov-filtros { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: flex-end; }
    .mov-filtros .clinic-input { max-width: 180px; }
    .mov-filtros label { font-size: 0.78rem; font-weight: bold; color: var(--text-muted); display: block; margin-bottom: 4px; }
    .btn-filtrar {
      background: var(--primary); color: white; border: none; padding: 10px 16px;
      border-radius: 6px; font-size: 0.82rem; font-weight: bold; cursor: pointer;
      transition: background 0.2s;
    }
    .btn-filtrar:hover { background: #162d5a; }
    .arqueo-box {
      background: linear-gradient(135deg, #1e3c72 0%, #0284c7 100%);
      border-radius: 10px; padding: 20px 25px; color: white; margin-bottom: 20px;
      display: flex; justify-content: space-between; align-items: center;
    }
    .arqueo-box .arqueo-titulo { font-size: 0.85rem; font-weight: bold; opacity: 0.8; text-transform: uppercase; letter-spacing: 1px; }
    .arqueo-box .arqueo-total { font-size: 2rem; font-weight: 900; }
    .arqueo-box .arqueo-detalle { font-size: 0.78rem; opacity: 0.7; margin-top: 4px; }
    .arqueo-leyendas { display: flex; gap: 25px; }
    .arqueo-leyendas .arq-item { text-align: center; }
    .arqueo-leyendas .arq-val { font-size: 1.1rem; font-weight: 800; }
    .arqueo-leyendas .arq-lbl { font-size: 0.7rem; opacity: 0.7; text-transform: uppercase; letter-spacing: 1px; }

    .caja-resumen-header {
      display: flex; justify-content: flex-end; align-items: center; margin-bottom: 8px;
    }
    .btn-ojo {
      background: rgba(0,0,0,0.06); border: 1px solid rgba(0,0,0,0.1); color: var(--text-muted);
      width: 34px; height: 34px; border-radius: 8px; font-size: 1rem; cursor: pointer;
      display: flex; align-items: center; justify-content: center; transition: background 0.15s, transform 0.1s;
    }
    .btn-ojo:hover { background: rgba(0,0,0,0.12); }
    .btn-ojo:active { transform: scale(0.92); }
    .btn-ojo.ojo-en-arqueo {
      background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.35); color: white;
    }
    .btn-ojo.ojo-en-arqueo:hover { background: rgba(255,255,255,0.28); }
    .monto-oculto { letter-spacing: 2px; }

    .toast {
      position: fixed; bottom: -60px; right: 30px; background-color: #065f46; color: white;
      padding: 14px 24px; border-radius: 8px; font-weight: bold; font-size: 0.9rem;
      box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 99999;
    }
    .toast.show { bottom: 30px; }

    @media (max-width: 768px) {
      body { flex-direction: column; overflow: hidden; }
      .mobile-navbar { display: flex; }
      .sidebar { position: fixed; top: 0; left: -270px; height: 100vh; width: 260px; transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: 5px 0 15px rgba(0,0,0,0.25); }
      .sidebar.open { left: 0; }
      .patient-header { padding: 15px 20px; flex-direction: column; align-items: stretch; gap: 12px; }
      .patient-title-area { justify-content: space-between; }
      .patient-meta { flex-wrap: wrap; gap: 10px 15px; }
      .btn-save { width: 100%; text-align: center; padding: 12px; }
      .tab-panel { padding: 15px 20px; }
      .form-row { grid-template-columns: 1fr; gap: 0; }
      .maxilar-seccion { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
      .grilla-dientes { min-width: 700px; }
      .caja-resumen { grid-template-columns: 1fr; }
      .caja-form-row { grid-template-columns: 1fr 1fr; }
      .arqueo-box { flex-direction: column; gap: 15px; }
    }
     #img-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  #img-lightbox-toolbar {
    position: absolute;
    top: 14px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10001;
  }

  #img-lightbox-toolbar button {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    font-size: 1rem;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
  }

  #img-lightbox-toolbar button:hover {
    background: rgba(255, 255, 255, 0.25);
  }

  #img-lightbox-close {
    background: rgba(220, 38, 38, 0.85) !important;
  }

  #img-lightbox-zoom-label {
    color: #fff;
    font-size: 0.85rem;
    min-width: 46px;
    text-align: center;
  }

  #img-lightbox-viewport {
    width: 92vw;
    height: 78vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    touch-action: none; /* clave para que el pellizco no scrollee la página */
  }

  #img-lightbox-src {
    max-width: 100%;
    max-height: 100%;
    cursor: grab;
    transition: transform 0.05s linear;
    user-select: none;
  }

  #img-lightbox-caption {
    color: #f1f5f9;
    margin-top: 10px;
    font-size: 0.9rem;
    text-align: center;
    max-width: 90vw;
  }