/* ============================================================
   Ruta: static/css/global.css
   Sistema de Diseno Centralizado (Mobile-first)
   ============================================================ */

@import url('/static/css/toast.css');

:root {
  /* Paleta principal extraida del proyecto */
  --color-primary: #3b82f6;
  --color-secondary: #1e293b;
  --color-background: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #0f172a;
  --color-text-muted: #57667A;
  --color-success: #10b981;
  --color-danger: #ef4444;

  /* Bordes redondeados estilo iOS */
  --radius-sm: 0.75rem;
  --radius-md: 1rem;
  --radius-lg: 1.5rem;

  /* Sombras suaves y difuminadas */
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 38px rgba(15, 23, 42, 0.11);

  /* Tamano minimo tactil recomendado por Apple */
  --touch-target-min: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-background);
  color: var(--color-text);
}

/* Mobile-first: nunca desbordar horizontalmente */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Medios fluidos (canvas excluido: Chart.js gestiona su tamano) */
img,
svg,
video {
  max-width: 100%;
  height: auto;
}

/* Tablas anchas: scroll dentro de su contenedor, no en la pagina */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Reset Mobile-first de controles nativos */
input,
button,
select,
textarea {
  font: inherit;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

button,
select,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  min-height: var(--touch-target-min);
}

.sidebar-logout,
#btn-logout {
  text-decoration: none !important;
}

.sidebar-logout:hover,
.sidebar-logout:focus,
.sidebar-logout:active,
#btn-logout:hover,
#btn-logout:focus,
#btn-logout:active {
  text-decoration: none !important;
}

/* Micro-feedback tactil estilo app nativa */
@media (hover: none) and (pointer: coarse) {
  button,
  .bottom-btn,
  .nav-link,
  .sidebar-logout {
    transition: transform 0.1s ease, opacity 0.1s ease;
  }

  button:active:not(:disabled),
  .bottom-btn:active,
  .nav-link:active,
  .sidebar-logout:active {
    transform: scale(0.95);
    opacity: 0.82;
  }
}

/* ══════════════════════════════════════════════════════════
   FILTROS TEMPORALES + PAGINADOR (Ventas y Gastos)
   Componente compartido: ambas pantallas cargan global.css, asi
   las capsulas y el paginador se ven igual en las dos.
   ══════════════════════════════════════════════════════════ */
.jem-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.jem-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.jem-pill {
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--color-primary);
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
  border-radius: 9999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.jem-pill:hover { background: #DBEAFE; }

.jem-pill.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.28);
}

.jem-date-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.jem-date {
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid #E2E8F0;
  border-radius: var(--radius-sm);
  outline: none;
  min-height: var(--touch-target-min);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.jem-date:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* Safari iOS: con appearance:none (reset de arriba) el valor de un
   input[type=date] se centra y, vacio, el control colapsa. Se alinea a la
   izquierda como el resto de campos. */
.jem-date::-webkit-date-and-time-value {
  text-align: left;
  min-height: 1.2em;
}

.jem-date-clear {
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  background: #F1F5F9;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.jem-date-clear:hover { background: #E2E8F0; color: var(--color-text); }
.jem-date-clear.hidden { display: none; }

/* ── Paginador ────────────────────────────────────────────── */
.jem-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px solid #F1F5F9;
}

.jem-pager.hidden { display: none; }

.jem-pager-info {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

.jem-pager-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.jem-pager-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--color-primary);
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.jem-pager-btn:hover:not(:disabled) { background: #DBEAFE; }

.jem-pager-btn:disabled {
  color: #57667A;
  background: #F8FAFC;
  border-color: #E2E8F0;
  cursor: not-allowed;
}

.jem-pager-page {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text);
  min-width: 4.5rem;
  text-align: center;
}

/* FAB inteligente: oculta texto al colapsar en scroll */
[data-fab-smart] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

[data-fab-smart] .fab-label {
  transition: max-width 0.2s ease, opacity 0.2s ease, margin 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

/* ── Filtros en movil ─────────────────────────────────────── */
@media (max-width: 768px) {
  .jem-filters { gap: 0.45rem; }

  /* Capsulas compactas. El min-height se pone explicito porque la regla
     general de button (min-height: 44px, arriba) mandaba sobre el padding y
     las dejaba igual de altas por mucho que se redujera. 32px sigue por
     encima del minimo de 24px de WCAG 2.2 (2.5.8) para objetivos tactiles. */
  .jem-pills { gap: 0.3rem; flex: 1 1 100%; }
  .jem-pill {
    min-height: 32px;
    padding: 0.28rem 0.65rem;
    font-size: 0.74rem;
  }
  .jem-pill.active { box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25); }

  /* Fecha a todo el ancho, en su propia linea. Antes .jem-date-wrap tenia
     flex-shrink:0 y el input no tenia min-width:0, asi que su ancho
     intrinseco (el del selector nativo) empujaba la fila fuera de la
     pantalla y forzaba scroll horizontal en la pagina. */
  .jem-date-wrap {
    flex: 1 1 100%;
    min-width: 0;
  }
  .jem-date {
    flex: 1;
    min-width: 0;
    width: 100%;
    /* 16px: por debajo, iOS hace zoom en la pagina al enfocar el campo. */
    font-size: 1rem;
    padding: 0.4rem 0.7rem;
  }
  .jem-date-clear { flex-shrink: 0; }
}

@media (max-width: 768px) {
  [data-fab-smart].fab-collapsed {
    padding-left: 0.8rem !important;
    padding-right: 0.8rem !important;
  }

  [data-fab-smart].fab-collapsed .fab-label {
    max-width: 0;
    opacity: 0;
    margin: 0;
    transform: translateX(4px);
    overflow: hidden;
  }
}