:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #0f766e;
    --primary-2: #115e59;
    --border: #dbe3ea;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-drawer: 0 0 30px rgba(15, 23, 42, 0.25);
    --nav-width: 260px;
    --topbar-height: 60px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    min-height: 100svh;
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 16px;
    color: var(--text);
    background: radial-gradient(circle at top right, #d6f3ee 0%, var(--bg) 45%);
    overflow-x: hidden;
}

body.is-nav-open {
    overflow: hidden;
}

/* Skip-Link */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 1000;
    background: var(--primary);
    color: #ffffff;
    padding: 10px 16px;
    border-radius: 0 0 8px 0;
    font-weight: 600;
    text-decoration: none;
}

.skip-link:focus {
    left: 0;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Off-Canvas Backdrop (nur Mobile sichtbar) */
.nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease;
}

body.is-nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
}

/* APP-SHELL: Default = Desktop-Layout (Sidebar links, Topbar oben rechts, View darunter) */
.app-shell {
    min-height: 100vh;
    min-height: 100svh;
    display: grid;
    grid-template-columns: var(--nav-width) 1fr;
    grid-template-rows: auto 1fr auto;
    transition: grid-template-columns 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

#nav-slot.is-nav-collapsed {
    --nav-width: 72px;
}

#nav-slot {
    grid-column: 1;
    grid-row: 1 / span 3;
    transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

#topbar-slot {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: 0;
    z-index: 50;
}

#view-slot {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
}

#footer-slot {
    grid-column: 2;
    grid-row: 3;
}

/* SIDEBAR */
.site-nav {
    height: 100%;
    background: #ffffff;
    border-right: 1px solid #f0f1f3;
    display: flex;
    flex-direction: column;
    transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1);
    width: 260px;
}

.site-nav.is-collapsed {
    width: 72px;
}

.site-nav__inner {
    height: 100%;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    min-height: 0;
}

.site-nav__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f1f3;
}

.site-nav__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.site-nav.is-collapsed .site-nav__brand {
    justify-content: center;
    gap: 0;
}

.site-nav__brand-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2563eb;
    flex-shrink: 0;
}

.site-nav__brand-icon svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(2px 3px 0 rgba(30, 58, 138, 0.22));
}

.site-nav__title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1a202c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 300ms ease;
}

.site-nav.is-collapsed .site-nav__title {
    display: none;
}

.site-nav__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    border-radius: 8px;
    transition: all 200ms ease;
    flex-shrink: 0;
    padding: 0;
}

.site-nav__toggle:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.site-nav__toggle:active {
    background: #e5e7eb;
}

.site-nav__toggle-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.site-nav__content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db #f3f4f6;
    -webkit-overflow-scrolling: touch;
}

.site-nav__content::-webkit-scrollbar {
    width: 6px;
}

.site-nav__content::-webkit-scrollbar-track {
    background: #f3f4f6;
}

.site-nav__content::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.site-nav__content::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.site-nav__links {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.site-nav__section-title {
    display: none;
}

.site-nav__link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #6b7280;
    border: none;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 200ms ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 44px;
    font-family: inherit;
    cursor: pointer;
}

.site-nav__link--button {
    background: transparent;
    text-align: left;
    width: 100%;
}

.site-nav.is-collapsed .site-nav__link {
    justify-content: center;
    gap: 0;
    padding: 10px;
}

.site-nav__icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.site-nav__icon svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    transition: transform 200ms ease;
}

.site-nav__label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: opacity 300ms ease;
}

.site-nav.is-collapsed .site-nav__label {
    display: none;
}

.site-nav__link:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.site-nav__link:hover .site-nav__icon svg {
    transform: scale(1.08);
}

.site-nav__link.is-active,
.site-nav__link[aria-current="page"] {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1) 0%, rgba(59, 130, 246, 0.1) 100%);
    color: #0ea5e9;
    font-weight: 600;
}

.site-nav__link.is-active::before,
.site-nav__link[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: linear-gradient(180deg, #0ea5e9 0%, #3b82f6 100%);
    border-radius: 0 3px 3px 0;
    transition: height 200ms ease;
}

.site-nav.is-collapsed .site-nav__link.is-active::before,
.site-nav.is-collapsed .site-nav__link[aria-current="page"]::before {
    display: none;
}

.site-nav__link:active {
    transform: scale(0.98);
}

.site-nav__link:focus-visible,
.site-nav__toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.site-nav__divider {
    height: 1px;
    background: #f0f1f3;
    margin: 4px 0;
    transition: opacity 300ms ease;
}

.site-nav.is-collapsed .site-nav__divider {
    opacity: 0;
}

.site-nav__profile {
    position: relative;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.site-nav__profile-button {
    appearance: none;
    width: 100%;
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid rgba(148, 163, 184, 0.26);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.92));
    color: #172033;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 220ms ease, border-color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
}

.site-nav__profile-button:hover,
.site-nav__profile.is-open .site-nav__profile-button {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(239, 246, 255, 0.92));
    border-color: rgba(96, 165, 250, 0.35);
    box-shadow: 0 10px 28px rgba(30, 64, 175, 0.12);
    transform: translateY(-1px);
}

.site-nav__profile-button:focus {
    outline: none;
}

.site-nav__profile-button:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.45);
    outline-offset: 2px;
}

.site-nav__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: linear-gradient(140deg, #eff6ff 0%, #dbeafe 100%);
    color: #1d4ed8;
    font-size: 0.86rem;
    font-weight: 800;
    border: 1px solid rgba(59, 130, 246, 0.24);
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.85);
}

.site-nav__profile-text {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.site-nav__profile-name {
    width: 100%;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.92rem;
    font-weight: 600;
    color: #1e293b;
}

.site-nav__profile-role {
    text-align: left;
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.site-nav__profile-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    color: #8b95a5;
    transition: transform 220ms ease, color 220ms ease;
}

.site-nav__profile.is-open .site-nav__profile-chevron {
    transform: rotate(180deg);
    color: #3b82f6;
}

.site-nav__profile-menu {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 10px);
    padding: 6px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 22px 36px rgba(15, 23, 42, 0.16);
    z-index: 5;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(12px) scale(0.97);
    transform-origin: bottom center;
    transition: opacity 210ms ease, transform 240ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 240ms;
}

.site-nav__profile.is-open .site-nav__profile-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition-delay: 0s;
}

.site-nav__profile-action {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #1f2937;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease;
}

.site-nav__profile-action svg {
    width: 19px;
    height: 19px;
    fill: currentColor;
}

.site-nav__profile-action:hover {
    background: #f8fafc;
    color: #0f172a;
}

.site-nav__profile-action:focus {
    outline: none;
}

.site-nav__profile-action:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: -1px;
}

.site-nav.is-collapsed .site-nav__profile {
    padding-top: 8px;
}

.site-nav.is-collapsed .site-nav__profile-button {
    justify-content: center;
    min-height: 48px;
    padding: 6px;
}

.site-nav.is-collapsed .site-nav__profile-text,
.site-nav.is-collapsed .site-nav__profile-chevron {
    display: none;
}

.site-nav.is-collapsed .site-nav__profile-menu {
    left: 0;
    right: auto;
    bottom: calc(100% + 10px);
    width: 180px;
}

/* VIEW + FOOTER */
.view-slot {
    max-width: 1240px;
    width: 100%;
    margin: 14px auto 0;
    padding: 18px;
}

.view-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.view-card h1,
.view-card h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

.view-card p,
.view-card li {
    color: var(--muted);
    line-height: 1.5;
}

.view-card ul {
    margin-left: 18px;
    display: grid;
    gap: 6px;
}

.site-footer {
    border-top: 1px solid var(--border);
    background: transparent;
}

.site-footer__inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 10px 18px calc(14px + var(--safe-bottom));
    color: var(--muted);
    font-size: 0.875rem;
}

/* LOGIN-VIEW: blendet Shell aus */
.is-login-view #nav-slot,
.is-login-view #topbar-slot,
.is-login-view #footer-slot,
.is-login-view .nav-backdrop {
    display: none;
}

.is-login-view .app-shell {
    grid-template-columns: 1fr;
}

.is-login-view #view-slot {
    grid-column: 1;
}

/* TABLET: Sidebar collapsed, Topbar voll */
@media (min-width: 769px) and (max-width: 1023px) {
    :root {
        --nav-width: 72px;
    }

    .site-nav {
        width: 72px;
    }

    .site-nav__title,
    .site-nav__label {
        display: none;
    }

    .site-nav__brand {
        justify-content: center;
        gap: 0;
    }

    .site-nav__link {
        justify-content: center;
        gap: 0;
        padding: 12px;
    }

    .site-nav__toggle {
        display: none;
    }

    .site-nav__header {
        justify-content: center;
    }

    .site-nav__brand-icon {
        width: 28px;
    }
}

/* WIDE-SCREEN */
@media (min-width: 1440px) {
    :root {
        --nav-width: 280px;
    }

    .view-slot {
        max-width: 1320px;
    }
}

/* MOBILE: Off-Canvas Drawer */
@media (max-width: 768px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    #nav-slot {
        position: fixed;
        top: calc(8px + var(--safe-top));
        left: 8px;
        bottom: calc(8px + var(--safe-bottom));
        width: min(360px, calc(100vw - 24px));
        z-index: 100;
        transform: translateX(calc(-100% - 12px));
        transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 20px;
        box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
        grid-column: unset;
        grid-row: unset;
        background: transparent;
        overflow: hidden;
    }

    body.is-nav-open #nav-slot {
        transform: translateX(0);
    }

    #nav-slot.is-nav-collapsed {
        --nav-width: 280px;
    }

    .site-nav,
    .site-nav.is-collapsed {
        position: relative;
        height: 100%;
        width: 100%;
        border-right: 0;
        border-radius: inherit;
        background:
            radial-gradient(120px 70px at 6% 96%, rgba(148, 163, 184, 0.22), transparent 62%),
            linear-gradient(170deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.94) 72%, rgba(232, 238, 248, 0.92) 100%);
        box-shadow: inset 0 0 0 1px rgba(226, 232, 240, 0.9);
    }

    .site-nav::after {
        content: "";
        position: absolute;
        left: -8%;
        right: -8%;
        bottom: -20px;
        height: 86px;
        background:
            radial-gradient(120px 46px at 34% 18%, rgba(203, 213, 225, 0.45), transparent 70%),
            radial-gradient(170px 54px at 76% 36%, rgba(226, 232, 240, 0.8), transparent 72%);
        pointer-events: none;
    }

    .site-nav__inner {
        position: relative;
        z-index: 1;
        padding: 22px 14px 16px;
        gap: 18px;
    }

    .site-nav__header {
        border-bottom: 0;
        padding: 2px 10px 10px;
    }

    .site-nav__title,
    .site-nav__label {
        display: inline;
    }

    .site-nav__brand {
        justify-content: flex-start;
        gap: 10px;
    }

    .site-nav__brand-icon,
    .site-nav__brand-icon svg {
        width: 34px;
        height: 34px;
    }

    .site-nav__title {
        font-size: 1.06rem;
        font-weight: 700;
        color: #111827;
    }

    .site-nav__toggle {
        display: none;
    }

    .site-nav__content {
        scrollbar-width: none;
    }

    .site-nav__content::-webkit-scrollbar {
        display: none;
    }

    .site-nav__links {
        gap: 8px;
        padding: 0 2px 12px;
    }

    .site-nav__section-title {
        display: block;
        margin: 14px 12px 8px;
        color: #8b95a5;
        font-size: 0.74rem;
        font-weight: 800;
        letter-spacing: 0.12em;
        text-transform: uppercase;
    }

    .site-nav__divider {
        margin: 18px 10px 12px;
        background: #e5eaf1;
    }

    .site-nav__link,
    .site-nav.is-collapsed .site-nav__link {
        justify-content: flex-start;
        gap: 18px;
        min-height: 58px;
        padding: 13px 18px;
        border-radius: 13px;
        color: #1f2937;
        font-size: 1rem;
        font-weight: 500;
        background: transparent;
    }

    .site-nav__profile {
        padding: 12px 2px 0;
        border-top-color: #e5eaf1;
    }

    .site-nav__profile-button,
    .site-nav.is-collapsed .site-nav__profile-button {
        justify-content: flex-start;
        min-height: 58px;
        padding: 9px 12px;
        border-radius: 16px;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(248, 250, 252, 0.9));
        border-color: rgba(148, 163, 184, 0.24);
        box-shadow: 0 10px 26px rgba(30, 64, 175, 0.1);
    }

    .site-nav.is-collapsed .site-nav__profile-text,
    .site-nav.is-collapsed .site-nav__profile-chevron {
        display: flex;
    }

    .site-nav.is-collapsed .site-nav__profile-menu {
        left: 2px;
        right: 2px;
        bottom: calc(100% + 10px);
        width: auto;
    }

    .site-nav__avatar {
        width: 38px;
        height: 38px;
    }

    .site-nav__profile-name {
        font-size: 0.92rem;
    }

    .site-nav__profile-action {
        min-height: 46px;
    }

    .site-nav__icon,
    .site-nav__icon svg {
        width: 26px;
        height: 26px;
    }

    .site-nav__icon svg {
        fill: currentColor;
    }

    .site-nav__link:hover {
        background: rgba(59, 130, 246, 0.08);
        color: #2563eb;
    }

    .site-nav__link.is-active,
    .site-nav__link[aria-current="page"] {
        background: linear-gradient(135deg, rgba(59, 130, 246, 0.14), rgba(96, 165, 250, 0.08));
        color: #2563eb;
        box-shadow: inset 4px 0 0 #3b82f6;
    }

    .site-nav__link.is-active::before,
    .site-nav__link[aria-current="page"]::before {
        display: none;
    }

    #topbar-slot {
        grid-column: 1;
        grid-row: 1;
        position: sticky;
        top: 0;
        z-index: 50;
    }

    #view-slot {
        grid-column: 1;
        grid-row: 2;
    }

    #footer-slot {
        grid-column: 1;
        grid-row: 3;
    }

    .view-slot {
        padding: 12px;
        margin-top: 0;
    }

    .view-card {
        padding: 16px;
        border-radius: 10px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* Cross-Browser */
input,
select,
textarea {
    font-size: 1rem;
}

input[type="search"] {
    appearance: none;
    -webkit-appearance: none;
}

input[type="search"]::-webkit-search-cancel-button {
    appearance: none;
    -webkit-appearance: none;
}
