/* ============================================================
   KIRONA – App-Schale
   Seitenleiste, Kopfzeile, Inhaltsbereich, Fusszeile.

   Bewusst global statt als Scoped CSS: die Schale spannt ueber
   MainLayout, NavMenu und TopNav – ein Ort fuer alle drei ist
   leichter zu pflegen als drei Dateien voller ::deep-Regeln.
   Farben und Masse kommen aus den Tokens in app.css bzw. aus
   dem UI-Styler (--sidebar-width, --header-height, --header-bg …).
   ============================================================ */

:root {
    --sidebar-bg: var(--metal-surface);
    --shell-gutter: clamp(1rem, 2.2vw, 1.75rem);
    --nav-row: 2.15rem;
}

/* Sprungmarke fuer Tastatur und Screenreader */
.skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 2000;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--on-accent, #fff);
    font-weight: 600;
    transform: translateY(-200%);
}
.skip-link:focus { transform: none; color: var(--on-accent, #fff); text-decoration: none; }

/* ---- Raster -------------------------------------------------- */
.page {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--metal-black);
    min-height: 100vh;
    min-height: 100dvh;
}

main {
    flex: 1;
    /* min-width: 0 verhindert, dass breite Tabellen das Flex-Element ueber den
       Viewport hinaus aufblasen; .table-responsive scrollt dann in sich. */
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    background: var(--metal-black);
}

article.content {
    flex: 1;
    padding: var(--space-4) var(--shell-gutter) var(--space-7);
    text-align: var(--content-align, left);
    outline: none;
}
.embed-page article.content { padding: 0; }

/* ---- Seitenleiste ------------------------------------------- */
.sidebar {
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    height: var(--header-height, 56px);
    padding: 0 4.25rem 0 var(--space-4);
    flex-shrink: 0;
}
.sidebar-logo-link {
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius);
    /* Das Logo liegt auf Schwarz vor. Im dunklen Design blendet "screen" das Schwarz
       aus; im hellen Design bekommt es eine schwarze Plakette. */
    background: light-dark(#000, transparent);
    padding: 0.15rem 0.4rem;
    margin-left: -0.4rem;
}
.sidebar-logo-img {
    display: block;
    max-width: 150px;
    max-height: 40px;
    width: auto;
    height: auto;
    object-fit: contain;
    mix-blend-mode: screen;
}

/* Menue-Schalter (nur schmale Fenster): Checkbox, damit es auch ohne Skript geht. */
.navbar-toggler {
    appearance: none;
    cursor: pointer;
    position: absolute;
    top: calc((var(--header-height, 56px) - 2.4rem) / 2);
    right: var(--space-4);
    width: 2.6rem;
    height: 2.4rem;
    margin: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background-color: transparent;
    background-image: linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink));
    background-size: 1.1rem 2px;
    background-position: center calc(50% - 6px), center, center calc(50% + 6px);
    background-repeat: no-repeat;
    transition: var(--transition);
}
.navbar-toggler:hover { background-color: var(--pressed); }
.navbar-toggler:checked { background-color: var(--accent-soft); border-color: var(--accent-text); }

.nav-scrollable {
    display: none;
    flex-direction: column;
    min-height: 0;
    max-height: calc(100dvh - var(--header-height, 56px));
    border-top: 1px solid var(--line);
}
.navbar-toggler:checked ~ .nav-scrollable { display: flex; }

.sidebar-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex-wrap: nowrap;
    padding: var(--space-2) var(--space-2) var(--space-5);
}

.nav-section-header {
    padding: var(--space-4) 0.7rem 0.35rem;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--ink-muted);
}
.sidebar-nav > .nav-section-header:first-child { padding-top: var(--space-2); }

.sidebar .nav-item { padding: 1px 0; font-size: var(--font-size-md); }

.sidebar .nav-item .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-height: var(--nav-row);
    padding: 0.3rem 0.7rem;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    font-weight: 400;
    line-height: 1.3;
    text-align: left;
    transition: var(--transition);
}
.sidebar .nav-item .nav-link:hover {
    background: var(--pressed);
    color: var(--ink);
    text-decoration: none;
}
.sidebar .nav-item .nav-link.active {
    background: var(--accent-soft);
    color: var(--ink);
    font-weight: 600;
    box-shadow: inset 2px 0 0 var(--accent);
}

.sidebar .nav-link > i,
.sidebar .nav-link > .bi,
.nav-group-summary > i {
    width: 1.15rem;
    flex-shrink: 0;
    margin: 0;
    font-size: 0.95rem;
    line-height: 1;
    text-align: center;
    color: var(--ink-muted);
    transition: color var(--dur-fast) var(--ease-out);
}
.sidebar .nav-link:hover > i { color: var(--ink); }
.sidebar .nav-link.active > i { color: var(--accent-text); }

.nav-cart-badge { margin-left: auto; }

/* Ordner */
.nav-group { margin: 1px 0; }
.nav-group-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-height: var(--nav-row);
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius);
    color: var(--ink);
    font-weight: 500;
    user-select: none;
    transition: var(--transition);
}
.nav-group-summary::-webkit-details-marker { display: none; }
.nav-group-summary:hover { background: var(--pressed); }
.nav-group-label { flex: 1; min-width: 0; }
.nav-group-summary::after {
    content: "";
    width: 0.45rem;
    height: 0.45rem;
    margin-right: 0.2rem;
    border-right: 1.5px solid var(--ink-muted);
    border-bottom: 1.5px solid var(--ink-muted);
    transform: rotate(-45deg);
    transition: transform var(--dur) var(--ease-out);
    flex-shrink: 0;
}
.nav-group[open] > .nav-group-summary::after { transform: rotate(45deg); }
.nav-group-items {
    margin: 2px 0 var(--space-2) 1.25rem;
    padding-left: 0.5rem;
    border-left: 1px solid var(--line);
}
.nav-group .nav-item .nav-link { font-size: var(--font-size-sm); min-height: 1.95rem; }

/* Konto am Fuss */
.sidebar-account {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    min-width: 0;
    padding: 0.35rem 0.45rem;
    border-radius: var(--radius);
    color: var(--ink);
    transition: var(--transition);
}
.sidebar-user:hover, .sidebar-user.active { background: var(--pressed); color: var(--ink); text-decoration: none; }
.sidebar-user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--pressed);
    box-shadow: inset 0 0 0 1px var(--line-strong);
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar-user-name { font-size: var(--font-size-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-hint { font-size: var(--font-size-xs); color: var(--ink-muted); }
.sidebar-logout-form { margin: 0; flex-shrink: 0; }
.sidebar-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.2rem;
    height: 2.2rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    transition: var(--transition);
}
.sidebar-logout:hover { background: var(--pressed); color: var(--ink); border-color: var(--line-strong); }
.sidebar-auth-btn { flex: 1; }

/* ---- Kopfzeile ---------------------------------------------- */
.top-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--header-height, 56px);
    padding: 0 var(--shell-gutter);
    background: var(--header-bg, var(--metal-black));
    border-bottom: 1px solid var(--line);
    color: var(--header-text, var(--ink-muted));
}
.top-row-tools {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
    flex-shrink: 0;
}
.top-row .language-switcher { width: auto; max-width: 8.5rem; flex: 0 0 auto; }
.tenant-switcher .form-select { width: auto; max-width: 11rem; }

/* Module als Reiter: die aktuelle Position traegt die rote Linie. */
.topnav {
    display: flex;
    align-items: stretch;
    align-self: stretch;
    gap: 0.15rem;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    /* Laeuft die Leiste ueber, blendet der rechte Rand aus – so sieht man, dass es weitergeht. */
    padding-right: 2rem;
    mask-image: linear-gradient(to right, #000 calc(100% - 2.25rem), transparent);
}
.topnav::-webkit-scrollbar { display: none; }
.topnav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0 0.7rem;
    border-bottom: 2px solid transparent;
    border-top: 2px solid transparent;
    color: var(--header-text, var(--ink-muted));
    font-size: var(--font-size-md);
    font-weight: 500;
    white-space: nowrap;
    transition: var(--transition);
}
.topnav-link:hover { color: var(--ink); text-decoration: none; border-bottom-color: var(--line-strong); }
.topnav-link.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.topnav-link i { font-size: 0.9rem; line-height: 1; color: var(--ink-muted); }
.topnav-link.active i { color: var(--accent-text); }
.topnav-link:focus-visible { outline-offset: -2px; }

/* ---- Fusszeile ---------------------------------------------- */
.footer {
    padding: var(--space-3) var(--shell-gutter);
    border-top: 1px solid var(--line);
    background: var(--footer-bg, transparent);
    color: var(--footer-text, var(--ink-muted));
    font-size: var(--font-size-xs);
}
.footer a { color: inherit; text-decoration: underline; }
.footer a:hover { color: var(--ink); }

/* ---- Breite Fenster: Leiste links, Kopfzeile haftet --------- */
@media (min-width: 992px) {
    .page { flex-direction: row; }

    .sidebar {
        width: var(--sidebar-width, 260px);
        height: 100vh;
        height: 100dvh;
        flex-shrink: 0;
        border-right: 1px solid var(--line);
        border-bottom: 0;
    }
    .sidebar-brand { padding-right: var(--space-4); border-bottom: 1px solid var(--line); }
    .navbar-toggler { display: none; }
    .nav-scrollable {
        display: flex;
        flex: 1;
        max-height: none;
        border-top: 0;
    }

    .top-row {
        position: sticky;
        top: 0;
        z-index: 100;
    }
}

/* ---- Schmale Fenster ---------------------------------------- */
@media (max-width: 991.98px) {
    .top-row { flex-wrap: wrap; row-gap: 0; padding-block: 0; }
    .topnav { flex-basis: 100%; min-height: 2.75rem; }
    /* Werkzeuge in einer Zeile: zwei Suchfelder teilen sich den Platz, die Sprache steht rechts. */
    /* min-width: 0, sonst haelt die Eigenbreite der Eingabefelder die Zeile breiter als das Fenster. */
    .top-row-tools { flex: 1 1 100%; min-width: 0; margin-left: 0; padding-bottom: var(--space-2); flex-wrap: nowrap; }
    .top-row-tools:empty { display: none; }
    .top-row-tools > .ms, .top-row-tools > .gs { flex: 1 1 0; min-width: 0; }
    .top-row .language-switcher { flex: 0 0 auto; }
    .gs-hint { display: none; }
}
@media (max-width: 575.98px) {
    .topnav-label { display: none; }
    .topnav-link { padding: 0 0.85rem; }
    .topnav-link i { font-size: 1.05rem; }
}

@media print {
    .sidebar, .top-row, .footer, .skip-link { display: none !important; }
    article.content { padding: 0; }
}

/* ---- Suche in der Kopfzeile (ModuleSearch = .ms, GlobalSearch = .gs) ---- */
.ms, .gs { position: relative; max-width: 100%; }
.ms { width: 11rem; }
.gs { width: 16rem; }
.ms, .gs { transition: width var(--dur) var(--ease-out); }
.ms:focus-within { width: 15rem; }
.gs:focus-within { width: 22rem; }

.ms-box, .gs-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 2.2rem;
    padding: 0 0.65rem;
    background: var(--surface-sunk);
    border: 1px solid var(--line-strong);
    border-radius: var(--input-radius, var(--radius));
    transition: var(--transition);
}
.ms-box:hover, .gs-box:hover { border-color: var(--ink-muted); }
.ms-box:focus-within, .gs-box:focus-within {
    border-color: var(--accent-text);
    box-shadow: var(--focus-ring);
}
.ms-icon, .gs-icon { color: var(--ink-muted); font-size: 0.85rem; }
.ms-input, .gs-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--ink);
    font-size: var(--font-size-sm);
}
.ms-input::placeholder, .gs-input::placeholder { color: var(--ink-muted); opacity: 0.8; }
.ms-input::-webkit-search-cancel-button, .gs-input::-webkit-search-cancel-button { filter: grayscale(1); cursor: pointer; }
.gs-hint {
    font-size: 0.7rem;
    color: var(--ink-muted);
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    padding: 0 0.35rem;
    line-height: 1.5;
    white-space: nowrap;
}
.gs-box:focus-within .gs-hint { display: none; }

.ms-results, .gs-results {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    z-index: 1050;
    min-width: 100%;
    width: max(100%, 22rem);
    max-width: calc(100vw - 2rem);
    max-height: min(26rem, 70vh);
    overflow-y: auto;
    padding: 0.3rem;
    background: var(--surface-raised);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-float);
    animation: popover-in var(--dur-fast) var(--ease-out);
}
@keyframes popover-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.ms-empty, .gs-empty { padding: 0.75rem 0.7rem; color: var(--ink-muted); font-size: var(--font-size-sm); }
.ms-group, .gs-group {
    padding: 0.5rem 0.65rem 0.2rem;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--ink-muted);
}
.ms-item, .gs-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.42rem 0.65rem;
    border: 0;
    border-radius: calc(var(--radius) - 1px);
    background: transparent;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}
.ms-item:hover, .gs-item:hover,
.ms-item:focus-visible, .gs-item:focus-visible { background: var(--pressed); outline: none; }
.ms-item-icon, .gs-item-icon { width: 1.1rem; flex-shrink: 0; text-align: center; color: var(--ink-muted); }
.gs-item-body { min-width: 0; }
.ms-item-title, .gs-item-title { font-size: var(--font-size-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gs-item-sub { font-size: var(--font-size-xs); color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 1399.98px) { .ms { width: 9.5rem; } .gs { width: 13rem; } }
@media (max-width: 991.98px) { .ms, .gs { width: auto; } .ms-results, .gs-results { left: 0; right: auto; } }
