:root {
  --corinth-bg: #f5f6f8;
  --corinth-surface: #ffffff;
  --corinth-border: #dde2ea;
  --corinth-text: #1a1f2b;
  --corinth-muted: #5b6578;
  --corinth-accent: #23588e;
  --corinth-accent-muted: #5e8ec2;
  --corinth-radius: 8px;
  --corinth-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  --corinth-header-h: 56px;
  --corinth-drawer-rail: 44px;
  --corinth-drawer-icon-size: 24px;
  --corinth-drawer-open-min: 140px;
  --corinth-drawer-title-rail-width: 20px;
  --corinth-content-pad-x: 0.75rem;
  --corinth-content-pad-y: 0.75rem;
  --corinth-control-min-h: 40px;
  --corinth-header-control-h: 34px;
  --corinth-tab-strip-h: 48px;
}

body:has(.corinth-root) {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.corinth-root {
  height: 100vh;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  background: var(--corinth-bg);
  color: var(--corinth-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.corinth-root * {
  box-sizing: border-box;
}

.corinth-header {
  flex: 0 0 var(--corinth-header-h);
  display: grid;
  grid-template-columns: minmax(220px, auto) minmax(280px, 1fr) auto;
  align-items: center;
  gap: 0.8rem;
  padding: 0 1rem;
  background: var(--corinth-surface);
  border-bottom: 1px solid var(--corinth-border);
  box-shadow: var(--corinth-shadow);
  z-index: 4;
}

.corinth-header__brand,
.corinth-header__brand a {
  display: flex;
  align-items: center;
  text-decoration: none;
  min-width: 0;
}

.corinth-header__icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.corinth-header__title {
  margin: 0 0 0 0.75rem;
  font-size: 1.04rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--corinth-text);
}

.corinth-header__search {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.corinth-header__search .MuiAutocomplete-root {
  width: 100%;
  max-width: 500px;
}

.corinth-header__search .MuiFormControl-root {
  margin-top: 0;
  margin-bottom: 0;
}

.corinth-header__search .MuiOutlinedInput-root,
.corinth-header__search .MuiOutlinedInput-notchedOutline {
  border-radius: 999px;
}

.corinth-header__search .MuiOutlinedInput-root {
  height: var(--corinth-header-control-h);
  min-height: var(--corinth-header-control-h);
  padding-left: 12px;
  padding-right: 12px;
  font-size: 1rem;
  align-items: center !important;
}

.corinth-header__search .MuiInputBase-input {
  font-size: 1rem;
  line-height: 1.2;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  text-align: center;
  align-self: center;
}

.corinth-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

.corinth-header__actions a {
  text-decoration: none;
}

.corinth-header__language {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  height: var(--corinth-header-control-h);
  padding: 0 0.2rem 0 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--corinth-border);
  background: var(--corinth-surface);
  box-sizing: border-box;
}

.corinth-header__language-icon {
  display: inline-flex;
  flex: 0 0 20px;
  align-items: center;
  justify-content: center;
  color: var(--corinth-muted);
}

.corinth-header__language-icon svg {
  display: block;
  width: 20px;
  height: 20px;
}

.corinth-header__language:hover {
  border-color: var(--corinth-muted);
}

.corinth-header__language:focus-within {
  border-color: var(--corinth-accent);
}

.corinth-header__language .MuiAutocomplete-root {
  width: 120px;
  flex: 0 0 120px;
}

.corinth-header__language .MuiFormControl-root {
  margin-top: 0;
  margin-bottom: 0;
  min-width: 120px;
  width: 120px;
}

.corinth-header__language .MuiAutocomplete-inputRoot.MuiOutlinedInput-root {
  height: auto;
  min-height: 0;
  padding: 0 22px 0 0 !important;
  font-size: 0.84rem;
  background: transparent;
}

.corinth-header__language .MuiOutlinedInput-notchedOutline {
  border: none;
}

.corinth-header__language .MuiAutocomplete-inputRoot:hover,
.corinth-header__language .MuiAutocomplete-inputRoot.Mui-focused {
  box-shadow: none;
}

.corinth-header__language .MuiAutocomplete-inputRoot:hover .MuiOutlinedInput-notchedOutline,
.corinth-header__language .MuiAutocomplete-inputRoot.Mui-focused .MuiOutlinedInput-notchedOutline {
  border: none;
}

.corinth-header__language .MuiInputLabel-root {
  display: none;
}

.corinth-header__language .MuiAutocomplete-input {
  padding: 0 !important;
  min-width: 0;
  text-overflow: ellipsis;
  font-size: 0.84rem;
}

.corinth-header__language .MuiAutocomplete-endAdornment {
  right: 0;
}

.corinth-header__language .MuiAutocomplete-clearIndicator {
  display: none !important;
}

.corinth-header__language .MuiAutocomplete-popupIndicator {
  padding: 0;
}

.corinth-header__language .MuiAutocomplete-popupIndicator .MuiIconButton-root {
  padding: 2px;
}

.corinth-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--corinth-header-control-h);
  min-height: var(--corinth-header-control-h);
  padding: 0 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--corinth-accent);
  background: var(--corinth-accent);
  color: #fff;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.corinth-workspace,
.corinth-workspace__rcc-wrap,
.corinth-workspace__rcc-wrap>div {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  display: flex;
}

.corinth-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--corinth-surface);
  border-right: 1px solid var(--corinth-border);
}

.corinth-field--main {
  border-right: none;
  background: var(--corinth-bg);
  overflow: auto;
}

.corinth-field--info {
  border-right: none;
  border-left: 1px solid var(--corinth-border);
}

.corinth-workspace__rcc-wrap ._rc-branch {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

#corinth-book-list:has(.corinth-field--drawer > ._toggle-button[aria-expanded="true"]),
#corinth-book-outlet:has(.corinth-field--drawer > ._toggle-button[aria-expanded="true"]),
#corinth-filters:has(.corinth-field--drawer > ._toggle-button[aria-expanded="true"]),
#corinth-results:has(.corinth-field--drawer > ._toggle-button[aria-expanded="true"]),
#corinth-details:has(.corinth-field--drawer > ._toggle-button[aria-expanded="true"]),
#corinth-ai-references:has(.corinth-field--drawer > ._toggle-button[aria-expanded="true"]) {
  min-width: var(--corinth-drawer-open-min);
}

.corinth-drawer-title-rail {
  display: contents;
}

.corinth-drawer-head {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
}

/* Main column tabs use the same head markup as drawers; icon stays on the left (drawers use row-reverse for the vertical rail). */
.corinth-field--main .corinth-drawer-head {
  flex-direction: row;
  justify-content: flex-start;
}

.corinth-drawer-label {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--corinth-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.corinth-drawer-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 var(--corinth-drawer-icon-size);
  width: var(--corinth-drawer-icon-size);
  height: var(--corinth-drawer-icon-size);
  color: inherit;
}

.corinth-drawer-icon svg {
  display: block;
  width: var(--corinth-drawer-icon-size);
  height: var(--corinth-drawer-icon-size);
}

.corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-head {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  min-height: 0;
  flex: 1 1 auto;
}

.corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-icon {
  flex: 0 0 auto;
  width: 100%;
  min-height: var(--corinth-drawer-icon-size);
  padding: 0.4rem 0.45rem 0.45rem;
}

.corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-title-rail {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  align-items: center;
  justify-content: flex-start;
  width: var(--corinth-drawer-title-rail-width);
  max-width: var(--corinth-drawer-title-rail-width);
  border-top: 1px solid var(--corinth-border);
  padding-top: 0.35rem;
  margin: 0 auto;
}

.corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-label {
  display: block;
  width: var(--corinth-drawer-title-rail-width);
  max-width: var(--corinth-drawer-title-rail-width);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  text-align: center;
  line-height: 1.15;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

._toggle-button {
  cursor: pointer;
  width: 100%;
  min-height: var(--corinth-control-min-h);
  border: none;
  border-bottom: 1px solid var(--corinth-border);
  background: linear-gradient(180deg, #fafbfd 0%, var(--corinth-surface) 100%);
  color: var(--corinth-muted);
  display: flex;
  align-items: stretch;
  padding: 0.45rem 0.6rem;
}

.corinth-field--drawer>._toggle-button[aria-expanded="false"] {
  padding: 0;
  flex: 1 1 auto;
}

._toggle-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: var(--corinth-content-pad-y) var(--corinth-content-pad-x);
}

._toggle-content._toggle-off {
  display: none;
}

.corinth-drawer-fallback-rail {
  width: var(--corinth-drawer-rail);
  min-height: 100%;
  margin: 0 auto;
}

.corinth-main-card {
  padding: 1rem 1.1rem;
  background: var(--corinth-surface);
  border: 1px solid var(--corinth-border);
  border-radius: var(--corinth-radius);
  box-shadow: var(--corinth-shadow);
  min-height: 100%;
  overflow: auto;
}

.corinth-main-card--drawer {
  margin: 0;
  min-height: 100%;
}

.corinth-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Chatbot root: column stack for message log, reference slots, and prompt row */
.corinth-chatbot > * {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.corinth-chat-entry {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--corinth-border);
}

.corinth-chat-entry:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.corinth-chat-entry:first-child {
  padding-top: 0;
}

.corinth-chat-entry__label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--corinth-muted);
}

.corinth-chat-entry__prompt {
  margin: 0;
  white-space: pre-wrap;
}

.corinth-chat-entry__response {
  margin: 0;
}

.corinth-chat-entry__response > :first-child {
  margin-top: 0;
}

.corinth-chat-ref-list {
  margin-top: 0.15rem;
}

.corinth-label {
  display: block;
  margin-bottom: 0.72rem;
  margin-top: 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--corinth-muted);
}

.corinth-divider {
  height: 1px;
  background: var(--corinth-border);
  margin: 0.25rem 0;
}

.corinth-results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.corinth-results-list li a {
  display: block;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid transparent;
  text-decoration: none;
  color: var(--corinth-accent);
}

.corinth-results-list li a:hover {
  background: var(--corinth-bg);
  border-color: var(--corinth-border);
}

.corinth-microcontent {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.78rem;
  color: var(--corinth-muted);
  line-height: 1.35;
  margin-top: 0.15rem;
  font-weight: 400;
}

.corinth-title-line {
  display: block;
  font-weight: 600;
  color: var(--corinth-text);
}

.corinth-title-line--book {
  text-transform: uppercase;
}

.corinth-hit-nav {
  display: flex;
  gap: 0.35rem;
}

.corinth-hit-btn {
  min-width: 2.5rem;
  padding: 0.25rem 0.45rem;
  font-size: 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--corinth-border);
  background: var(--corinth-surface);
}

.corinth-info-dl {
  margin: 0;
}

.corinth-info-dl dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--corinth-muted);
  margin-top: 0.65rem;
}

.corinth-info-dl dd {
  margin: 0.15rem 0 0 0;
}

.corinth-info-empty {
  font-size: 0.86rem;
  color: var(--corinth-muted);
}

.corinth-matrix {
  width: 100%;
  font-size: 0.8rem;
  margin-top: 0.35rem;
}

.corinth-matrix__row {
  display: flex;
  flex-wrap: wrap;
}

.corinth-matrix__cell {
  flex: 1 1 0;
  min-width: 4rem;
  border: 1px solid var(--corinth-border);
  padding: 0.35rem 0.45rem;
  vertical-align: top;
}

.corinth-matrix__row + .corinth-matrix__row .corinth-matrix__cell {
  border-top: none;
}

.corinth-matrix .validity-dimension {
  display: block;
  font-size: 0.68rem;
  color: var(--corinth-muted);
}

.corinth-prop-table {
  width: 100%;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.corinth-prop-table__row {
  display: grid;
  grid-template-columns: 38% 1fr;
  border: 1px solid var(--corinth-border);
}

.corinth-prop-table__row + .corinth-prop-table__row {
  border-top: none;
}

.corinth-prop-table__name {
  padding: 0.35rem 0.45rem;
  background: var(--corinth-bg);
  color: var(--corinth-muted);
  font-weight: 600;
  border-right: 1px solid var(--corinth-border);
}

.corinth-prop-table__values {
  padding: 0.35rem 0.45rem;
  vertical-align: top;
}

/* Wide: main column uses ToggleSwitch for narrow tabs only — no visible controller */
@media (min-width: 800px) {
  .corinth-field--main>._toggle-button {
    display: none !important;
  }

  .corinth-field--main>div:not(._toggle-button) {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
}

/* Narrow: one column visible; tab buttons in a horizontal strip above content */
@media (max-width: 799px) {
  .corinth-workspace__rcc-wrap>div {
    position: relative;
    padding-top: var(--corinth-tab-strip-h);
    align-items: stretch;
  }

  .corinth-workspace__rcc-wrap>div>[role="separator"] {
    display: none !important;
  }

  .corinth-workspace__rcc-wrap ._toggle-fallback {
    display: none !important;
  }

  .corinth-workspace__rcc-wrap>div>[id^="corinth-"]:not(:has(._toggle-button[aria-expanded="true"])) {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    flex: 0 0 0 !important;
    overflow: visible;
    border: none !important;
    pointer-events: none;
  }

  .corinth-workspace__rcc-wrap>div>[id^="corinth-"]:has(._toggle-button[aria-expanded="true"]) {
    flex: 1 1 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    pointer-events: auto;
  }

  /* Tab strip: absolute row; labels stay horizontal (override vertical rail drawer styles) */
  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-head,
  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="true"]) .corinth-drawer-head {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    min-height: 0;
    flex: 0 0 auto;
    gap: 0.35rem;
  }

  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-title-rail,
  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="true"]) .corinth-drawer-title-rail {
    display: contents;
  }

  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-icon,
  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="true"]) .corinth-drawer-icon {
    flex: 0 0 var(--corinth-drawer-icon-size);
    width: var(--corinth-drawer-icon-size);
    min-height: 0;
    padding: 0;
  }

  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="false"]) .corinth-drawer-label,
  .corinth-workspace__rcc-wrap .corinth-field--drawer:has(> ._toggle-button[aria-expanded="true"]) .corinth-drawer-label {
    display: block;
    width: auto;
    max-width: 100%;
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    transform: none;
    text-align: center;
    line-height: 1.2;
    font-size: 0.65rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .corinth-workspace__rcc-wrap ._toggle-button {
    position: absolute;
    top: 0;
    z-index: 3;
    height: var(--corinth-tab-strip-h);
    min-height: var(--corinth-tab-strip-h);
    padding: 0 0.35rem;
    margin: 0;
    flex: 0 0 auto !important;
    border: 1px solid var(--corinth-border);
    border-bottom: 2px solid var(--corinth-border);
    border-radius: 8px 8px 0 0;
    background: linear-gradient(180deg, #eef1f6 0%, var(--corinth-surface) 100%);
    box-sizing: border-box;
    pointer-events: auto;
  }

  .corinth-workspace__rcc-wrap ._toggle-button[aria-expanded="true"] {
    background: var(--corinth-surface);
    border-bottom-color: var(--corinth-surface);
    color: var(--corinth-text);
    font-weight: 600;
  }

  .corinth-workspace__rcc-wrap ._toggle-button[aria-expanded="false"] {
    opacity: 0.92;
  }

  /* Book / search: four tabs */
  #corinth-book-list ._toggle-button,
  #corinth-filters ._toggle-button {
    left: 0;
    width: 25%;
  }

  #corinth-book-outlet ._toggle-button,
  #corinth-results ._toggle-button {
    left: 25%;
    width: 25%;
  }

  #corinth-main ._toggle-button {
    left: 50%;
    width: 25%;
  }

  #corinth-details ._toggle-button {
    left: 75%;
    width: 25%;
  }

  /* AI: two tabs */
  #corinth-ai-main ._toggle-button {
    left: 0;
    width: 50%;
  }

  #corinth-ai-references ._toggle-button {
    left: 50%;
    width: 50%;
  }
}

@media (max-width: 900px) {
  .corinth-header {
    flex: 0 0 auto;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
    row-gap: 0.5rem;
  }

  .corinth-header__brand {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .corinth-header__search {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    justify-content: flex-start;
  }

  .corinth-header__actions {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
  }
}