/* ═══════════════════════════════════════════════════════════════
   layout.css — Shell, Sidebar, Topbar, Footer
   ═══════════════════════════════════════════════════════════════ */

/* ── Layout Shell ────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; width: 100%; align-items: stretch; }

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    margin-left: var(--sidebar-w);
    overflow-x: clip;
}

.page-content {
    padding: 1.75rem;
    padding-bottom: 3rem;
    flex: 1;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: #16213e;
    color: #8a99aa;
    padding: 1.25rem 0;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
}

.sidebar-brand {
    padding: 0 1.1rem 1.25rem;
    font-size: 15px;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    margin-bottom: 0.75rem;
}

.sidebar-brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #3d5070;
    padding: 0 1.1rem;
    margin: 1rem 0 0.35rem;
}

.sidebar a { text-decoration: none; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8.5px 1.1rem;
    font-size: 12.5px;
    color: #7a8fa6;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border-radius: 0 8px 8px 0;
    margin-right: 12px;
}

.nav-item:hover { background: rgba(255,255,255,0.05); color: #c9d1d9; }

.nav-item.active {
    background: rgba(83,74,183,0.18);
    color: #a8a2ef;
    border-left-color: var(--brand);
    font-weight: 600;
}

.nav-item i { width: 14px; text-align: center; flex-shrink: 0; }

/* ── Collapsible Nav Groups ──────────────────────────────────────── */
.nav-group { margin-top: 0.25rem; }

.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.1rem 0.35rem;
    cursor: pointer;
    user-select: none;
}

.nav-group-header:hover .sidebar-label { color: #6b8aaa; }
.nav-group-icon { font-size: 9px; color: #3d5070; transition: transform 0.2s ease; }
.nav-group-icon.open { transform: rotate(180deg); }
.nav-group-body { overflow: hidden; max-height: 0; transition: max-height 0.25s ease; }
.nav-group-body.open { max-height: 500px; }

/* ── Right Sidebar ───────────────────────────────────────────────── */
.sidebar-right {
    width: 290px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: var(--topbar-h);
    max-height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    align-self: flex-start;
    scrollbar-width: none;
}

.sidebar-right::-webkit-scrollbar { display: none; }

.sidebar-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 18px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
    background: var(--surface);
    height: var(--topbar-h);
    padding: 0 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border-bottom: 1px solid #eef0f3;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.topbar-search {
    flex: 1;
    max-width: 340px;
    margin: 0 1.5rem;
    position: relative;
}

.topbar-search input {
    width: 100%;
    height: 34px;
    background: #f4f5f7;
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-md);
    padding: 0 12px 0 34px;
    font-size: 13px;
    color: var(--text-secondary);
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

.topbar-search input:focus { background: white; border-color: #c4bef5; }
.topbar-search input::placeholder { color: var(--text-faint); }

.topbar-search i {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    font-size: 12px;
}

.hamburger { display: none; }

/* ── Page Header ─────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.page-header > div { display: flex; flex-direction: column; gap: 0.2rem; }
.page-header h1, .page-header h2 { margin: 0; }
.page-header p { margin: 0; font-size: 0.88rem; color: var(--text-faint); }

/* ── Footer ──────────────────────────────────────────────────────── */
.app-footer {
    padding: 1rem 1.75rem;
    font-size: 11px; color: var(--text-faint);
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
    background: var(--surface);
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .dashboard-layout  { flex-direction: column; gap: 1.25rem; }
    .sidebar-right     { width: 100%; flex-direction: row; flex-wrap: wrap; max-height: none; position: static; gap: 1.25rem; }
    .sidebar-right .sidebar-card { flex: 1; min-width: 260px; }
}

@media (max-width: 768px) {
    .shell { flex-direction: column; width: 100vw; overflow-x: clip; }
    .main  { width: 100vw; max-width: 100vw; margin-left: 0; overflow-x: clip; }

    .page-content {
        padding: 0.85rem;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 3rem);
        width: 100%; max-width: 100%; overflow-x: clip;
    }

    /* Sidebar drawer */
    .sidebar { position: fixed; left: -220px; top: 0; height: 100vh; width: 220px; z-index: 200; transition: left 0.25s ease; }
    .sidebar.open { left: 0; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 199; }
    .sidebar-overlay.open { display: block; }

    /* Topbar */
    /* 1. Allow topbar to wrap onto two lines */
    .topbar {
        padding: 0 1rem;
        flex-wrap: wrap;
        height: auto;
        min-height: var(--topbar-h);
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    /* 2. Replace  display: none  with full-width second row */
    .topbar-search {
        display: flex;                 
        order: 10;
        width: 100%;
        max-width: 100%;
        margin: 0 0 0.4rem 0;
        flex: 0 0 100%;
    }
    .topbar-left   { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
    .topbar-user span { display: none; }

    /* Hamburger */
    .hamburger {
        display: flex; align-items: center; justify-content: center;
        width: 36px; height: 36px;
        border: none; background: none; cursor: pointer;
        color: var(--text-secondary); font-size: 18px;
        border-radius: var(--radius-md); transition: background 0.15s; flex-shrink: 0;
    }
    .hamburger:hover { background: #f3f4f6; }

    .sidebar-right { width: 100%; position: static; max-height: none; flex-direction: column; gap: 0.85rem; }
    .sidebar-right .sidebar-card { border-radius: var(--radius-lg); border: 1px solid var(--border); box-shadow: 0 2px 4px rgba(0,0,0,0.04); }

    .page-header { flex-direction: column; align-items: flex-start; gap: 0.65rem; }
    .app-footer  { padding: 0.75rem 1rem; font-size: 10px; }

    /* Stack the main filter rows vertically */
    .filter-form-grid, 
    .form-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* Wrap the action buttons (Search/Clear & Export/Print) to share space evenly */
    .button-group,
    .actions-row {
        display: flex !important;
        flex-direction: row !important; 
        width: 100% !important;
        gap: 8px !important;
    }

    /* Allow the table below to scroll horizontally instead of clipping the screen */
    .table-container {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .page-content { padding: 0.65rem; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 3rem); }
}