/* ==========================================================================
   components/app-tabs.css — Tabs and segmented control
   --------------------------------------------------------------------------
   Two sibling controls for switching content in place. Tabs sit above the
   content they switch; the segmented control is a compact inline switch that
   fits inside a card or filter bar.

   Panel visibility is CSS-only (--active); the page owns the click handling.

   Markup contract — tabs:
     .app-tabs
       .app-tabs__list
         button.app-tabs__tab[aria-selected]   (+ --active)
       .app-tabs__panel[id]                    (+ --active)

   Markup contract — segmented control:
     .app-segment
       button.app-segment__btn                 (+ --active)
   ========================================================================== */

/* ========== TABS ========== */

.app-tabs {
    margin-bottom: var(--spacing-xl);
}

.app-tabs__list {
    display: flex;
    gap: var(--spacing-xs);
    border-bottom: 1px solid var(--color-border-default);
    overflow-x: auto;
    scrollbar-width: none;
}

.app-tabs__list::-webkit-scrollbar {
    display: none;
}

.app-tabs__tab {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-family: var(--font-family-primary);
    font-size: var(--font-body-md-size);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.app-tabs__tab .sym {
    font-size: var(--icon-size-md);
}

.app-tabs__tab:hover {
    color: var(--color-text-default);
}

.app-tabs__tab:focus-visible {
    outline: var(--focus-ring);
    outline-offset: calc(var(--focus-ring-offset) * -1);
}

.app-tabs__tab--active,
.app-tabs__tab[aria-selected="true"],
/* Briox.Generic.ModalTabs toggles .active on the legacy tab buttons */
.common_modal_tabs.app-tabs__list .modal_tab_button.active,
/* cpnl Konto ID modal: TabsMenuDisplay() toggles .dbmenuactive */
.app-tabs__tab.dbmenuactive {
    color: var(--color-nav-fg-active);
    border-bottom-color: var(--color-nav-fg-active);
}

/* forms.css paints .dbmenuactive grey and bold; the tab underline replaces both. */
.app-tabs__tab.dbmenuactive {
    background: transparent;
    font-weight: var(--font-weight-medium);
}

.app-tabs__tab:disabled {
    color: var(--color-disabled-text);
    cursor: default;
}

/* Counter chip inside a tab label */
.app-tabs__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    padding: 0 var(--spacing-xs);
    border-radius: var(--radius-full);
    background: var(--color-bg-sunken);
    font-size: var(--font-body-sm-size);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
}

/* ========== PANELS ========== */

.app-tabs__panel {
    display: none;
}

.app-tabs__panel--active {
    display: block;
}

/* ========== SEGMENTED CONTROL ========== */

.app-segment {
    --seg-h: 28px;
    --seg-px: var(--spacing-lg);
    --seg-font: var(--font-body-sm-size);
    --seg-radius-outer: var(--radius-md);
    --seg-radius-inner: var(--radius-sm);

    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--color-bg-sunken);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--seg-radius-outer);
}

/* Stretches the control and its buttons to the available width */
.app-segment--block {
    display: flex;
    width: 100%;
}

.app-segment__btn {
    height: var(--seg-h);
    padding: 0 var(--seg-px);
    background: transparent;
    border: none;
    border-radius: var(--seg-radius-inner);
    font-family: var(--font-family-primary);
    font-size: var(--seg-font);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.app-segment--block .app-segment__btn {
    flex: 1;
}

.app-segment__btn:hover:not(.app-segment__btn--active) {
    color: var(--color-text-default);
}

.app-segment__btn:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

.app-segment__btn--active,
.app-segment__btn[aria-pressed="true"] {
    background: var(--color-bg-default);
    color: var(--color-nav-fg-active);
    box-shadow: var(--shadow-sm);
}

/* ---- Radio-driven variant ----
   A segmented control that is still a form field: the choice has to submit a value and stay
   readable as `input[name=…]:checked`, which `button.app-segment__btn` above cannot do. The
   radio stays in the DOM, visually hidden but focusable, and the <label> is the visible segment. */
label.app-segment__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

label.app-segment__btn > input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

label.app-segment__btn:has(> input[type="radio"]:checked) {
    background: var(--color-bg-default);
    color: var(--color-nav-fg-active);
    box-shadow: var(--shadow-sm);
}

label.app-segment__btn:has(> input[type="radio"]:focus-visible) {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

.app-segment__btn:disabled,
label.app-segment__btn:has(> input[type="radio"]:disabled) {
    color: var(--color-disabled-text);
    cursor: default;
}

/* ---- Size variants (match button scale) ---- */

.app-segment--xs {
    --seg-h: 24px;
    --seg-px: var(--spacing-md);
    --seg-font: var(--font-caption-lg-size);
    --seg-radius-outer: var(--radius-sm);
    --seg-radius-inner: var(--radius-xs);
}

.app-segment--sm {
    --seg-h: 28px;
    --seg-px: var(--spacing-lg);
    --seg-font: var(--font-body-sm-size);
    --seg-radius-outer: var(--radius-md);
    --seg-radius-inner: var(--radius-sm);
}

/* In a form field the whole control, padding and border included, matches the 28px input beside it. */
.app-field .app-segment--sm {
    --seg-h: 20px;
}

.app-segment--md {
    --seg-h: 34px;
    --seg-px: var(--spacing-xl);
    --seg-font: var(--font-body-md-size);
    --seg-radius-outer: var(--radius-lg);
    --seg-radius-inner: var(--radius-md);
}

.app-segment--lg {
    --seg-h: 40px;
    --seg-px: var(--spacing-2xl);
    --seg-font: var(--font-body-lg-size);
    --seg-radius-outer: var(--radius-xl);
    --seg-radius-inner: var(--radius-lg);
}

/* ========== LEGACY BRIDGE: .novus_radio_toggle → app-segment visual ==========
   Maps the legacy input+label radio toggle to the app-segment look without
   changing HTML. Structure: .novus_radio_toggle > input[type=radio] + label.
   Uses --sm sizing (28px) as default — fits modal form rows.
   ============================================================================= */

.novus_radio_toggle {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--color-bg-sunken);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
}

.novus_radio_toggle input[type="radio"] {
    width: 0;
    height: 0;
    position: absolute;
    left: -9999px;
}

.novus_radio_toggle input[type="radio"] + label {
    height: 28px;
    margin: 0;
    padding: 0 var(--spacing-lg);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: none;
    box-sizing: border-box;
    color: var(--color-text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-family-primary);
    font-size: var(--font-body-sm-size);
    font-weight: var(--font-weight-medium);
    line-height: 1;
    white-space: nowrap;
    transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.novus_radio_toggle input[type="radio"] + label:first-of-type {
    border-radius: var(--radius-sm);
}

.novus_radio_toggle input[type="radio"] + label:last-of-type {
    border-radius: var(--radius-sm);
}

.novus_radio_toggle input[type="radio"]:hover + label {
    color: var(--color-text-default);
    border: none;
}

.novus_radio_toggle input[type="radio"]:checked + label {
    background: var(--color-bg-default);
    color: var(--color-nav-fg-active);
    box-shadow: var(--shadow-sm);
}

.novus_radio_toggle input[type="radio"]:focus-visible + label {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

/* Disabled / grey state */
.novus_radio_toggle input[type="radio"]:disabled + label {
    color: var(--color-disabled-text);
    cursor: default;
}

.novus_radio_toggle input[type="radio"]:disabled:checked + label {
    background: var(--color-bg-sunken);
    color: var(--color-disabled-text);
    box-shadow: none;
}

.novus_radio_toggle.grey {
    opacity: 0.6;
}

/* ========== THIRD-LEVEL MENU (breadcrumb sibling tabs) ==========
   The #third_header sibling links reuse .app-tabs__list, marking the current
   page with .is-active rather than [aria-selected], and sit between two
   horizontal scroll buttons. Emitted by common_header.htm.
   ================================================================ */

.app-tabs__tab.is-active {
    color: var(--accent);
    font-weight: var(--font-weight-semibold);
    border-bottom-color: var(--accent);
}

.app-tabs__tab.is-active:hover {
    background: transparent;
}

.app-tabs__scroll-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    flex-shrink: 0;
    background: var(--bg-primary);
    color: var(--text-tertiary);
    cursor: pointer;
    user-select: none;
    z-index: 10;
    font-size: var(--font-body-lg-size);
    transition: color var(--transition-fast), background var(--transition-fast);
    text-decoration: none;
}

.app-tabs__scroll-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.app-tabs__scroll-btn--left {
    box-shadow: 4px 0 6px -2px rgba(0, 0, 0, 0.06);
}

.app-tabs__scroll-btn--right {
    box-shadow: -4px 0 6px -2px rgba(0, 0, 0, 0.06);
}

@media (prefers-reduced-motion: reduce) {
    .app-tabs__scroll-btn {
        transition: none;
    }
}

/* The third-level menu scrolls by shifting .app-tabs__list's `left` (jQuery UI
   draggable + the scroll arrows in common_header.htm), not by native overflow,
   so it needs a clipping relative container. Scoped to #third_header: the plain
   .app-tabs component keeps its own overflow-x:auto behaviour. */

#third_header.app-tabs {
    display: flex;
    align-items: stretch;
    position: relative;
    min-height: 44px;
    border-bottom: 1px solid var(--border-secondary);
    overflow: hidden;
    z-index: 100;
}

#third_header .app-tabs__list {
    flex-flow: row nowrap;
    align-items: stretch;
    position: relative;
    left: 0;
    flex: 1;
    margin: 0 var(--spacing-md);
    border-bottom: none;
    overflow-x: visible;
}
