/* ==========================================================================
   CraftX ERP — Shell chrome (sidebar + topbar + page header)
   Global utility CSS. No per-component scoped styles.
   Source: design-pkg/craftx-design-system/project/erp/index.html
   Token-only: all values reference vars defined in app.css / tokens.css.
   ========================================================================== */

/* ── Shell container ───────────────────────────────────────────────────── */

.erp-shell {
    display: grid;
    grid-template-columns: var(--cx-sidebar-w) 1fr;
    /* --cx-app-h already subtracts the maintenance banner (0px when none).
       The downward shift comes from body padding-top (see app.css); here we
       only shrink the shell to keep the total at one viewport (no scrollbar). */
    grid-template-rows: var(--cx-app-h);
    height: var(--cx-app-h);
    max-width: 100vw;
    overflow: hidden;
    background: var(--cx-content-bg);
    transition: grid-template-columns 0.25s var(--ease);
}

.erp-shell.sidebar-collapsed {
    grid-template-columns: var(--cx-sidebar-w-collapsed) 1fr;
}

.erp-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: var(--cx-content-bg);
}

.erp-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    position: relative;
}

/* Right-hand drawers (ContactSidebar, JobSidebar via DynamicSidebar) mount into .erp-main —
   the non-scrolling shell column — and sit below the app bar. Mounting into .erp-content
   would make them scroll away with the page; mounting into body would cover the app bar. */
.erp-main > .e-sidebar.e-right {
    top: var(--cx-topbar-h, 60px);
    height: calc(100% - var(--cx-topbar-h, 60px));
}

/* Full-bleed pages opt out of the default content padding by adding
   `full-bleed` to their root element. Used for calendar, kanban,
   maps and any page that should run edge-to-edge below the topbar. */
.erp-content:has(> .full-bleed),
.erp-content.full-bleed {
    padding: 0;
}

/* Padded pages opt in to gutters around their root. Default `.erp-content`
   is flush so list/management pages can render their own `.cx-page-header`
   /`.cx-toolbar-section` flush to the topbar. Dashboards, summaries and
   any page that renders bare cards directly should wrap their content in
   `.cx-page-padded` to restore the framing gutter. */
.cx-page-padded {
    padding: 28px 40px 40px;
}
@media (max-width: 768px) {
    .cx-page-padded { padding: 16px; }
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */

.erp-sidebar {
    background: linear-gradient(180deg, var(--cx-sidebar-bg) 0%, var(--cx-sidebar-bg-2) 100%);
    color: var(--cx-sidebar-text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 10;
}

.sidebar-header {
    height: var(--cx-topbar-h);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 10px;
    border-bottom: 1px solid var(--cx-sidebar-border);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    color: white;
    transition: background 0.18s var(--ease);
}

.sidebar-header:hover .sidebar-logo {
    background: var(--copper);
}

.sidebar-logo svg {
    width: 18px;
    height: 18px;
}

.sidebar-brand {
    font-family: var(--font-display);
    font-weight: var(--fw-xbold);
    font-size: 17px;
    color: white;
    letter-spacing: -0.035em;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand .x {
    color: var(--copper-light);
}

.sidebar-brand > span {
    color: var(--cx-sidebar-text-muted);
    font-weight: var(--fw-medium);
    letter-spacing: -0.02em;
}

/* ── Sidebar nav ───────────────────────────────────────────────────────── */

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}

.nav-group {
    margin-bottom: 18px;
}

.nav-group-title {
    font-size: 10px;
    font-weight: var(--fw-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--cx-sidebar-text-muted);
    padding: 0 12px 8px;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--cx-sidebar-text);
    font-size: 13.5px;
    font-weight: var(--fw-medium);
    cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    margin-bottom: 1px;
    text-decoration: none;
}

.nav-item i {
    font-size: 17px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    color: inherit;
}

.nav-item span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item:hover {
    background: var(--cx-sidebar-hover);
    color: var(--cx-sidebar-text-hover);
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: var(--copper);
    border-radius: 0 3px 3px 0;
}

.nav-item.active i {
    color: #ffffff;
}

.nav-item.parent {
    cursor: pointer;
}

.nav-item .chev {
    font-size: 11px !important;
    width: auto !important;
    opacity: 0.5;
    transition: transform 0.2s var(--ease);
}

.nav-item.expanded .chev {
    transform: rotate(90deg);
}

/* ── Sidebar submenu ──────────────────────────────────────────────────── */

.nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s var(--ease);
    padding-left: 32px;
    position: relative;
}

.nav-submenu::before {
    content: '';
    position: absolute;
    left: 22px;
    top: 6px;
    bottom: 6px;
    width: 1px;
    background: var(--cx-sidebar-border);
}

.nav-item.expanded + .nav-submenu {
    max-height: 400px;
}

.nav-submenu .nav-item {
    padding: 6px 12px;
    font-size: 13px;
    color: var(--cx-sidebar-text-muted);
    font-weight: var(--fw-regular);
}

.nav-submenu .nav-item.active {
    background: transparent;
    color: white;
    font-weight: var(--fw-medium);
}

.nav-submenu .nav-item.active::before {
    display: none;
}

/* ── Nav badge ─────────────────────────────────────────────────────────── */

.nav-badge {
    margin-left: auto;
    min-width: 20px;
    height: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: var(--cx-primary);
    color: white;
    font-size: 10.5px;
    font-weight: var(--fw-bold);
    display: grid;
    place-items: center;
    letter-spacing: 0;
}

.nav-badge.muted {
    background: rgba(255, 255, 255, 0.12);
    color: var(--cx-sidebar-text-hover);
}

/* ── Sidebar footer ───────────────────────────────────────────────────── */

.sidebar-footer {
    border-top: 1px solid var(--cx-sidebar-border);
    padding: 10px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ── Collapsed state ──────────────────────────────────────────────────── */

.erp-shell.sidebar-collapsed .sidebar-brand,
.erp-shell.sidebar-collapsed .nav-group-title,
.erp-shell.sidebar-collapsed .nav-item span,
.erp-shell.sidebar-collapsed .nav-item .chev,
.erp-shell.sidebar-collapsed .nav-badge,
.erp-shell.sidebar-collapsed .nav-submenu {
    display: none;
}

.erp-shell.sidebar-collapsed .sidebar-header {
    padding: 0;
    justify-content: center;
}

.erp-shell.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
}

.erp-shell.sidebar-collapsed .nav-item.active::before {
    left: 0;
    top: 10px;
    bottom: 10px;
}

/* ── Topbar ───────────────────────────────────────────────────────────── */

.erp-topbar {
    height: var(--cx-topbar-h);
    background: rgba(250, 247, 242, 0.82);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--cx-hairline);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    /* Must beat legacy in-page wrappers like .job-header-wrapper (1050) so
       topbar dropdowns (Schnell-erstellen, notifications, profile) render
       above page content. backdrop-filter also creates a stacking context,
       which clips absolute children to the topbar's z-index. */
    z-index: 1100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── Icon button (topbar actions) ─────────────────────────────────────── */

.icon-button {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--cx-text-secondary);
    display: grid;
    place-items: center;
    font-size: 16px;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
    position: relative;
    flex-shrink: 0;
    cursor: pointer;
    font-family: inherit;
}

.icon-button:hover {
    background: rgba(28, 25, 21, 0.05);
    color: var(--cx-text-primary);
}

.icon-button .badge-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--cx-danger);
    color: white;
    font-size: 9.5px;
    font-weight: var(--fw-bold);
    display: grid;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.85);
}

/* ── Topbar search ─────────────────────────────────────────────────────── */

.topbar-search {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 420px;
    flex: 1;
    height: 36px;
    padding: 0 14px;
    background: rgba(28, 25, 21, 0.04);
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    transition: all 0.15s var(--ease);
}

.topbar-search:focus-within {
    background: white;
    border-color: var(--cx-primary);
    box-shadow: 0 0 0 3px rgba(184, 96, 31, 0.15);
}

.topbar-search i {
    color: var(--cx-text-muted);
    font-size: 15px;
}

.topbar-search input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 13.5px;
    color: var(--cx-text-primary);
    font-family: inherit;
    min-width: 0;
}

.topbar-search input::placeholder {
    color: var(--cx-text-muted);
}

.topbar-search .kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 6px;
    background: rgba(28, 25, 21, 0.06);
    border-radius: var(--radius-sm);
    color: var(--cx-text-muted);
}

/* ── Quick-add CTA ─────────────────────────────────────────────────────── */
/* Outline variant — topbar is a global utility surface, so the quick-add
   shouldn't compete with the page-level primary CTA (.cx-header-btn).
   Copper border + text reads as branded but doesn't dominate. */

.quick-add-btn {
    height: 34px;
    padding: 0 12px 0 10px;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--copper-dark);
    border: 1px solid var(--copper);
    font-size: 13px;
    font-weight: var(--fw-semibold);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
    font-family: inherit;
    cursor: pointer;
}

.quick-add-btn:hover {
    background: var(--copper-50);
    border-color: var(--copper-dark);
    color: var(--copper-dark);
}

.quick-add-btn i {
    font-size: 15px;
}

/* ── Profile chip ──────────────────────────────────────────────────────── */

.profile-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-radius: var(--radius-pill);
    background: transparent;
    border: 1px solid var(--cx-hairline);
    transition: background 0.15s var(--ease);
    margin-left: 6px;
    position: relative;
    cursor: pointer;
    font-family: inherit;
}

.profile-chip:hover {
    background: rgba(28, 25, 21, 0.04);
}

.profile-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--cx-info);
    color: white;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: var(--fw-bold);
    flex-shrink: 0;
    overflow: hidden;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-name {
    font-size: 13px;
    font-weight: var(--fw-semibold);
    color: var(--cx-text-primary);
    white-space: nowrap;
}

.profile-status {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--cx-success);
    border: 2px solid white;
    position: absolute;
    bottom: 3px;
    left: 23px;
}

.profile-status.online { background: var(--cx-success); }
.profile-status.away { background: var(--cx-warning); }
.profile-status.do-not-disturb { background: var(--cx-danger); }
.profile-status.offline { background: var(--cx-text-muted); }

/* ── Page header (inside erp-content) ─────────────────────────────────── */

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 24px;
    flex-wrap: wrap;
}

.page-title {
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: var(--fw-bold);
    letter-spacing: -0.02em;
    color: var(--cx-text-primary);
    margin: 0 0 4px;
    line-height: 1.15;
}

.page-subtitle {
    font-size: 14px;
    color: var(--cx-text-muted);
    margin: 0;
}

.wave {
    display: inline-block;
    animation: wave 2.5s ease-in-out infinite;
    transform-origin: 70% 70%;
}

@keyframes wave {
    0%, 60%, 100% { transform: rotate(0); }
    10%, 30% { transform: rotate(14deg); }
    20% { transform: rotate(-8deg); }
    40%, 50% { transform: rotate(10deg); }
}

/* ── Loading / error states (inside erp-content or full-screen) ───────── */

.loading-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--cx-sidebar-bg);
    z-index: 2000;
    color: white;
}

.loading-container p {
    margin-top: 1rem;
    font-size: 1.1rem;
}

.content-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(250, 247, 242, 0.8);
    z-index: 1000;
}

.error-container {
    text-align: center;
    padding: 3rem 1rem;
    background-color: var(--cx-card-bg);
    border-radius: var(--cx-border-radius);
    margin: 2rem auto;
    max-width: 600px;
    box-shadow: var(--shadow-sm);
}

.error-container .error-icon {
    font-size: 2.5rem;
    color: var(--cx-danger);
    margin-bottom: 1rem;
}

.error-container h3 {
    margin-bottom: 0.75rem;
    color: var(--cx-text-primary);
    font-weight: var(--fw-semibold);
}

.error-container p {
    color: var(--cx-text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.error-container .retry-button {
    padding: 0.5rem 1rem;
    background-color: var(--cx-primary);
    color: white;
    border: none;
    border-radius: var(--cx-border-radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-family: inherit;
}

.error-container .retry-button:hover {
    background-color: var(--cx-primary-hover);
}

.error-container .retry-button i {
    font-size: 1rem;
}

/* ── Public (unauthenticated) full-bleed content ───────────────────────── */

.erp-public-content {
    min-height: var(--cx-app-h);
    width: 100%;
    background: var(--cx-content-bg);
}

/* ── Global error banner (bottom of viewport) ─────────────────────────── */

#blazor-error-ui {
    background: #7f1d1d;
    color: #fef2f2;
    padding: 1rem;
    border-radius: var(--cx-border-radius);
    box-shadow: var(--shadow-md);
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    z-index: 2000;
    display: none;
    align-items: center;
    gap: 1rem;
}

#blazor-error-ui[style*="block"] {
    display: flex !important;
}

#blazor-error-ui a {
    color: #fecaca;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    margin-left: auto;
    font-size: 1.5rem;
    line-height: 1;
}

/* ── Responsive: mobile off-canvas sidebar ────────────────────────────── */

@media (max-width: 768px) {
    .erp-shell {
        grid-template-columns: 1fr;
    }

    .erp-shell.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .erp-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--cx-sidebar-w);
        transform: translateX(-100%);
        transition: transform 0.3s var(--ease);
        z-index: 1300;
    }

    .erp-sidebar.mobile-visible {
        transform: translateX(0);
    }

    .erp-content {
        padding: 16px 20px 24px;
    }

    body.mobile-sidebar-open::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1250;
    }
}
