/* ============================================
   KIOSKO VEGA — Design System
   Warm café aesthetic: cream, roasted coffee, leaf green, terracotta
   ============================================ */

:root {
  --bg-cream: #F5EAD4;
  --bg-paper: #FBF4E2;
  --bg-card: #FFFFFF;
  --bg-sidebar: #2C1810;
  --bg-sidebar-hover: #3D2618;
  --bg-overlay: rgba(44, 24, 16, 0.55);

  --ink-900: #2C1810;
  --ink-700: #4A2E1E;
  --ink-500: #8A6B56;
  --ink-400: #B09B84;
  --ink-300: #D4C3A8;
  --ink-on-dark: #FBF4E2;
  --ink-on-dark-dim: #C4B093;

  --coffee-900: #3A1F10;
  --coffee-700: #5C3518;
  --coffee-500: #8B5028;
  --coffee-300: #D49565;
  --coffee-100: #F2DFC5;

  --teal-700: #1E6670;
  --teal-500: #3D9CA8;
  --teal-300: #8DC5CE;
  --teal-100: #D4EAEE;

  --sunset-700: #C4511A;
  --sunset-500: #E87A35;
  --sunset-300: #F2A970;
  --sunset-100: #FCE4C9;

  --leaf-700: #3F5D3A;
  --leaf-500: #5C8255;
  --leaf-300: #9DB895;
  --leaf-100: #DCE6D8;

  --terra-700: #9A4A2E;
  --terra-500: #C56B45;
  --terra-300: #E4A07F;
  --terra-100: #F5D9C6;

  --gold-500: #D99333;
  --gold-100: #FBE3B8;

  --success: #5C8255;
  --success-bg: #DCE6D8;
  --danger: #9A4A2E;
  --danger-bg: #F5D9C6;
  --warning: #D99333;
  --warning-bg: #FBE3B8;
  --info: #1E6670;
  --info-bg: #D4EAEE;

  --line: #EADEC4;
  --line-strong: #D9C8A8;
  --line-dark: #3D2618;

  --shadow-sm: 0 1px 2px rgba(62, 40, 23, 0.06), 0 1px 3px rgba(62, 40, 23, 0.04);
  --shadow-md: 0 4px 12px rgba(62, 40, 23, 0.08), 0 2px 4px rgba(62, 40, 23, 0.05);
  --shadow-lg: 0 12px 32px rgba(62, 40, 23, 0.12), 0 4px 8px rgba(62, 40, 23, 0.06);
  --shadow-xl: 0 24px 48px rgba(62, 40, 23, 0.18);

  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-full: 999px;

  --font-display: 'Fraunces', 'Playfair Display', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--ink-900);
  background: var(--bg-cream);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
  /* Prevenir scroll horizontal en movil */
  overflow-x: hidden;
  max-width: 100%;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }

/* ----- Typography helpers ----- */
.t-display { font-family: var(--font-display); font-weight: 500; letter-spacing: -0.02em; }
.t-mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.t-tnum { font-variant-numeric: tabular-nums; }

/* ─── App layout ─────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; position: relative; overflow-x: hidden; }

.sidebar {
  width: 244px;
  background: var(--bg-sidebar);
  color: var(--ink-on-dark);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 18px;
  border-bottom: 1px solid var(--line-dark);
  margin-bottom: 14px;
}
.sidebar-logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--coffee-500), var(--coffee-300));
  display: grid; place-items: center;
  color: var(--bg-cream);
  font-family: var(--font-display); font-weight: 600; font-size: 18px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.2);
  flex-shrink: 0;
}
.sidebar-logo-text { display: flex; flex-direction: column; line-height: 1.1; }
.sidebar-logo-text .name { font-family: var(--font-display); font-weight: 500; font-size: 16px; letter-spacing: -0.01em; }
.sidebar-logo-text .tag { font-size: 11px; color: var(--ink-on-dark-dim); letter-spacing: 0.04em; text-transform: uppercase; }

.nav-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-on-dark-dim); padding: 14px 10px 6px; font-weight: 500;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--ink-on-dark-dim); font-size: 13.5px; font-weight: 450;
  transition: all 0.15s ease; width: 100%; text-align: left; position: relative;
}
.nav-item:hover { background: var(--bg-sidebar-hover); color: var(--ink-on-dark); }
.nav-item.active { background: var(--bg-sidebar-hover); color: var(--ink-on-dark); box-shadow: inset 3px 0 0 var(--coffee-300); }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-item .badge {
  margin-left: auto; font-size: 10px; padding: 2px 6px;
  border-radius: var(--r-full); background: var(--coffee-500);
  color: var(--bg-cream); font-weight: 500;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--line-dark);
  display: flex; align-items: center; gap: 10px;
  padding: 14px 10px 4px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--terra-500), var(--gold-500));
  display: grid; place-items: center;
  color: var(--bg-cream); font-weight: 600; font-size: 12px; flex-shrink: 0;
}
.sidebar-footer .who { font-size: 13px; line-height: 1.2; min-width: 0; overflow: hidden; }
.sidebar-footer .who .role { font-size: 11px; color: var(--ink-on-dark-dim); }

/* ----- Main content ----- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(251, 247, 238, 0.92);
}
.topbar-title {
  font-family: var(--font-display); font-size: 22px; font-weight: 500;
  letter-spacing: -0.015em; flex: 1; min-width: 0; overflow: hidden;
}
.topbar-title .sub {
  display: block; font-family: var(--font-sans); font-size: 12px;
  font-weight: 400; color: var(--ink-500); letter-spacing: 0; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.content {
  padding: 28px; flex: 1;
  max-width: 1400px; width: 100%; margin: 0 auto;
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500; transition: all 0.15s ease;
  border: 1px solid transparent; white-space: nowrap;
}
.btn-primary { background: var(--coffee-700); color: var(--bg-cream); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--coffee-900); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--bg-card); color: var(--ink-900); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--bg-paper); border-color: var(--ink-400); }
.btn-ghost { background: transparent; color: var(--ink-700); }
.btn-ghost:hover { background: var(--coffee-100); color: var(--ink-900); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-lg { padding: 12px 18px; font-size: 14px; }
.btn-icon { padding: 8px; border-radius: var(--r-sm); }

/* ----- Cards ----- */
.card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-sm); }
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-header h3 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.card-header .sub { font-size: 12px; color: var(--ink-500); margin-top: 2px; }
.card-body { padding: 20px; }

/* ----- Inputs ----- */
.input, .textarea, .select {
  width: 100%; padding: 9px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--bg-card);
  font-size: 13.5px; transition: all 0.15s ease;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--coffee-500); box-shadow: 0 0 0 3px var(--coffee-100);
}
.label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-700); margin-bottom: 6px; letter-spacing: 0.01em; }
.field { margin-bottom: 14px; }
.field-row { display: grid; gap: 12px; }
.field-row.cols-2 { grid-template-columns: 1fr 1fr; }
.field-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ----- Tags / Pills ----- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 500;
  background: var(--coffee-100); color: var(--coffee-700); letter-spacing: 0.01em;
}
.pill-success { background: var(--success-bg); color: var(--success); }
.pill-warn { background: var(--warning-bg); color: var(--warning); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-leaf { background: var(--leaf-100); color: var(--leaf-700); }
.pill-ghost { background: transparent; color: var(--ink-500); border: 1px solid var(--line-strong); }
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ----- Table ----- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-500);
  border-bottom: 1px solid var(--line); background: var(--bg-paper);
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-paper); }
.table .num { font-variant-numeric: tabular-nums; text-align: right; }

/* ----- Metric card ----- */
.metric {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 18px 20px; position: relative; overflow: hidden;
}
.metric-label { font-size: 12px; color: var(--ink-500); font-weight: 500; letter-spacing: 0.02em; display: flex; align-items: center; gap: 6px; }
.metric-value {
  font-family: var(--font-display); font-size: 32px; font-weight: 500;
  letter-spacing: -0.02em; margin-top: 6px; line-height: 1.1; font-variant-numeric: tabular-nums;
}
.metric-delta { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; margin-top: 8px; font-weight: 500; }
.metric-delta.up { color: var(--success); }
.metric-delta.down { color: var(--danger); }
.metric .spark { position: absolute; right: 0; bottom: 0; width: 100px; height: 40px; opacity: 0.5; }

/* ----- Scrollbars ----- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 2px solid var(--bg-cream); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-400); }

/* ----- Toast ----- */
.toast-stack { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  background: var(--bg-sidebar); color: var(--ink-on-dark);
  padding: 12px 16px; border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px;
  min-width: 280px; max-width: 380px; pointer-events: auto;
  animation: toastIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  border-left: 3px solid var(--leaf-500);
}
.toast .toast-icon { width: 32px; height: 32px; border-radius: 50%; background: var(--leaf-500); display: grid; place-items: center; color: white; flex-shrink: 0; }
.toast .t-title { font-size: 13px; font-weight: 600; }
.toast .t-body { font-size: 12px; color: var(--ink-on-dark-dim); margin-top: 2px; }
.toast .t-amount { font-family: var(--font-display); font-size: 18px; margin-left: auto; font-variant-numeric: tabular-nums; }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ----- Modal ----- */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--bg-overlay);
  backdrop-filter: blur(4px); z-index: 50;
  display: grid; place-items: center; padding: 20px;
  animation: fadeIn 0.2s ease;
}
.modal { background: var(--bg-card); border-radius: var(--r-lg); max-width: 720px; width: 100%; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-xl); animation: modalIn 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.05); }
.modal-lg { max-width: 960px; }
.modal-header { padding: 20px 24px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; }
.modal-header h2 { margin: 0; font-family: var(--font-display); font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 14px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-paper); border-radius: 0 0 var(--r-lg) var(--r-lg); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ----- Dropzone ----- */
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--r-lg); padding: 40px 24px; text-align: center; background: var(--bg-paper); transition: all 0.2s ease; cursor: pointer; }
.dropzone:hover { border-color: var(--coffee-500); background: var(--coffee-100); }
.dropzone.active { border-color: var(--coffee-700); background: var(--coffee-100); }

/* ----- Segmented control ----- */
.segmented { display: inline-flex; background: var(--bg-paper); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.segmented button { padding: 6px 12px; border-radius: calc(var(--r-sm) - 3px); font-size: 12.5px; font-weight: 500; color: var(--ink-500); transition: all 0.15s ease; }
.segmented button.active { background: var(--bg-card); color: var(--ink-900); box-shadow: var(--shadow-sm); }

/* ----- AI Chat ----- */
.chat-bubble { max-width: 82%; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; }
.chat-bubble.user { background: var(--coffee-700); color: var(--ink-on-dark); border-bottom-right-radius: 4px; align-self: flex-end; }
.chat-bubble.ai { background: var(--bg-paper); color: var(--ink-900); border: 1px solid var(--line); border-bottom-left-radius: 4px; align-self: flex-start; }

/* ----- Live pulse ----- */
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--leaf-500); position: relative; display: inline-block; }
.live-dot::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--leaf-500); animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.8; } 100% { transform: scale(2.8); opacity: 0; } }

/* ═══════════════════════════════════════════════════════════════
   MOBILE / TABLET  (≤ 1024px)
   Sidebar pasa a drawer deslizante. Contenido ocupa toda la pantalla.
   ═══════════════════════════════════════════════════════════════ */
.mobile-nav { display: none; }
.sidebar-mobile-toggle { display: none; }

@media (max-width: 1024px) {

  /* ── Contención total: nada se sale de la pantalla ─────────── */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
  }
  .app {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
  }
  .main {
    min-width: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }
  .content {
    padding: 12px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  /* ── Sidebar drawer ────────────────────────────────────────── */
  /* Usar transform en lugar de left: -300px.
     left negativo sigue ocupando espacio en el scroll area en Safari/iOS.
     transform: translateX(-100%) mueve el elemento SIN afectar el layout. */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 85vw);
    height: 100%;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    /* opacity: 1 siempre — ya no necesitamos el truco de opacity
       porque usamos transform para mostrar/ocultar */
    opacity: 1;
  }
  .sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
  }

  /* Backdrop oscuro */
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: var(--bg-overlay);
    z-index: 55;
    backdrop-filter: blur(2px);
  }
  .sidebar-backdrop.show { display: block; }

  /* ── Topbar ────────────────────────────────────────────────── */
  .sidebar-mobile-toggle { display: inline-flex; }
  .topbar { padding: 10px 14px; gap: 8px; max-width: 100vw; overflow: hidden; }
  .topbar-title { font-size: 16px; min-width: 0; flex: 1; }
  .topbar-title .sub { display: none; }
  .topbar-actions { gap: 6px; flex-shrink: 0; }

  /* ── Todos los flex/grid children deben poder encogerse ────── */
  .row { min-width: 0; flex-wrap: wrap; }
  /* Excepto en lugares donde no queremos wrap */
  .card-header { flex-wrap: nowrap; }
  .card-header > div:first-child { min-width: 0; flex: 1; }
  .card-header h3 {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nav-item { flex-wrap: nowrap; }

  /* ── Forms ─────────────────────────────────────────────────── */
  .field-row.cols-2,
  .field-row.cols-3 { grid-template-columns: 1fr; }

  /* ── Grids → una sola columna ──────────────────────────────── */
  .metric { min-width: 0; max-width: 100%; }
  .grid { grid-template-columns: 1fr !important; }
  .grid.cols-2-mobile { grid-template-columns: 1fr 1fr !important; }

  /* ── Tablas ────────────────────────────────────────────────── */
  .table { table-layout: fixed; width: 100%; max-width: 100%; }
  .table th { font-size: 10px; padding: 8px 8px; }
  .table td { padding: 10px 8px; font-size: 12px; word-break: break-word; white-space: normal; }
  .table .hide-mobile-col { display: none; }
  .table td.truncate-cell {
    max-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .upcoming-label { word-break: break-word; font-size: 12px; line-height: 1.3; }

  /* ── Modales → hoja desde abajo ────────────────────────────── */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }

  /* ── SVGs: NO aplicar min-width global — rompía todos los íconos ── */
  /* El bug anterior: svg { min-width: 320px } hacía que cada ícono
     de 14px tuviera 320px de ancho, generando scroll horizontal masivo. */
  svg { min-width: 0; max-width: 100%; }
  /* Solo los charts dentro de .chart-scroll pueden tener ancho mínimo */
  .chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .chart-scroll svg { min-width: 280px; max-width: none; }

  /* ── Segmented controls: que no desborden ──────────────────── */
  .segmented { flex-wrap: nowrap; max-width: 100%; }

  /* ── Cards ─────────────────────────────────────────────────── */
  .card { max-width: 100%; overflow: hidden; }

  /* ── Toast: ancho completo en movil ───────────────────────── */
  .toast-stack { right: 12px; left: 12px; bottom: 80px; }
  .toast { min-width: 0; max-width: 100%; }

  /* ── Botón flotante AI más arriba en móvil ─────────────────── */
  .assistant-fab { bottom: 80px !important; }
}

/* ── iPhone / telefonos pequeños (≤ 430px) ──────────────────── */
@media (max-width: 430px) {
  .topbar { padding: 8px 10px; }
  .topbar-title { font-size: 14px; }
  .content { padding: 8px; }
  .metric-value { font-size: 24px; }
  .card-body { padding: 12px; }
  .card-header { padding: 10px 12px; }
  .btn { padding: 7px 10px; font-size: 11.5px; gap: 4px; }
  .btn-icon { padding: 7px; }
  .pill { font-size: 10.5px; padding: 2px 7px; }
  .gap-6 { gap: 16px; }
  .gap-4 { gap: 12px; }
}

/* ═══════════════════════════════════════════════════════════════
   Utility classes
   ═══════════════════════════════════════════════════════════════ */
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; }
.grid { display: grid; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-5 { gap: 20px; } .gap-6 { gap: 24px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.text-sm { font-size: 12.5px; } .text-xs { font-size: 11.5px; }
.text-muted { color: var(--ink-500); }
.text-strong { color: var(--ink-900); font-weight: 600; }
.center { display: grid; place-items: center; }
.hide-mobile { display: initial; }
.show-mobile { display: none; }

@media (max-width: 1024px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: initial !important; }
}
