/* ──────────────────────────────────────────────
   Layout: shell (topbar + sidebar + main)
   ────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "side topbar"
    "side main";
  min-height: 100vh;
}
.shell.no-sidebar {
  grid-template-columns: 1fr;
  grid-template-areas:
    "topbar"
    "main";
}

/* ──────────────────────────────
   Topbar
   ────────────────────────────── */
.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 900;
  height: var(--topbar-h);
  background: rgba(10,10,10,0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--hair);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  gap: 18px;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.topbar-brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.topbar-brand-link svg, .topbar-brand-link img {
  height: 22px;
  width: auto;
  flex-shrink: 0;
}
.topbar-brand-text {
  font-family: var(--ff-display);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.2px;
  color: var(--ink);
  white-space: nowrap;
}
.topbar-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--hair-2);
  border-radius: var(--r-sm);
  font-family: var(--ff-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-left: 6px;
}
.topbar-tag-ver {
  color: var(--accent);
  font-weight: 700;
}
.topbar-crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 18px;
  padding-left: 18px;
  border-left: 1px solid var(--hair-2);
  min-width: 0;
}
.topbar-crumb-item {
  font-family: var(--ff-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}
.topbar-crumb-item.active { color: var(--ink); }
.topbar-crumb-sep {
  color: var(--mute);
  font-size: 10px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Client switcher */
.client-switcher {
  position: relative;
}
.client-switcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--hair-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--t-mid), background var(--t-mid);
}
.client-switcher-btn:hover {
  border-color: var(--hair-3);
  background: var(--surface-3);
}
.client-switcher-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 10px currentColor;
  flex-shrink: 0;
}
.client-switcher-name {
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.client-switcher-domain {
  font-family: var(--ff-mono);
  font-size: 9px;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  text-transform: lowercase;
  margin-left: 4px;
}
.client-switcher-arrow {
  width: 12px;
  height: 12px;
  color: var(--ink-3);
  transition: transform var(--t-mid);
}
.client-switcher.open .client-switcher-arrow { transform: rotate(180deg); }
.client-switcher-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--hair-2);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  padding: 6px;
  z-index: 950;
  display: none;
}
.client-switcher.open .client-switcher-menu { display: block; }
.client-switcher-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.client-switcher-item:hover { background: var(--surface-2); }
.client-switcher-item.active { background: var(--brand-soft); }
.client-switcher-item .meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.client-switcher-item .meta-name {
  font-family: var(--ff-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.client-switcher-item .meta-domain {
  font-family: var(--ff-mono);
  font-size: 9px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
}

/* User pill */
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 4px;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid var(--hair-2);
  cursor: pointer;
  transition: border-color var(--t-mid);
}
.user-pill:hover { border-color: var(--hair-3); }
.user-pill-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: #0A0A0A;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  font-family: var(--ff-mono);
}
.user-pill-name {
  font-family: var(--ff-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* Logout button (subtle) */
.btn-logout {
  background: transparent;
  border: 1px solid var(--hair-2);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  color: var(--ink-3);
  font-family: var(--ff-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--t-mid), border-color var(--t-mid);
}
.btn-logout:hover { color: var(--danger); border-color: rgba(255,90,90,0.4); }

/* ──────────────────────────────
   Sidebar
   ────────────────────────────── */
.sidebar {
  grid-area: side;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  background: var(--bg);
  border-right: 1px solid var(--hair);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 200;
}
.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 22px;
  border-bottom: 1px solid var(--hair);
  gap: 10px;
}
.sidebar-brand img.ep-logo {
  height: 18px;
  width: auto;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
  opacity: 0.92;
}
.sidebar-brand svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.sidebar-brand-name {
  font-family: var(--ff-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.1px;
  color: var(--ink);
}
.sidebar-brand-tag {
  font-family: var(--ff-mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-left: 6px;
}

.sidebar-section {
  padding: 18px 18px 8px;
  font-family: var(--ff-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.nav { display: flex; flex-direction: column; counter-reset: navitem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 22px 11px 18px;
  cursor: pointer;
  color: var(--ink-3);
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color var(--t-fast), background var(--t-fast);
  border: none;
  border-left: 2px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
  counter-increment: navitem;
}
.nav-item::before {
  content: counter(navitem, decimal-leading-zero);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--mute);
  font-weight: 500;
  min-width: 18px;
  transition: color var(--t-fast);
}
.nav-item:hover {
  color: var(--ink);
  background: rgba(255,255,255,0.02);
}
.nav-item:hover::before { color: var(--brand); }
.nav-item.active {
  color: var(--brand);
  background: var(--brand-soft);
  border-left-color: var(--brand);
}
.nav-item.active::before { color: var(--brand); }
.nav-item .icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
}
.nav-item .icon svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.4;
}
.nav-item .badge-tiny {
  margin-left: auto;
  padding: 1px 6px;
  background: var(--surface-3);
  color: var(--ink-2);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.nav-item.active .badge-tiny { background: var(--brand); color: #000; }

/* Grouped sidebar nav */
.nav-grouped { gap: 0; padding-bottom: 8px; }
.nav-group { display: flex; flex-direction: column; border-bottom: 1px solid var(--hair); }
.nav-group:last-child { border-bottom: none; }
.nav-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 18px 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--ff-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-3);
  transition: color var(--t-fast);
}
.nav-group-head:hover { color: var(--ink); }
.nav-group-label { flex: 1; text-align: left; }
.nav-group-count {
  font-size: 8px;
  font-weight: 600;
  color: var(--mute);
  letter-spacing: 0.06em;
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--hair);
}
.nav-group-chevron {
  font-size: 11px;
  color: var(--mute);
  transition: transform 0.18s ease, color var(--t-fast);
  display: inline-block;
}
.nav-group.collapsed .nav-group-chevron { transform: rotate(180deg); }
.nav-group-head:hover .nav-group-chevron { color: var(--brand); }

.nav-group-items {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 800px;
  transition: max-height 0.25s ease, opacity 0.18s ease;
  counter-reset: navitem;
}
.nav-group.collapsed .nav-group-items {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}
.nav-grouped .nav-item {
  padding-left: 28px;
  padding-top: 8px;
  padding-bottom: 8px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  counter-increment: navitem;
}
.nav-grouped .nav-item::before { content: ''; min-width: 0; }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--hair);
}
.sidebar-foot-version {
  font-family: var(--ff-mono);
  font-size: 9px;
  color: var(--mute);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* ──────────────────────────────
   Main view
   ────────────────────────────── */
.main {
  grid-area: main;
  padding: 28px 32px 80px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* View header */
.view-h {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--hair);
}
.view-h-l { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.view-h-eyebrow {
  font-family: var(--ff-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}
.view-h-title {
  font-family: var(--ff-display);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.05;
  color: var(--ink);
}
.view-h-lede {
  color: var(--ink-2);
  font-size: 14px;
  margin-top: 4px;
}
.view-h-r {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ─── Global dashboard: última actividad por cliente ─── */
.gd-client-last {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-family: 'Noto Sans Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink-3, rgba(0,0,0,0.55));
}
.gd-last-dot { font-size: 11px; line-height: 1; }
.gd-client-last-fresh .gd-last-dot { color: #22c55e; }
.gd-client-last-ok    .gd-last-dot { color: #fbbf24; }
.gd-client-last-stale .gd-last-dot { color: rgba(0,0,0,0.3); }
.gd-last-rel { font-weight: 700; color: var(--ink-2, rgba(0,0,0,0.78)); }
.gd-last-abs { color: var(--ink-3, rgba(0,0,0,0.4)); font-size: 9px; }

/* ─── Admin "Última actualización" cell ─── */
.admin-last-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Noto Sans Mono', monospace;
  font-size: 10px;
}
.admin-last-dot {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}
.admin-last-fresh .admin-last-dot { color: #22c55e; }
.admin-last-ok    .admin-last-dot { color: #fbbf24; }
.admin-last-stale .admin-last-dot { color: rgba(0,0,0,0.3); }
.admin-last-stack { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.admin-last-rel { font-weight: 700; color: var(--ink-1, rgba(0,0,0,0.92)); font-size: 11px; }
.admin-last-abs { color: var(--ink-3, rgba(0,0,0,0.55)); font-size: 9px; letter-spacing: 0.04em; }

/* ─── FreshnessBar (per page module) ─── */
.fresh-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--ink-4, rgba(0,0,0,0.1));
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.02);
  font-family: 'Noto Sans Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  flex-wrap: wrap;
}
.fresh-bar-l, .fresh-bar-r { display: flex; align-items: center; gap: 10px; }
.fresh-bar-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.fresh-bar-fresh .fresh-bar-dot { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.5); }
.fresh-bar-ok    .fresh-bar-dot { background: #fbbf24; }
.fresh-bar-stale .fresh-bar-dot { background: #ef4444; }
.fresh-bar-running .fresh-bar-dot { background: #ea8fd7; animation: fb-pulse 1s ease-in-out infinite; }
@keyframes fb-pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.4;transform:scale(0.7)} }
.fresh-bar-lbl {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-2, rgba(0,0,0,0.78));
  font-size: 10px;
}
.fresh-bar-time { color: var(--ink-1, rgba(0,0,0,0.92)); font-weight: 700; }
.fresh-bar-cost {
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
}
.fresh-bar-cost-paid { color: #fbbf24; border-color: rgba(251,191,36,0.4); background: rgba(251,191,36,0.06); }
.fresh-bar-cost-free { color: #22c55e; border-color: rgba(34,197,94,0.4); background: rgba(34,197,94,0.06); }
.fresh-bar-btn { font-size: 11px !important; }
.fresh-bar-btn .spin { display: inline-block; animation: fb-spin 1s linear infinite; }
@keyframes fb-spin { from{transform:rotate(0)} to{transform:rotate(360deg)} }

/* ─── Última actualización badge ─── */
.last-update {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 6px 12px;
  border: 1px solid var(--ink-4, rgba(0,0,0,0.1));
  border-radius: 4px;
  font-family: 'Noto Sans Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.02);
  width: fit-content;
}
.last-update-fresh {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.05);
}
.last-update-fresh .lu-icon { color: #22c55e; }
.last-update-ok {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.05);
}
.last-update-ok .lu-icon { color: #fbbf24; }
.last-update-stale {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.05);
}
.last-update-stale .lu-icon { color: #ef4444; }

.lu-icon { font-size: 14px; line-height: 1; }
.lu-label { color: var(--ink-3, rgba(0,0,0,0.55)); text-transform: uppercase; letter-spacing: 0.12em; font-size: 9.5px; }
.lu-time { font-weight: 700; color: var(--ink-1, rgba(0,0,0,0.92)); }
.lu-iso { color: var(--ink-3, rgba(0,0,0,0.55)); font-size: 10px; padding-left: 8px; border-left: 1px dashed var(--ink-4, rgba(0,0,0,0.1)); }

.lu-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  max-width: 920px;
}
.lu-source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid var(--ink-4, rgba(0,0,0,0.08));
  border-radius: 3px;
  font-family: 'Noto Sans Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.04em;
}
.lu-source-dot { font-size: 10px; line-height: 1; }
.lu-source-fresh .lu-source-dot { color: #22c55e; }
.lu-source-ok    .lu-source-dot { color: #fbbf24; }
.lu-source-stale .lu-source-dot { color: rgba(0,0,0,0.3); }
.lu-source-lbl { color: var(--ink-2, rgba(0,0,0,0.78)); text-transform: uppercase; }
.lu-source-time { color: var(--ink-3, rgba(0,0,0,0.55)); }

/* Section bar (with insight strip) */
.section-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--hair);
}
.section-bar .num {
  font-family: var(--ff-mono);
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.section-bar .label {
  font-family: var(--ff-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--ink);
}
.section-bar .meta {
  font-family: var(--ff-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-left: auto;
}

/* Insight strip (g777 fo-strip) */
.insight-strip {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  background: var(--bg-elev);
  border: 1px solid var(--hair);
  border-radius: var(--r);
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.insight-strip-mini {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 18px;
  border-right: 1px solid var(--hair-1);
}
.insight-strip-mini:last-of-type { border-right: none; }
.insight-strip-l {
  font-family: var(--ff-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.insight-strip-v {
  font-family: var(--ff-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.insight-strip-s {
  font-family: var(--ff-mono);
  font-size: 9px;
  color: var(--ink-3);
}
.insight-strip-verdict {
  margin-left: auto;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-family: var(--ff-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  border: 1px solid;
}
.insight-strip-verdict.success {
  background: rgba(76,209,122,0.10);
  border-color: rgba(76,209,122,0.3);
  color: var(--green);
}
.insight-strip-verdict.danger {
  background: rgba(255,90,90,0.10);
  border-color: rgba(255,90,90,0.3);
  color: var(--red);
}
.insight-strip-verdict.halo {
  background: linear-gradient(90deg, rgba(246,178,58,0.18), rgba(234,143,215,0.12));
  border-color: rgba(246,178,58,0.4);
  color: var(--orange);
}

/* Toast & modal hosts (handled in components.css) */

/* Mobile */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    width: 80vw;
    max-width: 280px;
    transform: translateX(-100%);
    transition: transform var(--t-slow);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 6px 0 30px rgba(0,0,0,0.5); }
  .main { padding: 18px 16px 60px; }
  .view-h-title { font-size: 24px; }
  .topbar { padding: 0 12px; }
  .topbar-tag { display: none; }
  .topbar-crumb { display: none; }
  .topbar-hamburger { display: inline-flex !important; }
  .topbar-cmd-label { display: none; }
  .sidebar-backdrop.show { display: block !important; }
}

/* Hamburger (hidden on desktop) */
.topbar-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--hair);
  border-radius: 6px;
  color: var(--ink-2);
  cursor: pointer;
  margin-right: 10px;
  transition: all var(--t-fast);
}
.topbar-hamburger:hover { color: var(--ink); border-color: rgba(234,143,215,0.30); }
.topbar-hamburger svg { width: 18px; height: 18px; }

/* Sidebar backdrop (mobile drawer) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.50);
  backdrop-filter: blur(4px);
  z-index: 199;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { 0% { opacity: 0; } 100% { opacity: 1; } }
