/*
 * In-app page tabs. Pair with app-tabs.js.
 * Retheme with the custom properties below; the defaults are a neutral light theme.
 * Assumes the shell is: body > .frame (sidebar + .stage) and .stage = top bar + [data-tab-views].
 * Rename .desk-frame / .desk-stage / .desk-side / .desk-top to the host app's classes.
 */
:root {
  --tabs-ink: #121826;
  --tabs-muted: #64748b;
  --tabs-faint: #94a3b8;
  --tabs-accent: #00aa85;
  --tabs-line: #e6edf5;
  --tabs-hover-bg: rgba(255, 255, 255, 0.62);
  --tabs-active-bg: #fff;
  --tabs-close-hover: #f4f7fb;
  --tabs-canvas: #eef6f3;
  --tabs-shadow: 0 2px 6px rgba(21, 34, 56, 0.04);
  --tabs-ring: 0 0 0 4px rgba(0, 170, 133, 0.12);
}

/* ---- shell: fills the window; the active tab's iframe fills the content area ---- */
body.is-shell { height: 100vh; height: 100dvh; overflow: hidden; }
body.is-shell .desk-frame { height: 100%; min-height: 0; }
body.is-shell .desk-stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
[data-tab-views] { position: relative; flex: 1; min-height: 0; }
.app-tab-view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--tabs-canvas);
  /* visibility (not display:none) keeps hidden tabs laid out, so charts and scroll positions survive */
  visibility: hidden;
}
.app-tab-view.is-active { visibility: visible; }

/* ---- page inside a tab ---- */
body.is-embed { min-height: 100vh; padding: 0; margin: 0; background: var(--tabs-canvas); }
/* fallback: a full page that landed in a tab hides its own chrome */
html.is-tab-frame body { padding: 0; background: var(--tabs-canvas); }
html.is-tab-frame .desk-side,
html.is-tab-frame .desk-top { display: none !important; }

/* ---- tab strip (sits in the top bar where the spacer was) ---- */
[data-tab-strip] {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
[data-tab-strip]::-webkit-scrollbar { display: none; }
.app-tab {
  flex: 0 1 196px;
  min-width: 118px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 0 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--tabs-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.app-tab:hover { background: var(--tabs-hover-bg); color: var(--tabs-ink); }
.app-tab.is-active { background: var(--tabs-active-bg); border-color: var(--tabs-line); color: var(--tabs-ink); box-shadow: var(--tabs-shadow); }
.app-tab:focus-visible { outline: none; border-color: var(--tabs-accent); box-shadow: var(--tabs-ring); }
.app-tab.is-dragging { opacity: 0.45; }
.app-tab-icon {
  position: relative;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  color: var(--tabs-faint);
}
.app-tab-icon svg { width: 16px; height: 16px; }
.app-tab.is-active .app-tab-icon { color: var(--tabs-accent); }
.app-tab.is-loading .app-tab-icon svg { visibility: hidden; }
.app-tab.is-loading .app-tab-icon::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--tabs-accent) 18%, transparent);
  border-top-color: var(--tabs-accent);
  animation: app-tab-spin 0.7s linear infinite;
}
.app-tab-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.app-tab-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tabs-faint);
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
}
.app-tab-close svg { width: 14px; height: 14px; }
.app-tab:hover .app-tab-close,
.app-tab.is-active .app-tab-close,
.app-tab:focus-visible .app-tab-close { opacity: 1; }
.app-tab-close:hover { background: var(--tabs-close-hover); color: var(--tabs-ink); }
[data-tab-strip].is-single .app-tab-close { display: none; }
@keyframes app-tab-spin { to { transform: rotate(360deg); } }

/* desktop only: below the breakpoint the strip keeps its space but hides; links load in the visible tab */
@media (max-width: 1023px) {
  [data-tab-strip] { visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .app-tab.is-loading .app-tab-icon::after { animation-duration: 1.6s; }
}
