/*
 * Application shell only: sidebar footer block, topbar identity, and the
 * failed-page message. Loaded after theme.css, so it may set the few layout
 * properties theme.css does not own. Colours and sizes come from --tv-* tokens;
 * the bottom block deliberately inherits the existing `.sidebar nav a` styling
 * instead of restating it.
 */

/* ---------- Sidebar navigation ---------- */
.sidebar {
  box-shadow: inset 0 0 0 1px var(--tv-border);
}

.sidebar > nav {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.workspace-nav-icon {
  display: block;
  order: -1;
  flex: 0 0 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar nav a {
  position: relative;
  color: var(--tv-text-2);
}

.sidebar nav a .workspace-nav-icon {
  color: var(--tv-text-3);
}

.sidebar nav a:hover {
  background: var(--tv-surface);
}

.sidebar nav a:hover .workspace-nav-icon,
.sidebar nav a.active .workspace-nav-icon {
  color: inherit;
}

.sidebar nav a.active {
  background: var(--tv-trade-brand-soft);
  color: var(--tv-trade-brand-hover);
  box-shadow: none;
  font-weight: 700;
}

.sidebar nav a.active::before {
  content: "";
  position: absolute;
  inset-block: 10px;
  inset-inline-start: 0;
  width: 2px;
  border-radius: 2px;
  background: currentColor;
}

.workspace-navigation-toggle {
  display: none;
}

.sidebar > nav .nav-bottom {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: auto;
  padding-top: var(--tv-s4);
}

@media (max-width: 800px) {
  .sidebar { padding: 8px 10px; }
  .sidebar .brand { margin: 0; min-height: 44px; }
  .sidebar .brand-mark { max-width: 62%; }
  .workspace-navigation-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 12px;
    margin-inline-start: auto;
    border: 1px solid transparent;
    border-radius: var(--tv-radius);
    background: var(--tv-surface);
    color: var(--tv-text);
    font-size: var(--tv-fs-md);
    font-weight: 650;
    cursor: pointer;
    transition: background var(--tv-motion), color var(--tv-motion);
  }
  .workspace-navigation-toggle:hover,
  .workspace-navigation-toggle[aria-expanded="true"] {
    background: var(--tv-trade-brand-soft);
    color: var(--tv-trade-brand-hover);
  }
  .sidebar > nav {
    display: none;
    max-height: 66dvh;
    overflow: auto;
    margin-top: 8px;
  }
  .sidebar:has(.workspace-navigation-toggle[aria-expanded="true"]) > nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 8px;
  }
  .sidebar nav .nav-group {
    flex-direction: column;
    margin: 0;
  }
  .sidebar nav .nav-group-label { display: block; }
  .sidebar nav a { min-height: 44px; white-space: normal; }
  .sidebar > nav .nav-bottom {
    flex-direction: column;
    margin-top: 0;
    padding-top: 0;
  }
}

.sidebar nav a:focus-visible,
.workspace-navigation-toggle:focus-visible {
  outline: 2px solid var(--tv-trade-brand);
  outline-offset: -2px;
}

@media (prefers-reduced-motion: reduce) {
  .workspace-navigation-toggle { transition: none; }
  .button:active:not(:disabled), .ghost:active:not(:disabled),
  .tv-btn:active:not(:disabled), .tv-btn--ghost:active:not(:disabled) { transform: none; }
}

/* ---------- Topbar: one status dot on the left, the operator on the right ---------- */
.topbar,
body[data-view=dashboard] .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tv-s4);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: var(--tv-s2);
}

/* The API status button is the single status point: a dot, never a word.
   Its text stays in the DOM as the accessible name. */
#healthButton {
  width: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  border: 1px solid var(--tv-border-strong);
  border-radius: var(--tv-radius-full);
  background: var(--tv-surface);
  font-size: 0;
  line-height: 0;
  color: transparent;
}

#healthButton::before {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  margin: auto;
  border-radius: var(--tv-radius-full);
  background: var(--tv-text-3);
}

#healthButton:hover::before {
  background: var(--tv-brand);
}

/* app.js keeps updating the data-source wording; the same fact is shown in
   Settings next to the provider list, so the shell shows one status dot only. */
#dataBadge {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--tv-s2);
  flex: 0 0 auto;
}

.topbar-avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius-full);
  background: var(--tv-surface);
  color: var(--tv-text-2);
  font-size: var(--tv-fs-xs);
  font-weight: 600;
}

.topbar-name {
  font-size: var(--tv-fs-sm);
  color: var(--tv-text-3);
}

/* ---------- A page whose module or stylesheet never arrived ---------- */
.page-load-error {
  margin: 0;
  padding: var(--tv-s4);
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  background: var(--tv-surface);
  color: var(--tv-text-2);
  font-size: var(--tv-fs-md);
}
