/* App shell: sidebar + topbar + content area. */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
    transition: grid-template-columns var(--duration) var(--ease);
}

/* Not a grid child visually — hidden by default so it doesn't consume the 2nd grid row on desktop. */
.sidebar-scrim { display: none; }
.app-shell.collapsed { grid-template-columns: var(--sidebar-width-collapsed) 1fr; }

/* grid-column is pinned explicitly rather than left to auto-placement: below 960px .sidebar switches
   to position:fixed (see the responsive block below), and a fixed-position element is removed from
   grid-item auto-placement entirely per spec — without this, .shell-main becomes the *first* in-flow
   grid item once that happens and gets placed in column 1 (0 width at that breakpoint) instead of
   column 2, collapsing the topbar/content area to almost nothing on every mobile screen. */
.shell-main { display: flex; flex-direction: column; min-width: 0; grid-column: 2; }

/* --- Sidebar --- */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-brand img { height: 38px; width: auto; flex-shrink: 0; }
.sidebar-brand .brand-text { font-weight: 700; font-size: var(--text-md); color: var(--accent); white-space: nowrap; overflow: hidden; }
/* Collapsed rail (72px) is too narrow for the wordmark — swap to the square circular badge instead
   of letting the wordmark get clipped by .sidebar's overflow:hidden. */
.brand-logo-collapsed { display: none; }
.app-shell.collapsed .sidebar-brand { justify-content: center; padding-left: var(--space-3); padding-right: var(--space-3); }
.app-shell.collapsed .brand-logo-full { display: none; }
.app-shell.collapsed .brand-logo-collapsed { display: block; height: 34px; }
.app-shell.collapsed .sidebar-brand .brand-text { display: none; }

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--space-3) var(--space-3) var(--space-4);
}

.nav-group { margin-bottom: var(--space-2); }
.nav-group-label {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    font: inherit;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--space-4) var(--space-3) var(--space-1);
    white-space: nowrap;
    transition: color var(--duration-fast) var(--ease);
}
.nav-group-label:hover { color: var(--text-secondary); }
.nav-group-chevron { flex-shrink: 0; }
.app-shell.collapsed .nav-group-label { display: none; }

.nav-item-wrap { position: relative; }

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 9px 30px 9px var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--text-base);
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    margin-bottom: 1px;
    transition: background-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item svg { flex-shrink: 0; width: 18px; height: 18px; }
.nav-item .nav-item-label { overflow: hidden; text-overflow: ellipsis; }
.app-shell.collapsed .nav-item .nav-item-label { display: none; }
.app-shell.collapsed .nav-item { justify-content: center; padding-right: var(--space-3); }

/* Star-on-hover favorite toggle — sits over the nav item as a sibling (not nested inside the <a>,
   which would be invalid HTML), positioned via the shared .nav-item-wrap relative container. */
.nav-item-star {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    padding: 0;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease), background-color var(--duration-fast) var(--ease);
}
.nav-item-wrap:hover .nav-item-star,
.nav-item-star.active,
.nav-item-star:focus-visible {
    opacity: 1;
}
.nav-item-star:hover { color: var(--warning); background: var(--bg-hover); }
.nav-item-star svg { fill: none; }
.nav-item-star.active svg { fill: var(--warning); stroke: var(--warning); }
.app-shell.collapsed .nav-item-star { display: none; }

.nav-item.active {
    background: var(--accent-soft-bg);
    color: var(--accent-soft-text);
}
.nav-item.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    border-radius: var(--radius-full);
    background: var(--accent);
}
.app-shell.collapsed .nav-item.active::before { display: none; }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: var(--space-3);
    flex-shrink: 0;
}
.sidebar-collapse-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
}
.sidebar-collapse-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-collapse-btn svg { transition: transform var(--duration) var(--ease); }
.app-shell.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

/* --- Topbar --- */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-canvas);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 0 var(--space-6);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-title { font-size: var(--text-lg); font-weight: 650; }
.topbar-subtitle { font-size: var(--text-sm); color: var(--text-secondary); margin-top: 1px; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.active { background: var(--accent-soft-bg); color: var(--accent-soft-text); }

.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-3);
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    white-space: nowrap;
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.sync-dot.online { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft-bg); }
.sync-dot.offline { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft-bg); }

.store-switcher {
    padding: 6px var(--space-3);
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    max-width: 160px;
}

.user-menu { position: relative; }
.user-menu-trigger {
    display: flex; align-items: center; gap: var(--space-2);
    padding: 4px var(--space-2) 4px 4px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    cursor: pointer;
    color: var(--text-primary);
}
.user-menu-trigger:hover { border-color: var(--border-strong); }
.user-menu-name { font-size: var(--text-sm); font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    padding: var(--space-2);
    z-index: 50;
}
.user-menu-header { padding: var(--space-2) var(--space-3) var(--space-3); border-bottom: 1px solid var(--border); margin-bottom: var(--space-2); }
.user-menu-header .name { font-weight: 650; font-size: var(--text-sm); }
.user-menu-header .email { font-size: var(--text-xs); color: var(--text-muted); }
.user-menu-item {
    display: flex; align-items: center; gap: var(--space-2);
    width: 100%; padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm); background: none; border: none;
    color: var(--text-secondary); font-size: var(--text-sm); text-align: left; cursor: pointer;
}
.user-menu-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.user-menu-item.danger:hover { background: var(--danger-soft-bg); color: var(--danger-soft-text); }

.notif-trigger { position: relative; }
.notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bg-surface);
}
.notif-dropdown { width: 320px; max-width: calc(100vw - var(--space-6)); max-height: 380px; overflow-y: auto; padding: var(--space-2) 0; }
.notif-dropdown .user-menu-header { padding: var(--space-1) var(--space-3) var(--space-3); }
.notif-empty { padding: var(--space-5) var(--space-3); text-align: center; color: var(--text-muted); font-size: var(--text-sm); }
.notif-item { align-items: flex-start; gap: var(--space-3); white-space: normal; line-height: 1.4; }
.notif-item svg { flex-shrink: 0; margin-top: 2px; color: var(--accent); }
.notif-time { display: block; font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

/* --- Content --- */
.content {
    padding: var(--space-6) var(--space-8) var(--space-12);
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
}
.page-header h1 { font-size: var(--text-2xl); }
.page-header .page-description { color: var(--text-secondary); margin-top: var(--space-1); font-size: var(--text-base); }
/* flex-shrink is deliberately NOT 0 here: this block also has flex-wrap:wrap for its own children
   (date inputs, export/print buttons, etc.), but a wrapping flex container that refuses to shrink
   still reports its *unwrapped* intrinsic width (as if every child sat on one line) to its own
   parent — so on a narrow screen it would overflow .page-header's line by exactly that unwrapped
   width instead of actually wrapping within it. Letting it shrink is what allows the wrap to work. */
.page-header-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; max-width: 100%; }

/* Date-range filter inputs are the most common Actions content (every report page) — the shared
   text-like-input rule (components.css) gives every text-like <input> width:100% as its flex-basis,
   which fights for space against its neighbors instead of sizing to content, and is the main reason
   this row needed to wrap at all on anything narrower than a tablet. !important is needed because
   that shared rule's long :not() chain out-specifies a plain attribute selector here. */
.page-header-actions input[type="date"] { width: auto !important; flex-shrink: 0; }

/* --- Login / auth shell --- */
.login-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    background:
        radial-gradient(900px 520px at 12% -8%, var(--accent-soft-bg), transparent 62%),
        radial-gradient(760px 480px at 108% 112%, var(--lime-soft-bg), transparent 60%),
        var(--bg-canvas);
    position: relative;
    overflow: hidden;
}
/* soft brand aura behind the card — subtle, does the atmospheric work the flat canvas can't */
.login-shell::before {
    content: "";
    position: absolute;
    width: 460px; height: 460px;
    top: 50%; left: 50%;
    transform: translate(-50%, -60%);
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--lime) 20%, transparent), transparent 68%);
    filter: blur(48px);
    pointer-events: none;
    z-index: 0;
}

/* controls cluster (theme + optional language) — top-right of the shell */
.login-controls {
    position: absolute;
    top: var(--space-5); right: var(--space-5);
    display: flex; align-items: center; gap: var(--space-2);
    z-index: 2;
}
.login-theme-toggle { position: absolute; top: var(--space-5); right: var(--space-5); z-index: 2; }

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--space-10) var(--space-8) var(--space-6);
    width: 100%;
    max-width: 408px;
    position: relative;
    z-index: 1;
    overflow: hidden;
}
/* brand accent stripe — mirrors the FreshCircle transactional-email header */
.login-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--lime), var(--accent));
}

.login-logo { display: block; height: 80px; width: auto; margin: 0 auto var(--space-5); }

/* circular badge hero — the customer login leads with the app-mark, not the wordmark */
.login-badge {
    display: block;
    width: 88px; height: 88px;
    margin: 0 auto var(--space-5);
    border-radius: 50%;
    box-shadow:
        0 12px 30px -12px color-mix(in srgb, var(--accent) 60%, transparent),
        0 0 0 7px color-mix(in srgb, var(--lime) 13%, transparent);
}

.login-title {
    text-align: center;
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: -0.015em;
    line-height: 1.2;
    margin: 0 0 var(--space-2);
    color: var(--text-primary);
    text-wrap: balance;
}

.login-subtitle {
    text-align: center; color: var(--text-secondary); margin: 0 0 var(--space-6);
    font-size: var(--text-base); line-height: 1.5;
    max-width: 32ch; margin-left: auto; margin-right: auto;
}
/* uppercase eyebrow variant (opt-in) for utilitarian contexts like first-time setup */
.login-subtitle.eyebrow {
    font-size: var(--text-sm); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
}

.login-footnote { text-align: center; color: var(--text-muted); font-size: var(--text-xs); margin-top: var(--space-6); }

/* secondary auth links (forgot password / switch to register) */
.login-alt { text-align: center; color: var(--text-secondary); font-size: var(--text-sm); margin: var(--space-4) 0 0; }
.login-alt a { font-weight: 600; }

/* legal links row — customer auth screens (Impressum/Datenschutz) live off the FreshCircle shell footer */
.login-legal {
    display: flex; justify-content: center; gap: var(--space-4);
    margin-top: var(--space-5); padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    font-size: var(--text-xs);
}
.login-legal a { color: var(--text-secondary); text-decoration: none; }
.login-legal a:hover { color: var(--text-primary); text-decoration: underline; }

/* icon-leading fields + show-password toggle — wraps just the control, inside a .field */
.auth-field { position: relative; }
.auth-field-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); display: flex; pointer-events: none;
}
/* !important needed: components.css's base input rule chains 10 :not() clauses onto the `input`
   selector, which out-specifies a plain descendant selector — without it the icon overlaps the text. */
.auth-field input { padding-left: 38px !important; }
.auth-field input.auth-pw { padding-right: 42px !important; }
.auth-pw-toggle {
    position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm);
    transition: color var(--duration-fast) var(--ease), background-color var(--duration-fast) var(--ease);
}
.auth-pw-toggle:hover { color: var(--text-secondary); background: var(--bg-hover); }

/* elevated primary call-to-action — gradient + hover lift, opt-in via .auth-cta */
.btn.primary.auth-cta {
    background: linear-gradient(135deg, var(--accent), var(--accent-active));
    box-shadow: 0 10px 22px -10px color-mix(in srgb, var(--accent) 65%, transparent);
    transition: transform var(--duration-fast) var(--ease), box-shadow var(--duration) var(--ease), filter var(--duration) var(--ease);
}
.btn.primary.auth-cta:hover:not(:disabled) {
    filter: brightness(1.04);
    transform: translateY(-1px);
    box-shadow: 0 15px 28px -10px color-mix(in srgb, var(--accent) 72%, transparent);
}
.btn.primary.auth-cta:active:not(:disabled) { transform: translateY(0); }

@media (max-width: 480px) {
    .login-card { padding: var(--space-8) var(--space-5) var(--space-5); border-radius: var(--radius-lg); }
    .login-badge { width: 76px; height: 76px; }
}

@media (prefers-reduced-motion: reduce) {
    .btn.primary.auth-cta { transition: none; }
    .btn.primary.auth-cta:hover:not(:disabled) { transform: none; }
}

.mobile-menu-btn { display: none; }

/* --- Floating "back to top" --- */
.scroll-top-btn {
    position: fixed;
    right: var(--space-6);
    bottom: var(--space-6);
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: none;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), background var(--duration) var(--ease);
    z-index: 90;
}
.scroll-top-btn.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.scroll-top-btn:hover { background: var(--accent-hover); }
@media (max-width: 480px) { .scroll-top-btn { right: var(--space-4); bottom: var(--space-4); } }

/* --- Responsive --- */
@media (max-width: 960px) {
    .mobile-menu-btn { display: inline-flex; }
    .app-shell { grid-template-columns: 0 1fr; }
    .app-shell .sidebar { position: fixed; left: 0; top: 0; width: var(--sidebar-width); z-index: 100; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .app-shell.mobile-open .sidebar { transform: translateX(0); }
    .content { padding: var(--space-4); }
    .sidebar-scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; }
    .app-shell.mobile-open .sidebar-scrim { display: block; }

    /* Topbar: at this width the sidebar is already a drawer (reachable via mobile-menu-btn), so the
       "Quick jump" search and the sync-status pill are non-essential extras — drop them here rather
       than let a flex row with 6+ children silently overflow/clip on anything narrower than a tablet.
       Scoped to .topbar specifically — .search-input is also reused by page-level DataTable toolbar
       filters (e.g. Roles & Permissions' "Search roles…"), which must stay visible at this width. */
    .topbar { padding: 0 var(--space-4); gap: var(--space-2); }
    .topbar .search-input { display: none; }
    .sync-pill { display: none; }
    .store-switcher { max-width: 110px; }
}

/* Phones specifically: the store switcher and user menu still have their full desktop width/label at
   960px (a tablet in portrait has room for them) — shed the remaining non-essential chrome only once
   there's genuinely no room left for it. */
@media (max-width: 480px) {
    .store-switcher { max-width: 72px; }
    .user-menu-name { display: none; }
    .user-menu-trigger { padding: 4px; gap: 0; border: none; background: transparent; }
}

/* --- Print: app chrome never belongs on a printed page (e.g. supplier claim reports) --- */
@media print {
    .sidebar, .topbar, .sidebar-scrim, .no-print { display: none !important; }
    .app-shell { display: block !important; }
    .content { padding: 0 !important; }
}
