/* ==========================================================================
   Kreatik OS — layout.css
   Estructura de la aplicación: shell, sidebar, header, vistas.
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  width: 100vw;
  transition: grid-template-columns 0.28s cubic-bezier(0.4,0,0.2,1);
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 10px;
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.28s cubic-bezier(0.4,0,0.2,1), padding 0.28s cubic-bezier(0.4,0,0.2,1);
  position: relative;
}

/* Expand button — top of sidebar, only visible when collapsed */
.sidebar-expand-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  margin-bottom: 10px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.sidebar-expand-btn:hover {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb),0.3);
  background: rgba(var(--accent-rgb),0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 16px;
  min-height: 36px;
  position: relative;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  box-shadow: 0 0 22px var(--accent-glow);
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.28s cubic-bezier(0.4,0,0.2,1), height 0.28s cubic-bezier(0.4,0,0.2,1), padding 0.28s cubic-bezier(0.4,0,0.2,1), margin-left 0.28s cubic-bezier(0.4,0,0.2,1);
}

.brand-mark-img {
  width: 65%;
  height: 65%;
  object-fit: contain;
  display: block;
}

.brand-text {
  flex: 1;
  min-width: 0;
  transition: opacity 0.2s cubic-bezier(0.4,0,0.2,1), width 0.25s cubic-bezier(0.4,0,0.2,1);
}

.brand-text .brand-title {
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.2;
}

.brand-text .brand-subtitle {
  font-size: 10.5px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ---------- Nav group ---------- */
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
  flex: 1;
}

.nav-group-item {
  position: relative;
}

/* ---------- Nav items (card-style) ---------- */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all 0.2s ease;
  white-space: nowrap;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

/* --- Default accent (blue) --- */
.nav-item.active {
  background: linear-gradient(180deg, rgba(var(--accent-rgb), 0.2) 0%, rgba(255,255,255,0.03) 100%);
  border: 1px solid var(--accent);
  box-shadow: inset 0px 1px 1px rgba(255, 255, 255, 0.3), 0px 4px 12px rgba(var(--accent-rgb), 0.25);
  color: #ffffff;
}

.nav-item .nav-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  background: transparent;
  transition: background 0.2s ease, color 0.2s ease;
}

.nav-item.active .nav-icon {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.4);
}

/* --- Section color accents --- */

/* Inicio — Blue (default) */
[data-view="dashboard"].active {
  --section-accent: var(--accent);
  --section-accent-rgb: var(--accent-rgb);
}

/* Cotizaciones — Emerald */
[data-view="cotizaciones"].active,
.nav-group-item:has([data-view="cotizaciones"].open) > .nav-submenu .nav-item.active {
  --section-accent: #10b981;
  --section-accent-rgb: 16, 185, 129;
}

/* Estrategia de Marca — Violet */
[data-view="gestion"].active,
.nav-group-item:has([data-view="gestion"].open) > .nav-submenu .nav-item.active {
  --section-accent: #8b5cf6;
  --section-accent-rgb: 139, 92, 246;
}

/* Configuración — Amber */
[data-view="configuracion"].active {
  --section-accent: #f59e0b;
  --section-accent-rgb: 245, 158, 11;
}

/* Apply section accent to active items */
[data-view="cotizaciones"].active,
[data-view="gestion"].active,
[data-view="configuracion"].active {
  background: linear-gradient(180deg, rgba(var(--section-accent-rgb), 0.2) 0%, rgba(255,255,255,0.03) 100%);
  border: 1px solid var(--section-accent);
  box-shadow: inset 0px 1px 1px rgba(255, 255, 255, 0.3), 0px 4px 12px rgba(var(--section-accent-rgb), 0.25);
}

[data-view="cotizaciones"].active .nav-icon,
[data-view="gestion"].active .nav-icon,
[data-view="configuracion"].active .nav-icon {
  background: var(--section-accent);
  box-shadow: 0 0 12px rgba(var(--section-accent-rgb), 0.4);
}

/* Sub-items inherit parent section accent when active */
.nav-group-item:has([data-view="cotizaciones"].open) > .nav-submenu .nav-item.active {
  background: linear-gradient(180deg, rgba(var(--section-accent-rgb), 0.2) 0%, rgba(255,255,255,0.03) 100%);
  border: 1px solid var(--section-accent);
  box-shadow: inset 0px 1px 1px rgba(255, 255, 255, 0.3), 0px 4px 12px rgba(var(--section-accent-rgb), 0.25);
}
.nav-group-item:has([data-view="cotizaciones"].open) > .nav-submenu .nav-item.active .nav-icon {
  background: var(--section-accent);
  box-shadow: 0 0 12px rgba(var(--section-accent-rgb), 0.4);
}

.nav-group-item:has([data-view="gestion"].open) > .nav-submenu .nav-item.active {
  background: linear-gradient(180deg, rgba(var(--section-accent-rgb), 0.2) 0%, rgba(255,255,255,0.03) 100%);
  border: 1px solid var(--section-accent);
  box-shadow: inset 0px 1px 1px rgba(255, 255, 255, 0.3), 0px 4px 12px rgba(var(--section-accent-rgb), 0.25);
}
.nav-group-item:has([data-view="gestion"].open) > .nav-submenu .nav-item.active .nav-icon {
  background: var(--section-accent);
  box-shadow: 0 0 12px rgba(var(--section-accent-rgb), 0.4);
}

.nav-item .nav-icon i {
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon-img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.nav-label {
  transition: opacity 0.2s cubic-bezier(0.4,0,0.2,1), width 0.25s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
  max-width: 200px;
}

/* ---------- Submenú desplegable ---------- */
.nav-toggle .nav-icon {
  transition: transform 0.2s ease;
}
.nav-toggle.open .nav-icon {
  transform: rotate(90deg);
}

.nav-submenu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
  opacity: 0;
  margin-top: 8px;
  padding-left: 20px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  margin-left: 24px;
  position: relative;
}
.nav-submenu.open {
  max-height: 400px;
  opacity: 1;
}

.nav-subitem {
  position: relative;
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.nav-subitem::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  width: 8px;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-50%);
}

.nav-subitem.active::before {
  background: var(--section-accent, var(--accent));
  box-shadow: 0 0 6px rgba(var(--section-accent-rgb, var(--accent-rgb)), 0.5);
}

/* ---------- Sidebar nav bottom (collapse button) ---------- */
.sidebar-nav-bottom {
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: auto;
}

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  transition: all 0.2s ease;
}
.sidebar-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}
.sidebar-collapse-btn .nav-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
}
.sidebar-collapse-btn i {
  font-size: 13px;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

/* ---------- Sidebar footer ---------- */
.sidebar-footer {
  padding: 8px 0 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.sidebar-logout-btn:hover {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
  color: #ef4444;
}
.sidebar-logout-btn i {
  font-size: 14px;
}

.sidebar-footer-bottom {
  padding: 10px 4px 4px;
  font-size: 15px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-footer-text {
  font-size: 11px;
  color: var(--text-muted);
  transition: opacity 0.3s ease-in-out;
}

.sidebar-footer-icons {
  display: flex;
  gap: 6px;
}
.sidebar-footer-icons a {
  opacity: 0.5;
  transition: opacity 0.2s ease;
}
.sidebar-footer-icons a:hover {
  opacity: 1;
}

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(13,14,17,0.6);
  backdrop-filter: blur(10px);
  min-height: 56px;
}

.topbar-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.topbar-title.animate {
  animation: titleReveal 0.35s ease-out;
}

@keyframes titleReveal {
  from {
    opacity: 0;
    transform: translateY(-6px);
    letter-spacing: 0.06em;
  }
  to {
    opacity: 1;
    transform: translateY(0);
    letter-spacing: 0.01em;
  }
}

.dashboard-greeting {
  display: none;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  margin-bottom: 18px;
  border-radius: 18px;
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  color: var(--text-primary);
}

.dashboard-greeting.active {
  display: flex;
}

.dashboard-greeting-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59,130,246,0.14);
  color: var(--accent-2);
}

.dashboard-greeting-icon i {
  font-size: 22px;
}

.dashboard-greeting-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-right: 2px solid var(--accent);
  padding-right: 6px;
  white-space: nowrap;
  overflow: hidden;
}

.dashboard-greeting-text.done {
  border-right: 0;
}

.topbar-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.01em;
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

.view-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px 60px;
}

.view {
  display: none;
  animation: fadeUp var(--normal) var(--ease);
}
.view.active { display: block; }

/* ---------- Grid helpers ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; min-width: 0; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }

.two-col-layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1100px) {
  .two-col-layout { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ---------- Flyout flotante (modo colapsado) — bubble tooltip ---------- */
.sidebar-flyout {
  position: fixed;
  left: 88px;
  z-index: 600;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  min-height: 36px;
  align-items: center;
  backdrop-filter: blur(8px);
  min-width: 140px;
  max-width: 260px;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.18s cubic-bezier(0.4,0,0.2,1), transform 0.18s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  visibility: hidden;
}
.sidebar-flyout::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.sidebar-flyout.visible {
  opacity: 1;
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}
.sidebar-flyout.submenu {
  flex-direction: column;
  align-items: stretch;
  padding: 6px;
  min-width: 180px;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  pointer-events: auto;
}
.sidebar-flyout.submenu::before {
  display: none;
}
.sidebar-flyout.submenu .nav-item {
  padding: 7px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  width: 100%;
  text-align: left;
  opacity: 0.7;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}
.sidebar-flyout.submenu .nav-item:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  opacity: 1;
}
.sidebar-flyout.submenu .nav-item .nav-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
}

/* ---------- Sidebar colapsable (solo íconos) ---------- */
@media (min-width: 769px) {
  .app-shell.sidebar-collapsed {
    grid-template-columns: 92px 1fr;
  }
  .app-shell.sidebar-collapsed .sidebar {
    padding: 14px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .app-shell.sidebar-collapsed .sidebar-expand-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: auto;
    margin-right: auto;
    width: 44px;
    height: 36px;
  }
  .app-shell.sidebar-collapsed .sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2px 0 12px;
    width: 100%;
    gap: 0;
  }
  .app-shell.sidebar-collapsed .brand-mark {
    width: 44px;
    height: 44px;
    margin: 0 auto;
    border-radius: 12px;
  }
  .app-shell.sidebar-collapsed .brand-text,
  .app-shell.sidebar-collapsed .mobile-menu-btn {
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
  }
  .app-shell.sidebar-collapsed .nav-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
  }
  .app-shell.sidebar-collapsed .nav-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
  }
  .app-shell.sidebar-collapsed .nav-item {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    gap: 0;
    margin-left: auto;
    margin-right: auto;
    border-radius: 12px;
  }
  .app-shell.sidebar-collapsed .nav-item .nav-icon {
    margin: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .app-shell.sidebar-collapsed .nav-item .nav-icon i {
    font-size: 15px;
  }
  .app-shell.sidebar-collapsed .nav-submenu {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    border-left: none;
    padding-left: 0;
    margin-left: 0;
    margin-top: 0;
  }
  .app-shell.sidebar-collapsed .sidebar-nav-bottom {
    padding: 8px 0;
    border-top: none;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .app-shell.sidebar-collapsed .sidebar-collapse-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    gap: 0;
    margin-left: auto;
    margin-right: auto;
  }
  .app-shell.sidebar-collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
  }
  .app-shell.sidebar-collapsed .sidebar-footer {
    padding: 8px 0 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .app-shell.sidebar-collapsed .sidebar-logout-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    margin-left: auto;
    margin-right: auto;
  }
  .app-shell.sidebar-collapsed .sidebar-logout-btn span {
    display: none;
  }
  .app-shell.sidebar-collapsed .sidebar-footer-bottom {
    flex-direction: column;
    align-items: center;
    padding: 10px 0 4px;
    gap: 10px;
  }
  .app-shell.sidebar-collapsed .sidebar-footer-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
  }
  .app-shell.sidebar-collapsed .sidebar-footer-icons {
    justify-content: center;
  }
}

@media print {
  .app-shell { display: none !important; }
}
