/*
 * shell.css — App-shell styles matching the v2 design handoff
 * (docs/design/handoff/v2/project/).  No MudBlazor layout wrappers;
 * the shell is a plain CSS grid: 248px sidebar | 1fr main.
 */

/* ========== App shell grid ======================================= */

.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
    background: var(--bg);
}

/* ========== Sidebar ============================================== */

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 10;
}

/* Brand */
.brand {
    padding: 18px 18px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}
.brand-mark {
    width: 28px; height: 28px;
    border-radius: 7px;
    background: var(--syndic-blue-ink);
    position: relative;
    flex-shrink: 0;
    display: grid; place-items: center;
}
.brand-mark::before, .brand-mark::after {
    content: "";
    position: absolute;
    background: var(--syndic-teal);
}
.brand-mark::before { width: 3px; height: 14px; left: 7px; top: 7px; }
.brand-mark::after { width: 3px; height: 10px; left: 13px; top: 11px; box-shadow: 6px 4px 0 var(--syndic-teal); }
.brand-name {
    font-family: var(--f-serif);
    font-size: 22px;
    letter-spacing: -0.01em;
    color: var(--ink);
    line-height: 1.1;
}
.brand-suffix {
    font-size: 9px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin-top: 1px;
    font-weight: 600;
}

/* Building selector */
.shell-building-selector {
    padding: 10px 12px 6px;
    flex-shrink: 0;
}
.shell-building-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font-size: 12.5px;
    color: var(--ink);
    cursor: pointer;
    font-family: inherit;
}
.shell-building-btn:disabled {
    opacity: 0.7;
    cursor: default;
}

/* Navigation sections — matching .nav-section from design handoff */
.nav-section {
    padding: 14px 12px 4px;
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-4);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}
.nav-section .nav-section-ar {
    font-family: var(--f-ar);
    text-transform: none;
    letter-spacing: 0;
    font-size: 11px;
    opacity: 0.7;
}

/* Navigation list — matching .nav from design handoff */
.nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 8px;
}
/* NavLink renders as <a>, we style it like design's .nav-item button */
.nav .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--r-sm);
    color: var(--ink-2);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    text-align: left;
    width: 100%;
    position: relative;
    text-decoration: none;
    font-family: inherit;
    line-height: 1.4;
    min-height: 34px;
}
.nav .nav-item:hover { background: var(--bg-2); color: var(--ink); }
.nav .nav-item.active {
    background: var(--syndic-blue-ink);
    color: white;
}
[data-theme="dark"] .nav .nav-item.active { background: var(--syndic-blue); }
.nav .nav-item .ico {
    width: 16px; height: 16px;
    display: grid; place-items: center;
    flex-shrink: 0;
}
.nav .nav-item .badge {
    margin-left: auto;
    background: var(--tint-warn);
    color: var(--warn);
    font-size: 10.5px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}
.nav .nav-item.active .badge { background: rgba(255,255,255,0.18); color: white; }

/* Scrollable nav region.

   .sidebar is a 100vh flex column: brand, building selector, nav, foot. NavMenu
   renders its sections as several sibling divs, and with no scroll container
   between them and .sidebar their combined height simply exceeded the column on
   a full manager menu. .sidebar-foot's `margin-top: auto` only positions when
   there is free space, so under overflow the nav boxes shrank, their content
   spilled, and the foot — a later sibling in the same stacking context — painted
   over the last nav item (settings-cmi for a SyndicManager), swallowing its
   clicks.

   min-height: 0 is the load-bearing half. A flex child's default
   `min-height: auto` resolves to its content height, so without this the
   container cannot shrink and overflow-y never engages. */
.nav-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Sidebar foot / user card */
.sidebar-foot {
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}
.user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 8px;
    border-radius: var(--r-sm);
    cursor: pointer;
}
.user-card:hover { background: var(--bg-2); }
.avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--syndic-blue), var(--syndic-teal));
    color: white;
    display: grid; place-items: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.user-role { font-size: 11px; color: var(--ink-3); }

/* ========== Main content area ==================================== */

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

/* ========== Topbar =============================================== */

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(8px);
    flex-shrink: 0;
}
.hamburger {
    display: none;
    width: 30px; height: 30px;
    border: none;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    border-radius: var(--r-sm);
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.hamburger:hover { background: var(--bg-2); color: var(--ink); }

.crumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ink-3);
}
.crumbs .sep { opacity: 0.4; }
.crumbs .cur { color: var(--ink); font-weight: 500; }
.crumbs a.cur {
    color: var(--syndic-blue);
    text-decoration: none;
}
.crumbs a.cur:hover {
    text-decoration: underline;
}

/* Search bar */
.search {
    margin-left: auto;
    flex: 0 1 320px;
    position: relative;
}
.search input {
    width: 100%;
    padding: 7px 10px 7px 32px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font-size: 13px;
    color: var(--ink);
    outline: none;
}
.search input:focus { border-color: var(--syndic-blue); background: var(--surface); }
.search .ico-search {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--ink-3);
    display: grid; place-items: center;
}
.kbd {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    font-family: var(--f-mono);
    font-size: 10px;
    color: var(--ink-3);
    background: var(--surface);
    padding: 2px 5px;
    border-radius: 4px;
    border: 1px solid var(--line);
}

/* Icon buttons (topbar actions) */
.icon-btn {
    width: 30px; height: 30px;
    display: grid; place-items: center;
    border-radius: var(--r-sm);
    background: transparent;
    border: none;
    color: var(--ink-2);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }
.icon-btn .dot {
    position: absolute; top: 6px; right: 6px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--crit);
    border: 2px solid var(--surface);
}
.icon-btn .dot.num {
    top: 2px; right: 2px;
    width: auto; height: auto;
    min-width: 16px;
    padding: 1px 4px;
    border-radius: 9px;
    border: 2px solid var(--surface);
    font-size: 9px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    color: white;
}

/* ========== Page content ========================================= */

.page {
    flex: 1;
    padding: 28px 28px 56px;
    min-width: 0;
    max-width: 1500px;
}

/* ========== Sidebar backdrop (mobile) ============================ */

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 5;
}

/* ========== Responsive — mobile < 768px ========================== */

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

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 20;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: block;
    }

    .hamburger {
        display: flex;
    }

    .topbar {
        padding: 8px 12px;
        gap: 8px;
    }

    .search {
        flex: 1;
        min-width: 0;
    }

    .page {
        padding: 16px 12px 40px;
    }
}

/* ========== MudBlazor overrides (within pages, not shell) ======== */

.mud-card {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    box-shadow: none;
}
.mud-card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    align-items: center;
}
.mud-card-header .mud-typography {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.005em;
}
.mud-card-content { padding: 18px; }
.mud-card-actions {
    padding: 10px 18px;
    border-top: 1px solid var(--line);
    gap: 8px;
}

.mud-chip.mud-chip-filled.mud-chip-color-default,
.mud-chip.mud-chip-outlined.mud-chip-color-default {
    font-size: 11px;
    font-weight: 600;
    height: auto;
    padding: 2px 7px;
    border-radius: 100px;
    background: var(--bg-3);
    color: var(--ink-2);
    border: none;
    line-height: 1.4;
    min-height: 0;
}

/* Override old MudDrawer border (no longer used but keep for safety) */
.mud-drawer { border-right: none; }

/* ========== Drawer overlay (Finance, etc.) ========== */

.drawer-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
}

.drawer {
    width: 420px;
    max-width: 90vw;
    background: var(--surface);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.drawer-title {
    font-weight: 600;
    font-size: 14px;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
}

.drawer-foot {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 14px 18px;
    border-top: 1px solid var(--line);
}

/* Legacy shell selectors kept for test backward compat */
.shell-page-wrapper { min-width: 0; }

/* ========== RTL overrides ======================================== */
[dir="rtl"] .sidebar {
    border-right: none;
    border-left: 1px solid var(--line);
}

[dir="rtl"] .nav .nav-item {
    text-align: right;
}

[dir="rtl"] .nav .nav-item .badge {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .nav-item-sub {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .search {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .search .ico-search {
    left: auto;
    right: 10px;
}

[dir="rtl"] .kbd {
    right: auto;
    left: 6px;
}

[dir="rtl"] .icon-btn .dot {
    right: auto;
    left: 6px;
}

[dir="rtl"] .icon-btn .dot.num {
    right: auto;
    left: 2px;
}

[dir="rtl"] .drawer {
    border-left: none;
    border-right: 1px solid var(--line);
}

[dir="rtl"] .sidebar-backdrop { /* no dir change — full-screen overlay */ }

@keyframes slideInRtl {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

[dir="rtl"] .drawer {
    animation-name: slideInRtl;
}

@media (max-width: 767px) {
    [dir="rtl"] .sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
    }
    [dir="rtl"] .sidebar.open {
        transform: translateX(0);
    }
}
