/* ============================================================
   PUERTA A PUERTA — PORTAL LAYOUT
   Sidebar + Topbar + Main content shell. Totalmente responsivo.
   Depende de: portal-vars.css
   ============================================================ */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }

body.portal-body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--surface-page);
  line-height: var(--lh-normal);
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
img { display: block; max-width: 100%; }

/* ── Portal Shell ─────────────────────────────────────────── */
.portal-wrapper {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  padding-top: var(--safe-top);
  background: var(--surface-sidebar);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: var(--z-sidebar);
  transition: transform var(--t-slow), width var(--t-slow);
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

/* Logo area */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  min-height: var(--topbar-height);
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: var(--text-md);
  font-weight: var(--w-extrabold);
  color: var(--text-primary);
  line-height: 1;
  white-space: nowrap;
}
.portal-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--pap-primary);
  color: #fff;
  font-size: 10px;
  font-weight: var(--w-bold);
  border-radius: var(--r-full);
  letter-spacing: .5px;
  text-transform: uppercase;
  flex-shrink: 0;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: var(--sp-4) 0 var(--sp-8);
  overflow-y: auto;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-section {
  margin-bottom: var(--sp-3);
}

.nav-section-title {
  display: block;
  padding: var(--sp-3) var(--sp-5) var(--sp-2);
  font-size: var(--text-xs);
  font-weight: var(--w-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: .7px;
  white-space: nowrap;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-5);
  font-size: var(--text-base);
  font-weight: var(--w-medium);
  color: var(--text-secondary);
  border-radius: 0;
  border-left: 3px solid transparent;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
  position: relative;
  cursor: pointer;
}
.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.nav-link.active {
  background: var(--pap-primary-light);
  color: var(--pap-primary-dark);
  font-weight: var(--w-semibold);
  border-left-color: var(--pap-primary);
}
.nav-link svg {
  flex-shrink: 0;
  opacity: .7;
  transition: opacity var(--t-fast);
}
.nav-link:hover svg,
.nav-link.active svg {
  opacity: 1;
}
.nav-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--pap-primary);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--w-bold);
  border-radius: var(--r-full);
}

/* Sidebar divider */
.nav-divider {
  height: 1px;
  background: var(--border-default);
  margin: var(--sp-3) var(--sp-5);
}

/* ── Mobile Overlay ──────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: calc(var(--z-sidebar) - 1);
  opacity: 0;
  transition: opacity var(--t-slow);
}
.sidebar-overlay.show {
  opacity: 1;
}

/* ── Portal Main ─────────────────────────────────────────── */
.portal-main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  transition: margin-left var(--t-slow);
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  height: calc(var(--topbar-height) + var(--safe-top));
  background: var(--surface-topbar);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--safe-top) var(--content-pad) 0;
  gap: var(--sp-4);
  z-index: var(--z-topbar);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-left: auto;
}

.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  padding: 0;
  transition: background var(--t-fast);
}
.hamburger:hover { background: var(--surface-hover); }

/* Store selector */
.store-selector {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  font-weight: var(--w-semibold);
  color: var(--text-primary);
  cursor: pointer;
  border: 1px solid var(--border-default);
  transition: background var(--t-fast);
  max-width: 280px;
}
.store-selector:hover { background: var(--surface-hover); }
.store-selector-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Estado button */
.estado-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: none;
  border: 1px solid var(--border-default);
  border-radius: var(--r-full);
  font-size: var(--text-sm);
  font-weight: var(--w-medium);
  color: var(--text-secondary);
  transition: all var(--t-fast);
  white-space: nowrap;
  flex-shrink: 0;
}
.estado-btn.open {
  border-color: var(--color-success);
  color: var(--color-success);
  background: var(--color-success-bg);
}
.estado-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-disabled);
  flex-shrink: 0;
  transition: background var(--t-fast);
}
.estado-dot.open  { background: var(--color-success); }
.estado-dot.closed { background: var(--color-error); }

/* Topbar icon buttons */
.btn-topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 34px;
  padding: 0 var(--sp-3);
  background: none;
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  font-weight: var(--w-medium);
  color: var(--text-secondary);
  transition: background var(--t-fast);
}
.btn-topbar:hover { background: var(--surface-hover); }
.btn-topbar.btn-icon {
  width: 34px;
  padding: 0;
  justify-content: center;
  border-radius: var(--r-sm);
}
/* ── Portal Content ──────────────────────────────────────── */
.portal-content {
  flex: 1;
  padding: var(--sp-8) var(--content-pad);
  overflow-y: auto;
}

/* ── Views ───────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  margin-bottom: var(--sp-6);
}
.page-title {
  font-size: var(--text-3xl);
  font-weight: var(--w-extrabold);
  color: var(--text-primary);
  line-height: var(--lh-tight);
  margin-bottom: var(--sp-2);
}
.page-crumb {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  font-weight: var(--w-semibold);
  color: var(--pap-primary-dark);
  cursor: pointer;
  border-bottom: 1px dashed var(--pap-primary);
}
.page-crumb svg { opacity: .7; }

/* ── View Toolbar ────────────────────────────────────────── */
.view-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.toolbar-left  { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: var(--sp-3); margin-left: auto; }

/* ── Help Section ────────────────────────────────────────── */
.help-section {
  margin-top: var(--sp-12);
  padding-top: var(--sp-8);
  border-top: 1px solid var(--border-default);
}
.help-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--sp-5);
}
.help-section-header h4 {
  font-size: var(--text-xl);
  font-weight: var(--w-bold);
}
.help-section-header p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}
.help-more-link {
  font-size: var(--text-sm);
  font-weight: var(--w-semibold);
  color: var(--text-secondary);
  white-space: nowrap;
}
.help-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
}
.help-card {
  padding: var(--sp-5);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  background: var(--surface-card);
}
.help-card h5 {
  font-size: var(--text-base);
  font-weight: var(--w-semibold);
  margin-bottom: var(--sp-2);
}
.help-card p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--lh-relaxed);
  margin-bottom: var(--sp-3);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.help-card-link {
  font-size: var(--text-sm);
  font-weight: var(--w-semibold);
  color: var(--pap-primary-dark);
}
.help-card-link:hover { text-decoration: underline; }

/* ── Menu Split Layout ───────────────────────────────────── */
.split-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: var(--sp-6);
  align-items: start;
}

/* ── Responsive ──────────────────────────────────────────── */

/* Tablet: collapse sidebar */
@media (max-width: 1024px) {
  .split-layout { grid-template-columns: 200px 1fr; }
  .help-cards { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile: hide sidebar, show hamburger */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  .sidebar-overlay.show { display: block; }

  .portal-main { margin-left: 0; }

  .hamburger { display: flex; }

  .portal-content {
    padding: var(--sp-5) var(--sp-4);
  }

  .topbar {
    padding: 0 var(--sp-4);
    gap: var(--sp-2);
  }

  .store-selector { max-width: 180px; }

  .view-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { margin-left: 0; }

  .split-layout {
    grid-template-columns: 1fr;
  }

  .help-cards { grid-template-columns: 1fr 1fr; }

  .page-title { font-size: var(--text-2xl); }
}

@media (max-width: 480px) {
  .help-cards { grid-template-columns: 1fr; }
  .store-selector { max-width: 140px; font-size: var(--text-xs); }
  .btn-topbar:not(.btn-icon) { display: none; }

  /* Textos de acción largos ("Pausar pedidos ahora", "Marcar como cerrado")
     no entran en una fila junto al selector de local + campana en pantallas
     chicas — se achican y truncan con "…" en vez de envolver y romper el
     alto fijo del topbar (ver applyComercioToUI() en comercio.js). */
  .estado-btn {
    font-size: var(--text-xs);
    padding: var(--sp-2);
    max-width: 96px;
  }
  .estado-btn span:not(.estado-dot) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
