/* Shared AdminLTE-style application frame; all modules use these components. */
.app-shell {
    --sidebar-width: 256px;
    --rail-width: 80px;
    --header-height: 76px;
    min-height: 100vh;
    min-height: 100dvh;
    font-size: 14px;
    line-height: 1.55
}

.ui-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    vertical-align: middle
}

.app-shell .shell {
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    min-height: 100dvh;
    transition: margin-left .2s ease;
    min-width: 0
}

.app-shell .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    padding: 0;
    background: var(--paper);
    border-right: 1px solid var(--line);
    z-index: 2100;
    transform: none;
    transition: width .2s ease, transform .2s ease;
    overflow: hidden
}

.app-shell .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 25px 22px;
    text-decoration: none;
    min-height: 108px;
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    border-radius: 0;
    flex-shrink: 0
}

.brand-monogram {
    display: grid;
    place-items: center;
    position: relative;
    flex-shrink: 0;
    width: 38px;
    height: 44px;
    border-radius: 12px;
    background: var(--soft);
    color: var(--brand);
    font-size: 27px;
    font-weight: 800;
    letter-spacing: -2px
}

.brand-monogram>span {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    right: 4px;
    bottom: 7px;
    background: var(--brand)
}

.app-shell .brand-copy b {
    font-size: 26px;
    letter-spacing: -1px;
    line-height: 1.1;
    margin: 0
}

.app-shell .brand-copy small {
    font-size: 10px;
    letter-spacing: .2em;
    color: var(--brand);
    margin: 7px 0 0
}

.app-shell .sidebar-nav {
    padding: 18px 14px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent
}

.nav-group {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: .08em;
    font-weight: 650;
    margin: 17px 12px 9px;
    white-space: nowrap
}

.nav-group:first-child {
    margin-top: 2px
}

.app-shell .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 13px;
    color: var(--muted);
    min-height: 48px;
    padding: 12px 14px;
    margin: 4px 0;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 550;
    transition: background .15s, color .15s;
    white-space: nowrap
}

.app-shell .nav-link:hover {
    background: var(--soft);
    color: var(--brand)
}

.app-shell .nav-link.active {
    background: var(--soft);
    color: var(--brand);
    font-weight: 700
}

.nav-active-dot {
    width: 6px;
    height: 6px;
    background: var(--brand);
    border-radius: 50%;
    margin-left: auto
}

.nav-soon {
    font-size: 9px;
    padding: 3px 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-left: auto;
    font-weight: 400
}

.app-shell .nav-disabled {
    opacity: .58;
    cursor: default
}

.app-shell .nav-disabled:hover {
    background: transparent;
    color: var(--muted)
}

.sidebar-caption {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 19px 24px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 11px;
    flex-shrink: 0
}

.workspace-dot {
    width: 7px;
    height: 7px;
    flex-shrink: 0;
    background: var(--brand);
    border-radius: 50%
}

.app-shell .sidebar-caption small {
    margin: 2px 0 0;
    letter-spacing: 0;
    font-size: 10px;
    color: var(--muted)
}

.app-shell .app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
    height: auto;
    min-height: var(--header-height);
    padding: 14px clamp(16px, 3vw, 36px);
    background: var(--paper);
    border-bottom: 1px solid var(--line)
}

.header-start {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0
}

.header-heading {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-weight: 600
}

.header-kicker {
    color: var(--muted);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .12em
}

.app-shell .icon-button {
    display: grid;
    place-items: center;
    padding: 10px;
    min-width: 44px;
    min-height: 44px
}

.app-shell .menu-toggle {
    display: grid
}

.app-shell .header-tools {
    gap: 16px;
    flex-shrink: 0
}

.app-shell .theme-picker {
    display: flex;
    align-items: center;
    flex-direction: row;
    gap: 7px;
    margin: 0;
    color: var(--muted)
}

.app-shell .theme-picker select {
    min-height: 40px;
    font-size: 12px;
    padding: 8px 9px;
    max-width: 112px
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0
}

.user-avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--soft);
    color: var(--brand);
    font-size: 14px;
    font-weight: 700
}

.app-shell .user-name {
    display: block;
    max-width: 150px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

.user-name small {
    display: block;
    color: var(--muted);
    font-size: 10px;
    font-weight: 400
}

.app-shell .logout-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-size: 12px;
    padding: 10px 12px;
    min-height: 44px
}

.app-shell main {
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 1480px;
    margin: 0 auto;
    padding: clamp(24px, 3vw, 40px);
    outline: none
}

.app-shell .crumb {
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px
}

.app-shell .app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    flex-shrink: 0;
    border-top: 1px solid var(--line);
    background: var(--paper);
    padding: 17px clamp(16px, 3vw, 36px);
    font-size: 11px;
    color: var(--muted);
    line-height: 1.7
}

.footer-copyright,
.footer-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px
}

.app-footer a {
    font-weight: 650;
    text-decoration: none
}

.footer-rights {
    margin-left: 5px
}

.footer-meta {
    gap: 10px
}

.footer-version b {
    font-weight: 600;
    color: var(--ink)
}

.sidebar-backdrop {
    display: none
}

.sidebar-backdrop[hidden] {
    display: none !important
}

.app-shell .sidebar-close {
    display: none
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0
}

html.drawer-open {
    overflow: hidden
}

.app-shell .sidebar-nav {
    overscroll-behavior: contain
}

.skip-link {
    position: fixed;
    left: 16px;
    top: -100px;
    padding: 12px 18px;
    background: var(--paper);
    border: 2px solid var(--brand);
    border-radius: 8px;
    z-index: 5000
}

.skip-link:focus {
    top: 12px
}

.app-shell a:focus-visible,
.app-shell button:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 3px
}

.app-shell.sidebar-collapsed .app-sidebar {
    width: var(--rail-width)
}

.app-shell.sidebar-collapsed .shell {
    margin-left: var(--rail-width)
}

.app-shell.sidebar-collapsed .sidebar-brand {
    padding: 25px 20px
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .nav-active-dot,
.app-shell.sidebar-collapsed .nav-soon {
    display: none
}

.app-shell.sidebar-collapsed .nav-group {
    font-size: 0;
    height: 10px;
    margin: 10px 10px 6px;
    border-bottom: 1px solid var(--line)
}

.app-shell.sidebar-collapsed .nav-link {
    justify-content: center;
    padding: 12px;
    gap: 0
}

.app-shell.sidebar-collapsed .sidebar-caption {
    justify-content: center;
    padding: 23px
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin: 24px 0
}

.dashboard-stats article {
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 22px;
    min-width: 0
}

.dashboard-stats em {
    font-size: 11px;
    display: block
}

.app-shell .heading {
    min-width: 0
}

.app-shell .heading>div {
    min-width: 0
}

.app-shell .heading h1 {
    overflow-wrap: anywhere
}

.app-shell .heading p {
    color: var(--muted);
    line-height: 1.7
}

.app-shell .panel {
    min-width: 0
}

.app-shell .table-scroll {
    max-width: 100%;
    overscroll-behavior-x: contain
}

/* Tablet widths use a drawer too, giving forms/tables the entire content width. */
@media(max-width:1100px) {
    .app-shell .header-user {
        display: none
    }

    .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr))
    }
}

@media(max-width:1023px) {

    .app-shell .shell,
    .app-shell.sidebar-collapsed .shell {
        margin-left: 0
    }

    .app-shell .app-sidebar,
    .app-shell.sidebar-collapsed .app-sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        visibility: hidden
    }

    .app-shell .app-sidebar.open {
        transform: translateX(0);
        visibility: visible;
        box-shadow: 10px 0 50px #10172230
    }

    .app-shell.sidebar-collapsed .brand-copy,
    .app-shell.sidebar-collapsed .nav-label {
        display: block
    }

    .app-shell.sidebar-collapsed .nav-active-dot,
    .app-shell.sidebar-collapsed .nav-soon {
        display: block
    }

    .app-shell.sidebar-collapsed .nav-group {
        font-size: 10px;
        height: auto;
        border: 0;
        margin: 17px 12px 9px
    }

    .app-shell.sidebar-collapsed .sidebar-brand {
        padding: 25px 22px
    }

    .app-shell.sidebar-collapsed .nav-link {
        justify-content: flex-start;
        gap: 13px;
        padding: 12px 14px
    }

    .app-shell.sidebar-collapsed .sidebar-caption {
        justify-content: flex-start;
        padding: 19px 24px
    }

    .app-shell .sidebar-close {
        display: grid;
        place-items: center;
        position: absolute;
        right: 10px;
        top: 10px;
        padding: 5px;
        width: 30px;
        min-height: 30px;
        background: transparent;
        color: var(--muted)
    }

    .app-shell .sidebar-backdrop:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        border: 0;
        border-radius: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        min-height: 0;
        background: #10172266;
        backdrop-filter: blur(3px);
        z-index: 2050
    }

    .app-shell.sidebar-open {
        overflow: hidden
    }

    .app-shell .profile-grid {
        grid-template-columns: 1fr
    }
}

@media(max-width:600px) {
    .app-shell .app-header {
        padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
        gap: 8px;
        min-height: 68px;
        flex-wrap: nowrap
    }

    .header-heading {
        display: none
    }

    .app-shell .header-tools {
        gap: 8px
    }

    .app-shell .theme-picker>.ui-icon {
        display: none
    }

    .app-shell .theme-picker select {
        max-width: 108px;
        min-height: 44px
    }

    .app-shell main {
        padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left))
    }

    .app-shell .app-footer {
        padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
        gap: 8px
    }

    .footer-rights {
        margin-left: 0
    }

    .footer-meta {
        width: 100%
    }

    .app-shell .heading {
        flex-wrap: wrap;
        gap: 14px
    }

    .app-shell .heading h1 {
        font-size: 1.5rem
    }

    .app-shell .heading p {
        font-size: 12px
    }

    .app-shell .form-grid {
        grid-template-columns: 1fr
    }

    .app-shell .filters label {
        min-width: min(140px, 100%)
    }

    .app-shell .filters {
        gap: 14px
    }

    .app-shell .filters button {
        min-height: 44px
    }

    .app-shell .panel {
        padding: 18px
    }

    .app-shell .table-panel {
        padding: 16px
    }

    .app-shell .form-actions,
    .app-shell .pagination {
        flex-wrap: wrap
    }

    .dashboard-stats article {
        padding: 16px
    }

    .dashboard-stats {
        gap: 12px
    }

    .dashboard-stats article small {
        font-size: 11px
    }

    .app-shell .app-sidebar,
    .app-shell.sidebar-collapsed .app-sidebar {
        width: min(var(--sidebar-width), calc(100vw - 48px))
    }
}

@media(max-width:360px) {
    .app-shell .theme-picker select {
        max-width: 93px
    }

    .app-shell .logout-button {
        padding: 10px
    }

    .app-shell .logout-button span {
        font-size: 11px
    }

    .app-shell .app-header {
        gap: 5px
    }

    .app-shell .header-tools {
        gap: 6px
    }
}

@media(max-height:500px) {
    .app-shell .sidebar-brand {
        min-height: 80px;
        padding-top: 16px;
        padding-bottom: 16px
    }

    .app-shell .sidebar-caption {
        padding-top: 10px;
        padding-bottom: 10px
    }

    .app-shell .sidebar-nav {
        padding-top: 8px;
        padding-bottom: 8px
    }
}

@media(prefers-reduced-motion:reduce) {

    .app-shell .shell,
    .app-shell .app-sidebar,
    .app-shell .nav-link {
        transition: none
    }
}

/* Public login/installer use the same tokens and footer, without protected navigation. */
.public-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh
}

.public-shell .public-main {
    display: grid;
    place-items: center;
    flex: 1;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 40px 20px
}

.public-shell .auth-card {
    width: min(440px, 100%);
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--line);
    padding: clamp(24px, 5vw, 40px)
}

.public-shell .auth-card h1 {
    font-size: 1.8rem
}

.public-shell .auth-card input {
    min-width: 0;
    width: 100%;
    min-height: 44px
}

.public-shell .auth-card button {
    width: 100%;
    min-height: 44px
}

.public-shell .public-brand {
    font-size: 12px;
    letter-spacing: .12em;
    color: var(--brand);
    font-weight: 700;
    margin: 0 0 24px
}

.public-shell .public-theme {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 24px
}

.public-shell .public-theme select {
    width: auto;
    font-size: 12px;
    max-width: 112px
}

.public-shell .public-theme .public-brand {
    margin: 0
}

@media print {

    .app-shell .app-sidebar,
    .app-shell .app-header,
    .skip-link,
    .sidebar-backdrop {
        display: none !important
    }

    .app-shell .shell,
    .app-shell.sidebar-collapsed .shell {
        margin-left: 0
    }

    .app-shell .app-footer {
        position: static
    }

    .app-shell main {
        padding: 0;
        max-width: none
    }
}

/* Safe areas and touch controls follow base rules so they survive the cascade. */
@media (max-width:1023px) {
    .app-shell .sidebar-brand {
        padding-top: max(25px, env(safe-area-inset-top));
        padding-left: max(22px, env(safe-area-inset-left));
    }
    .app-shell .sidebar-nav { padding-left: max(14px, env(safe-area-inset-left)); }
    .app-shell .sidebar-caption { padding-bottom: max(19px, env(safe-area-inset-bottom)); }
    .app-shell .sidebar-close {
        top: max(10px, env(safe-area-inset-top));
        width: 44px;
        min-height: 44px;
    }
}
@media (max-width:600px) {
    .app-shell .app-header { padding-top: max(12px, env(safe-area-inset-top)); }
    .app-shell input, .app-shell select, .app-shell textarea,
    .app-shell .theme-picker select, .public-shell .public-theme select { font-size: 16px; }
}
