/* =========================================================================
   Don Topo POS — v5 Shell
   App chrome completo: appbar, tabbar, side rail (desktop).
   Funciona SIN v3/app.css. Requiere tokens + foundation.
   ========================================================================= */

/* —— App root —— */
.app {
  min-height: 100dvh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  position: relative;
}

.view {
  min-width: 0;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--space-3) var(--space-3) calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-4));
}

/* Topnav oculto en móvil (vive en desktop como rail) */
.topnav {
  display: none;
}

/* —— Appbar (móvil / tablet) —— */
.appbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 14px 12px;
  margin: calc(var(--space-3) * -1) calc(var(--space-3) * -1) var(--space-3);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  /* sticky actúa como containing block; relative refuerza el hairline ::before */
  isolation: isolate;
}

.appbar-cash,
.topnav-cash {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-height: 34px;
  padding: 4px 11px 4px 9px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.01em;
  white-space: nowrap;
  text-decoration: none !important;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.topnav-cash-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 18%, transparent);
  flex: none;
}

.topnav-cash-copy {
  display: grid;
  line-height: 1.05;
  gap: 1px;
}

.topnav-cash-copy small {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topnav-cash-copy strong {
  color: var(--ink);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.appbar-cash.is-ok,
.topnav-cash.is-ok {
  background: color-mix(in srgb, var(--ok-soft) 70%, #fff);
  border-color: color-mix(in srgb, var(--ok) 22%, var(--line));
  color: var(--ok);
}

.topnav-cash.is-ok .topnav-cash-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent);
}

.topnav-cash.is-ok .topnav-cash-copy strong {
  color: color-mix(in srgb, var(--ok) 72%, var(--ink));
}

.appbar-cash.is-off,
.topnav-cash.is-off {
  background: color-mix(in srgb, var(--danger-soft) 65%, #fff);
  border-color: color-mix(in srgb, var(--danger) 20%, var(--line));
  color: var(--danger);
}

.topnav-cash.is-off .topnav-cash-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 16%, transparent);
}

.topnav-cash.is-off .topnav-cash-copy strong {
  color: color-mix(in srgb, var(--danger) 70%, var(--ink));
}

.appbar-cash.is-warn,
.topnav-cash.is-warn {
  background: color-mix(in srgb, var(--warn-soft) 70%, #fff);
  border-color: color-mix(in srgb, var(--warn) 28%, var(--line));
  color: var(--warn);
}

.topnav-cash.is-warn .topnav-cash-dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 20%, transparent);
  animation: topnavCashPulse 1.6s ease-in-out infinite;
}

.topnav-cash.is-warn .topnav-cash-copy strong {
  color: color-mix(in srgb, var(--warn) 75%, var(--ink));
}

@keyframes topnavCashPulse {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 16%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--warn) 10%, transparent); }
}

@media (hover: hover) {
  .topnav-cash:hover {
    border-color: color-mix(in srgb, var(--ink) 16%, var(--line));
    background: #fff;
  }
}

@media (prefers-reduced-motion: reduce) {
  .topnav-cash.is-warn .topnav-cash-dot {
    animation: none;
  }

  .topnav-more-panel,
  .topnav-user-panel {
    animation: none;
  }
}

/* Hairline dorado — firma de marca */
.appbar::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gold);
}

.appbar .grow {
  flex: 1;
  min-width: 0;
}

.appbar h1 {
  font-size: 1.05rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.appbar .sub {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appbar .eyebrow {
  margin-bottom: 2px;
}

.appbar-date {
  display: none;
  text-align: right;
  font-size: 0.74rem;
  line-height: 1.25;
  flex: none;
}

.appbar-date strong {
  display: block;
  font-weight: 700;
  color: var(--ink);
}

.appbar-date span {
  color: var(--muted);
}

.appbar-bell {
  display: inline-flex;
  flex: none;
}

/* —— Tabbar (móvil) —— */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-tabbar);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 4px 4px env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(20, 19, 15, 0.04);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 650;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.tab svg {
  width: 20px;
  height: 20px;
  flex: none;
}

.tab span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab.is-active {
  color: var(--ink);
}

/* Indicador activo — hairline oro */
.tab.is-active::after {
  content: '';
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 2px;
  background: var(--gold);
  border-radius: 1px;
}

@media (hover: hover) {
  .tab:hover {
    color: var(--ink-soft);
    background: var(--accent-soft);
  }
}

.tab:active {
  opacity: 0.88;
}

/* —— Tablet 768–1023 —— */
@media (min-width: 768px) and (max-width: 1023px) {
  .view {
    padding-inline: var(--space-5);
    padding-top: var(--space-4);
  }

  .appbar {
    margin-inline: calc(var(--space-5) * -1);
    padding: 12px var(--space-5) 14px;
    gap: var(--space-4);
  }

  .appbar h1 {
    font-size: 1.12rem;
  }

  .appbar .sub {
    font-size: 0.76rem;
    white-space: normal;
  }

  .appbar-date {
    display: grid;
    gap: 1px;
  }

  .tabbar {
    padding-inline: var(--space-2);
  }

  .tab {
    font-size: 0.68rem;
    gap: 3px;
  }

  .tab svg {
    width: 22px;
    height: 22px;
  }
}

/* —— Desktop ≥1024 — barra superior horizontal —— */
@media (min-width: 1024px) {
  .app {
    padding-top: var(--topnav-h);
    padding-left: 0;
  }

  .topnav {
    position: fixed;
    z-index: calc(var(--z-tabbar) + 10);
    inset: 0 0 auto 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    height: var(--topnav-h);
    padding: 0 clamp(14px, 2.2vw, 32px);
    background: #fffef9;
    border-bottom: 1px solid var(--line);
    border-right: 0;
    box-shadow: 0 1px 0 rgba(20, 19, 15, 0.03);
    overflow: visible;
  }

  .topnav::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    z-index: 5;
    height: 3px;
    background: var(--gold);
    pointer-events: none;
  }

  .topnav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 16px 0 0;
    padding: 0;
    border-radius: 2px;
    text-decoration: none;
    color: var(--ink);
    flex: none;
  }

  .topnav-brand:hover {
    text-decoration: none;
  }

  .logo,
  .av {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 2px;
    background: var(--ink);
    color: #fff;
    font-family: var(--display);
    font-weight: 850;
    font-size: 0.82rem;
    letter-spacing: -0.02em;
    flex: none;
  }

  .logo {
    border: 1px solid var(--ink);
    border-left: 3px solid var(--gold);
  }

  .topnav-brand-text {
    display: grid;
    gap: 1px;
    line-height: 1.1;
    min-width: 0;
  }

  .topnav-brand-text strong {
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 850;
    letter-spacing: -0.03em;
  }

  .topnav-brand-text small {
    color: var(--gold-strong, #9a7209);
    font-size: 0.6rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
  }

  .topnav-nav {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    align-self: stretch;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: visible;
    padding: 0;
    scrollbar-width: none;
  }

  .topnav-nav::-webkit-scrollbar {
    display: none;
  }

  .topnav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 100%;
    height: 100%;
    padding: 0 12px;
    border-radius: 0;
    color: var(--muted);
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: -0.01em;
    text-decoration: none;
    white-space: nowrap;
    transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
  }

  .topnav-link svg {
    width: 15px;
    height: 15px;
    flex: none;
    opacity: 0.72;
  }

  .topnav-link span {
    min-width: 0;
  }

  @media (hover: hover) {
    .topnav-link:hover {
      background: color-mix(in srgb, var(--surface-2) 70%, transparent);
      color: var(--ink);
      text-decoration: none;
    }

    .topnav-link:hover svg {
      opacity: 1;
    }
  }

  .topnav-link.is-active,
  .topnav-more.is-active > .topnav-link,
  .topnav-more.is-active > summary.topnav-link {
    background: transparent;
    color: var(--ink);
    font-weight: 800;
  }

  .topnav-link.is-active svg,
  .topnav-more.is-active > summary.topnav-link svg {
    opacity: 1;
  }

  .topnav-link.is-active::after,
  .topnav-more.is-active > .topnav-link::after,
  .topnav-more.is-active > summary.topnav-link::after {
    content: '';
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 0;
    top: auto;
    width: auto;
    height: 3px;
    background: var(--gold);
    border-radius: 2px 2px 0 0;
  }

  /* Más — fuera del scroll de .topnav-nav para que el panel no se recorte */
  .topnav-more {
    position: relative;
    align-self: stretch;
    display: flex;
    align-items: stretch;
    flex: none;
    margin-inline: 2px 4px;
    z-index: 2;
  }

  .topnav-more summary {
    list-style: none;
    cursor: pointer;
    height: 100%;
  }

  .topnav-more summary::-webkit-details-marker {
    display: none;
  }

  .topnav-more-chev {
    width: 0;
    height: 0;
    margin-left: 2px;
    border-left: 3.5px solid transparent;
    border-right: 3.5px solid transparent;
    border-top: 4px solid currentColor;
    opacity: 0.55;
    transition: transform 160ms var(--ease);
  }

  .topnav-more[open] .topnav-more-chev {
    transform: rotate(180deg);
    opacity: 0.9;
  }

  .topnav-more[open] > summary.topnav-link,
  .topnav-more.is-active > summary.topnav-link {
    background: transparent;
    color: var(--ink);
  }

  .topnav-more-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 120;
    width: min(300px, calc(100vw - 32px));
    max-height: min(70vh, 480px);
    overflow: auto;
    padding: 12px 8px 10px;
    background: #fffef9;
    border: 1px solid var(--line);
    border-radius: 2px;
    box-shadow:
      0 1px 2px rgba(20, 19, 15, 0.04),
      0 18px 40px -18px rgba(20, 19, 15, 0.28);
    animation: topnavMoreIn 180ms var(--ease) both;
  }

  .topnav-more-panel::before {
    content: "";
    position: absolute;
    left: 18px;
    top: -6px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-left: 1px solid var(--line);
    border-top: 1px solid var(--line);
    transform: rotate(45deg);
  }

  @keyframes topnavMoreIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .topnav-more-label {
    margin: 0 10px 8px;
    color: var(--gold-strong);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .topnav-more-label:not(:first-child) {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
  }

  .topnav-more-link {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 2px;
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
  }

  .topnav-more-ico {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--surface-2);
    color: var(--ink);
  }

  .topnav-more-ico svg {
    width: 16px;
    height: 16px;
  }

  .topnav-more-copy {
    display: grid;
    gap: 1px;
    min-width: 0;
  }

  .topnav-more-copy strong {
    color: var(--ink);
    font-size: 0.84rem;
    font-weight: 750;
    letter-spacing: -0.015em;
  }

  .topnav-more-copy em {
    color: var(--muted);
    font-size: 0.7rem;
    font-style: normal;
    font-weight: 550;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topnav-more-link svg {
    width: 16px;
    height: 16px;
    flex: none;
  }

  @media (hover: hover) {
    .topnav-more-link:hover {
      background: var(--surface-2);
      color: var(--ink);
      text-decoration: none;
    }

    .topnav-more-link:hover .topnav-more-ico {
      border-color: color-mix(in srgb, var(--ink) 16%, var(--line));
      background: #fff;
    }
  }

  .topnav-more-link.is-active {
    background: color-mix(in srgb, var(--gold-soft) 55%, #fff);
    color: var(--ink);
  }

  .topnav-more-link.is-active .topnav-more-ico {
    border-color: color-mix(in srgb, var(--gold) 35%, var(--line));
    background: #fff;
  }

  .topnav-aside {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0 0 0 auto;
    padding: 0 0 0 14px;
    border-top: 0;
    border-left: 1px solid var(--line);
    flex: none;
    position: relative;
    align-self: stretch;
  }

  .topnav-bell {
    position: static;
  }

  .topnav-bell .dot {
    top: 2px;
    right: 2px;
  }

  .topnav-user {
    position: relative;
    display: flex;
    align-items: stretch;
    align-self: stretch;
    flex: none;
    z-index: 2;
  }

  .topnav-user-sum {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 100%;
    margin: 0;
    padding: 0 8px 0 6px;
    border: 0;
    border-radius: 2px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    list-style: none;
  }

  .topnav-user-sum::-webkit-details-marker {
    display: none;
  }

  @media (hover: hover) {
    .topnav-user-sum:hover {
      background: color-mix(in srgb, var(--surface-2) 80%, transparent);
    }
  }

  .topnav-user[open] > .topnav-user-sum {
    background: color-mix(in srgb, var(--gold-soft) 40%, #fff);
  }

  .topnav-user[open] .topnav-more-chev {
    transform: rotate(180deg);
    opacity: 0.9;
  }

  .topnav-user .av {
    width: 32px;
    height: 32px;
    font-size: 0.78rem;
    background: var(--ink);
    color: #fff;
    border: 1px solid var(--ink);
    border-left: 3px solid var(--gold);
  }

  .topnav-user-meta {
    display: grid;
    min-width: 0;
    max-width: 110px;
    font-size: 0.74rem;
    line-height: 1.15;
  }

  .topnav-user-meta strong,
  .topnav-user-meta small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topnav-user-meta strong {
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  .topnav-user-meta small {
    color: var(--muted);
    font-size: 0.62rem;
    font-weight: 750;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .topnav-user-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 120;
    width: min(260px, calc(100vw - 24px));
    padding: 12px;
    background: #fffef9;
    border: 1px solid var(--line);
    border-radius: 2px;
    box-shadow:
      0 1px 2px rgba(20, 19, 15, 0.04),
      0 18px 40px -18px rgba(20, 19, 15, 0.28);
    animation: topnavMoreIn 180ms var(--ease) both;
  }

  .topnav-user-panel::before {
    content: "";
    position: absolute;
    right: 22px;
    top: -6px;
    width: 10px;
    height: 10px;
    background: #fffef9;
    border-left: 1px solid var(--line);
    border-top: 1px solid var(--line);
    transform: rotate(45deg);
  }

  .topnav-user-head {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 0 2px 12px;
    margin: 0 0 10px;
    border-bottom: 1px solid var(--line);
  }

  .topnav-user-head .av {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
  }

  .topnav-user-head strong {
    display: block;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
  }

  .topnav-user-head small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
  }

  .topnav-logout {
    margin: 0;
  }

  .topnav-logout-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 0.84rem;
    font-weight: 750;
    letter-spacing: -0.01em;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  }

  .topnav-logout-btn svg {
    width: 16px;
    height: 16px;
    flex: none;
    opacity: 0.75;
  }

  @media (hover: hover) {
    .topnav-logout-btn:hover {
      border-color: color-mix(in srgb, var(--danger) 28%, var(--line));
      background: color-mix(in srgb, var(--danger-soft) 55%, #fff);
      color: color-mix(in srgb, var(--danger) 80%, var(--ink));
    }

    .topnav-logout-btn:hover svg {
      opacity: 1;
    }
  }

  .topnav-logout-btn:disabled {
    opacity: 0.7;
    cursor: wait;
  }

  .view {
    padding: var(--space-5) clamp(20px, 2.8vw, 44px) var(--space-8);
  }

  .appbar {
    position: relative;
    margin: 0 0 var(--space-5);
    padding: 0 0 var(--space-4);
    background: transparent;
    border-bottom: 1px solid var(--line);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .appbar::before {
    display: none;
  }

  /* Debe ganar a .iconbtn { display: inline-flex } de components.css
     (misma especificidad; components carga después de shell). */
  .appbar .appbar-bell {
    display: none !important;
  }

  .appbar-date {
    display: grid;
    gap: 2px;
  }

  .appbar h1 {
    font-size: 1.2rem;
  }

  .appbar .sub {
    white-space: normal;
    font-size: 0.8rem;
  }

  .tabbar {
    display: none;
  }
}

@media (min-width: 1280px) {
  .topnav-brand-text {
    display: grid;
  }
}

@media (min-width: 1440px) {
  .view {
    padding-top: 28px;
  }

  .topnav {
    padding-inline: max(36px, calc((100vw - 1440px) / 2 + 24px));
  }
}
