/*
 * QAFind Control — console shell.
 *
 * Layout contract (tests/console-layout.test.js):
 *   .app > aside      sticky sidebar, exactly --sidebar-w (< 300px), beside the main column
 *   .app > .main-shell  starts at the sidebar's right edge and ends at the viewport's right edge
 *   at <=860px         the sidebar collapses to a brand + Menu bar, page content first
 */

@import url("/ui/tokens.css");
@import url("/ui/base.css");
@import url("/ui/components.css");

body {
  background: var(--paper-0);
  font-size: var(--fz-md);
}

/* =====================================================================
   App frame
   ===================================================================== */

.app {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}

.main-shell {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =====================================================================
   Sidebar
   ===================================================================== */

.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--ink-0);
  color: var(--bone-0);
}

.primary-nav {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: var(--sp-4) var(--sp-3);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  color: var(--bone-0);
  text-decoration: none;
}

.brand:hover {
  color: var(--bone-0);
  text-decoration: none;
}

.brand__mark {
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  object-fit: contain;
  display: block;
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand__name {
  color: var(--bone-0);
  font-size: var(--fz-md);
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.brand__sub {
  color: var(--bone-2);
  font-family: var(--font-mono);
  font-size: 9.5px;
}

.nav-toggle {
  display: none;
  color: var(--bone-1);
  border-color: var(--line-ink-strong);
}

.sidebar :focus-visible {
  outline-color: var(--focus-ink);
}

/* Workspace switcher */

.ws-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-ink);
  border-radius: var(--r-2);
  background: var(--ink-1);
  color: var(--bone-0);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    background-color var(--dur-1) var(--ease-out),
    border-color var(--dur-1) var(--ease-out);
}

.ws-switch:hover:not(:disabled) {
  background: var(--ink-2);
  border-color: var(--line-ink-strong);
}

.ws-switch:disabled {
  cursor: default;
}

.ws-switch__mark {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: var(--r-2);
  background: var(--signal);
  color: #fff;
  font-size: var(--fz-sm);
  font-weight: var(--fw-semibold);
}

.ws-switch__text {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.ws-switch__name {
  overflow: hidden;
  color: var(--bone-0);
  font-size: var(--fz-sm);
  font-weight: var(--fw-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ws-switch__plan {
  overflow: hidden;
  color: var(--bone-2);
  font-size: var(--fz-2xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ws-switch__chev {
  flex: 0 0 auto;
  fill: none;
  stroke: var(--bone-2);
  stroke-width: 1.4;
}

/* Primary action */

.sidebar__cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: var(--sp-3);
  padding: 10px;
  border-radius: var(--r-2);
  background: var(--signal-ink);
  color: #fff;
  font-size: var(--fz-sm);
  font-weight: var(--fw-medium);
  text-decoration: none;
  transition:
    background-color var(--dur-1) var(--ease-out),
    transform 80ms var(--ease-out);
}

.sidebar__cta:hover {
  background: var(--signal-hover);
  color: #fff;
  text-decoration: none;
}

.sidebar__cta:active {
  transform: scale(0.985);
}

.sidebar__cta-dot {
  fill: #fff;
}

.sidebar__cta-ring {
  fill: none;
  stroke: #fff;
  stroke-width: 1.2;
}

/* Navigation groups */

.nav-groups {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: var(--sp-4);
}

.nav-group__title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
  padding: 0 10px;
  color: var(--bone-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.nav-group__preview {
  padding: 0 4px;
  border: 1px solid rgba(216, 203, 179, 0.35);
  border-radius: var(--r-1);
  color: var(--sand);
  font-size: 9.5px;
}

.nav-group__list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cn-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-2);
  color: var(--bone-1);
  font-size: 13.5px;
  text-decoration: none;
  transition:
    background-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}

.cn-icon {
  flex: none;
  fill: none;
  stroke: var(--bone-2);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cn-item:hover {
  background: var(--ink-1);
  color: var(--bone-0);
  text-decoration: none;
}

.cn-item.is-active {
  background: var(--ink-2);
  box-shadow: inset 2px 0 0 var(--signal);
  color: #fff;
}

.cn-item.is-active .cn-icon {
  stroke: var(--signal-bright);
}

.cn-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cn-badge {
  padding: 1px 6px;
  border-radius: var(--r-1);
  background: var(--ink-2);
  color: var(--bone-1);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.cn-badge[hidden] {
  display: none;
}

/* Sidebar foot */

.sidebar__foot {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: auto;
  padding-top: var(--sp-5);
}

.usage-card {
  padding: var(--sp-3);
  border: 1px solid var(--line-ink);
  border-radius: var(--r-2);
}

.usage-card__line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--fz-xs);
}

.usage-card__line > span:first-child {
  color: var(--bone-1);
}

#usage-count {
  color: var(--bone-0);
  font-family: var(--font-mono);
}

.usage-card .meter {
  height: 4px;
  margin-top: 8px;
  border-radius: 1px;
  background: var(--ink-2);
}

#usage-bar {
  width: 64%;
  height: 4px;
  border-radius: 1px;
  background: var(--signal-bright);
  transition: width var(--dur-3) var(--ease-out);
}

#usage-bar[data-level="warn"] {
  background: var(--warn);
}

#usage-bar[data-level="danger"] {
  background: var(--bad);
}

.usage-reset {
  display: block;
  margin-top: 6px;
  color: var(--bone-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.usage-card__link {
  display: inline-block;
  margin-top: 10px;
  color: var(--signal-bright);
  font-size: var(--fz-xs);
  text-decoration: none;
}

.usage-card__link:hover {
  color: var(--signal-bright);
  text-decoration: underline;
}

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--line-ink);
}

.profile .avatar {
  width: 30px;
  height: 30px;
  background: var(--sand);
  color: var(--ink-0);
  font-size: var(--fz-xs);
  font-weight: var(--fw-semibold);
}

.profile__text {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.profile__name {
  overflow: hidden;
  color: var(--bone-0);
  font-size: var(--fz-sm);
  font-weight: var(--fw-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile__role {
  overflow: hidden;
  color: var(--bone-2);
  font-size: var(--fz-2xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-button {
  display: inline-flex;
  padding: 8px;
  border: 0;
  border-radius: var(--r-2);
  background: transparent;
  cursor: pointer;
}

.profile-button svg {
  fill: var(--bone-2);
}

.profile-button:hover {
  background: var(--ink-2);
}

.profile-button:hover svg {
  fill: var(--bone-0);
}

/* =====================================================================
   Sample-mode banner
   ===================================================================== */

.sample-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 9px var(--content-pad-x);
  border-bottom: 1px solid var(--line-0);
  background: var(--paper-2);
  box-shadow: inset 3px 0 0 var(--signal);
  color: var(--text-1);
  font-size: var(--fz-sm);
}

.sample-banner[hidden] {
  display: none;
}

.sample-banner strong {
  color: var(--text-0);
  font-weight: var(--fw-semibold);
}

.sample-banner a {
  color: var(--signal-ink);
  font-weight: var(--fw-medium);
}

/* =====================================================================
   Topbar
   ===================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  min-height: var(--topbar-h);
  padding: 8px var(--content-pad-x);
  border-bottom: 1px solid var(--line-0);
  background: #fff;
}

.topbar .breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 200px;
  min-width: 0;
  font-size: var(--fz-sm);
}

.topbar .breadcrumb #crumb-workspace {
  color: var(--text-2);
}

.topbar .breadcrumb__sep {
  color: var(--line-2);
}

.topbar .breadcrumb strong {
  color: var(--text-0);
  font-weight: var(--fw-semibold);
}

.topbar__search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 240px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-1);
  border-radius: var(--r-2);
  background: #fff;
}

.topbar__search-icon {
  flex: none;
  fill: none;
  stroke: var(--text-2);
  stroke-width: 1.5;
}

.topbar__search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: var(--fz-sm);
}

.topbar__search kbd {
  padding: 1px 5px;
  border: 1px solid var(--line-0);
  border-radius: var(--r-1);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.topbar__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
}

.topbar__link {
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--text-0);
  font: inherit;
  font-size: var(--fz-sm);
  cursor: pointer;
}

.topbar__link:hover {
  background: var(--paper-2);
}

.topbar .topbar__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 4px 8px;
  border: 0;
  border-radius: var(--r-1);
  background: var(--sand-soft);
  color: var(--sand-ink);
  font-family: var(--font-mono);
  font-size: var(--fz-2xs);
}

.topbar__chip .chip__dot,
.topbar__chip .chip-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--warn);
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--ok);
}

.topbar__chip .chip-dot {
  background: var(--ok);
}

.chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__avatar {
  width: 32px;
  height: 32px;
  border: 0;
  background: var(--sand);
  color: var(--text-0);
  font-size: var(--fz-xs);
  font-weight: var(--fw-semibold);
  cursor: pointer;
}

.topbar__avatar:hover {
  background: var(--signal-soft);
  color: var(--signal-soft-ink);
}

/* =====================================================================
   Content
   ===================================================================== */

.content-wrap {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--content-pad-x) var(--sp-12);
}

.view-main {
  min-width: 0;
}

.view-panel[hidden] {
  display: none !important;
}

/* Common in-view rhythm helpers */
.view-stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* =====================================================================
   Footer
   ===================================================================== */

.app-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 14px var(--content-pad-x);
  border-top: 1px solid var(--line-0);
  background: var(--paper-1);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.app-footer a {
  color: var(--text-1);
  text-decoration: none;
}

.app-footer a:hover {
  color: var(--text-0);
  text-decoration: underline;
}

.app-footer__status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-footer__status i {
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--ok);
}

/* =====================================================================
   Boot failure fallback (dashboard.js appends .boot-error to body)
   ===================================================================== */

.boot-error {
  max-width: 560px;
  margin: 12vh auto;
  padding: var(--sp-6);
  border: 1px solid var(--line-1);
  border-left: 3px solid var(--bad);
  border-radius: var(--r-3);
  background: var(--paper-1);
}

.boot-error h1 {
  margin-bottom: var(--sp-2);
  font-size: var(--fz-xl);
}

.boot-error p {
  margin-bottom: var(--sp-4);
  color: var(--text-2);
}

.boot-error button {
  min-height: 34px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-2);
  background: var(--ink-0);
  color: var(--bone-0);
  font-weight: var(--fw-semibold);
}

/* =====================================================================
   Responsive shell
   ===================================================================== */

@media (max-width: 1080px) {
  .topbar__search {
    flex: 1 1 200px;
  }
}

@media (max-width: 860px) {
  .app {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar {
    position: sticky;
    top: 0;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--ink-2);
  }

  .primary-nav {
    height: auto;
    padding: 10px var(--sp-4);
    gap: var(--sp-3);
    overflow: visible;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .brand {
    padding-bottom: 4px;
  }

  .sidebar__foot {
    margin-top: var(--sp-4);
  }

  .sidebar:not([data-open="true"]) .ws-switch,
  .sidebar:not([data-open="true"]) .sidebar__cta,
  .sidebar:not([data-open="true"]) .nav-groups,
  .sidebar:not([data-open="true"]) .sidebar__foot {
    display: none;
  }

  .sidebar[data-open="true"] .primary-nav {
    max-height: calc(100vh - 12px);
    overflow-y: auto;
  }

  .main-shell {
    min-height: 0;
  }

  .topbar {
    position: static;
    padding: 8px var(--sp-4);
    gap: 8px;
  }

  .topbar .breadcrumb {
    flex: 1 1 100%;
    order: 1;
  }

  .topbar__actions {
    order: 2;
    width: 100%;
  }

  .topbar__search {
    order: 3;
    flex: 1 1 100%;
  }

  .topbar .chip {
    max-width: 100%;
  }

  .sample-banner {
    padding: 10px var(--sp-4);
  }

  .content-wrap {
    padding: var(--sp-4) var(--sp-4) var(--sp-10);
  }

  .app-footer {
    padding: 12px var(--sp-4);
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 420px) {
  .topbar__actions .btn span {
    display: none;
  }

  .topbar__actions {
    gap: 6px;
  }
}


.app-footer__github {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.app-footer__stars {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.app-footer__stars[hidden] {
  display: none !important;
}
