/* App shell: sidebar, top bar, content viewport, section states */

/* ==== Sidebar (Replaced by Top Navigation Header) ==== */
.sidebar,
.topbar-toggle-btn,
.sidebar-toggle-btn {
    display: none !important;
}

.sidebar .logo {
    height: var(--topbar-h);
    flex: 0 0 var(--topbar-h);
    padding: 0 1rem 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    color: var(--on-brand);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar .sidebar-toggle-btn {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border: none;
    background: transparent;
    color: var(--on-brand);
    font-size: 1.1rem;
    display: grid;
    place-items: center;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 0.16s ease, color 0.16s ease;
}

.sidebar .sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--on-brand);
}

body:not(.sidebar-hidden) .topbar-toggle-btn {
    display: none !important;
}

.logo-caption {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--on-brand);
}

.nav-menu {
    padding: 0.85rem 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.nav-item {
    position: relative;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background-color 0.16s ease, color 0.16s ease;
    overflow: hidden;
}

.nav-item i {
    width: 20px;
    flex: 0 0 20px;
    text-align: center;
    font-size: 0.95rem;
    color: var(--sidebar-text);
    transition: color 0.16s ease;
}

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

.nav-item:hover i {
    color: var(--faint);
}

.nav-item.active {
    color: var(--sidebar-text-active);
    background-color: var(--sidebar-active-bg);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.nav-item.active i {
    color: var(--on-brand);
    opacity: 1;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3.5px;
    background: linear-gradient(180deg, var(--brand-line) 0%, var(--brand-line) 100%);
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
}

/* ==== Main column ==== */
.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    height: var(--topbar-h);
    flex: 0 0 var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0 var(--page-pad-x);
}

.top-bar-left {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
    font-size: 0.8125rem;
    line-height: 1.4;
    white-space: nowrap;
}

.role-badge #header-role-text {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.role-badge .header-badge-user {
    color: var(--ink);
    font-weight: 600;
    font-size: 0.8125rem;
    line-height: 1.4;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
    padding-bottom: 2px;
}

.role-badge .header-badge-sep {
    color: var(--faint);
    margin: 0 0.1rem;
    font-weight: 400;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
}

.role-badge .header-badge-role-group {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--surface-2);
    padding: 0.22rem 0.6rem;
    border-radius: 9999px;
    border: 1px solid var(--line);
}

.role-badge .header-badge-role-group i {
    color: var(--brand-ink);
    font-size: 0.8rem;
}

.role-badge .header-badge-role {
    color: var(--ink);
    font-weight: 600;
    font-size: 0.775rem;
}

.sidebar-toggle-btn {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.sidebar-toggle-btn:hover {
    background: var(--primary-soft);
    border-color: var(--primary-soft-border);
    color: var(--primary);
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-md);
    width: 320px;
}

.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font: inherit;
    font-size: 0.875rem;
}

.search-bar i {
    color: var(--text-faint);
}

.user-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--brand);
    color: var(--on-brand);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 650;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    line-height: 1;
    overflow: hidden;
    white-space: nowrap;
}

.user-profile {
    display: flex;
    align-items: center;
    padding: 0.2rem;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    background: transparent;
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease;
}

.user-profile:hover {
    border-color: var(--border);
    background: var(--bg-sunken);
}

/* ==== Content viewport ==== */
.content-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--page-card-gap) var(--page-pad-x) var(--page-pad-x);
}

.view-section {
    display: none;
    min-width: 0;
}

.view-section.active {
    display: grid;
    align-content: start;
    gap: var(--page-card-gap);
    animation: fadeIn 0.24s ease;
}

/* Table pages fill the viewport so their table body scrolls, not the page */
.view-section.view-fill.active {
    height: 100%;
    min-height: 420px;
    grid-template-rows: minmax(0, 1fr);
    align-content: stretch;
}

.view-section.active>* {
    margin-top: 0;
    margin-bottom: 0;
    min-width: 0;
}

/* ==== Auth visibility states ==== */
body.logged-out .sidebar,
body.logged-out .auth-only {
    display: none !important;
}

body.logged-in .guest-only {
    display: none !important;
}

body.logged-out,
body.logged-out .app-layout,
body.logged-out .main-content {
    background-color: var(--surface-2) !important;
}

body.logged-out .top-bar {
    background-color: var(--surface-2) !important;
    border-bottom: 1px solid transparent !important;
    box-shadow: none !important;
    max-width: 1160px !important;
    width: 100% !important;
    margin: 0 auto !important;
    padding: 1.5rem 0 0 0 !important;
    box-sizing: border-box !important;
}

@media (max-width: 1220px) {
    body.logged-out .top-bar {
        padding-left: 2rem !important;
        padding-right: 2rem !important;
    }
}

body.logged-out .header-brand {
    border-right: none !important;
    padding-right: 0 !important;
    margin-right: 0 !important;
}

body.logged-out .content-wrapper {
    padding: 0 !important;
    background-color: var(--surface-2) !important;
    overflow: hidden !important;
}

/* ==== Home ==== */
.home-section {
    display: none;
    background-color: var(--surface-2);
    min-height: calc(100vh - 65px);
    height: calc(100vh - 65px);
    align-items: center;
    justify-content: center;
    padding: 1rem 0;
    box-sizing: border-box;
    overflow: hidden;
}

.home-section.active {
    display: flex;
}

.home-hero {
    width: 100%;
    max-width: 1160px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 2.5rem;
    align-items: center;
}

@media (max-width: 1220px) {
    .home-hero {
        padding-left: 2rem;
        padding-right: 2rem;
        box-sizing: border-box;
    }
}

@media (max-width: 1024px) {
    .home-hero {
        grid-template-columns: minmax(0, 1fr) 350px;
        gap: 1.75rem;
    }
}

@media (max-width: 768px) {
    .home-section {
        height: auto;
        min-height: calc(100vh - 65px);
        overflow-y: auto;
        padding: 2rem 1.25rem;
    }

    .home-hero {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}

.home-left-col {
    display: flex;
    flex-direction: column;
}

.hero-badge {
    align-self: flex-start;
    padding: 4px 13px;
    background: var(--brand-soft);
    color: var(--brand-ink);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-radius: 9999px;
    border: 1px solid var(--brand-line);
    margin-bottom: 12px;
}

.hero-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 38px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--ink);
    margin: 0 0 12px 0;
    letter-spacing: -0.02em;
}

@media (max-width: 768px) {
    .hero-title {
        font-size: 30px;
    }
}

.hero-subtitle {
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--muted);
    margin: 0 0 24px 0;
    max-width: 500px;
}

.hero-feature-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

@media (max-width: 600px) {
    .hero-feature-grid {
        grid-template-columns: 1fr;
    }
}

.hero-feature-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.03);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hero-feature-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.hero-feature-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 10px;
    background: var(--brand-soft);
    color: var(--brand-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.hero-feature-text h3 {
    margin: 0 0 3px 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--ink);
}

.hero-feature-text p {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--muted);
}

/* Sign in Card */
.home-right-col {
    display: flex;
    justify-content: center;
    width: 100%;
}

.login-card {
    background: var(--surface);
    border-radius: 24px;
    border: 1px solid var(--surface);
    box-shadow: 0 20px 40px -15px rgba(15, 23, 42, 0.07), 0 2px 6px rgba(0, 0, 0, 0.02);
    padding: 30px 28px 22px 28px;
    width: 100%;
    max-width: 380px;
}

.login-card-title {
    font-size: 26px;
    font-weight: 700;
    color: var(--ink);
    margin: 0 0 6px 0;
    letter-spacing: -0.02em;
}

.login-card-subtitle {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 24px 0;
    line-height: 1.45;
}

.login-card-form .form-group {
    margin-bottom: 0; /* no labels: the form's own gap spaces the fields */
}

.login-card-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 7px;
}

.login-input-wrap {
    position: relative !important;
    display: flex;
    align-items: center;
    background: var(--surface-2);
    border-radius: 10px;
    padding: 0 38px 0 14px;
    height: 44px;
    border: 1px solid var(--line);
    transition: all 0.2s ease;
}

.login-input-wrap:focus-within {
    background: var(--surface);
    border-color: var(--brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 12%, transparent);
}

.login-input-wrap .input-icon {
    color: var(--faint);
    font-size: 15px;
    margin-right: 10px;
    min-width: 15px;
    transition: color 0.2s ease;
}

.login-input-wrap:focus-within .input-icon {
    color: var(--brand-ink) !important;
}

.login-input-wrap input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 13.5px;
    color: var(--ink);
    font-family: inherit;
}

.login-input-wrap select {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    height: 100%;
    font-size: 13.5px;
    color: var(--ink);
    font-family: inherit;
    cursor: pointer;
}

.login-input-wrap input:-webkit-autofill,
.login-input-wrap input:-webkit-autofill:hover,
.login-input-wrap input:-webkit-autofill:focus,
.login-input-wrap input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px transparent inset !important;
    transition: background-color 50000s ease-in-out 0s;
    background-color: transparent !important;
    -webkit-text-fill-color: var(--ink) !important;
}

.login-input-wrap input::placeholder {
    color: var(--faint);
}

.login-input-wrap .password-toggle {
    position: absolute !important;
    right: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    background: transparent !important;
    border: none !important;
    color: var(--faint) !important;
    cursor: pointer !important;
    padding: 0 !important;
    font-size: 14px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 26px !important;
    height: 26px !important;
    border-radius: 6px !important;
    z-index: 2 !important;
}

.login-input-wrap .password-toggle:hover {
    color: var(--brand-ink) !important;
}

.login-btn-primary,
#login-submit-btn {
    width: 100% !important;
    height: 45px !important;
    background: var(--brand) !important;
    color: var(--on-brand) !important;
    border: none !important;
    border-radius: var(--radius) !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    margin-top: 6px !important; /* with the form's 16px gap: 22px under the last field */
    transition: background-color 0.16s ease !important;
    box-shadow: none !important;
}

.login-btn-primary:hover:not(:disabled),
#login-submit-btn:hover:not(:disabled) {
    background: var(--brand-hover) !important;
}

.login-btn-primary:disabled,
#login-submit-btn:disabled {
    opacity: 0.7 !important;
    cursor: not-allowed !important;
}

.login-card-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    text-align: center;
    font-size: 11.5px;
    color: var(--faint);
}

/* ==== Responsive shell ==== */
@media (max-width: 1100px) {
    :root {
        --page-pad-x: 1.25rem;
    }

    /* the badge keeps only the role, so the header never overlaps the tabs */
    .role-badge .header-badge-user,
    .role-badge .header-badge-sep {
        display: none;
    }
}

@media (max-width: 760px) {
    .role-badge {
        display: none !important;
    }
}

@media (max-width: 900px) {
    body.logged-out .content-wrapper {
        padding: 0 !important;
    }

    .search-bar {
        display: none !important;
    }
}

/* Below this width the fixed sidebar steals too much room, so the nav becomes a top strip
   and the page scrolls instead of the table body. */
@media (max-width: 880px) {
    .app-layout {
        flex-direction: column;
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        flex: 0 0 auto;
    }

    body.sidebar-hidden .sidebar {
        width: 100%;
        flex-basis: auto;
    }

    .sidebar .logo {
        display: none;
    }

    .nav-menu {
        flex-direction: row;
        gap: 0.35rem;
        padding: 0.5rem;
        overflow-x: auto;
    }

    .nav-item {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .main-content {
        min-height: 0;
        overflow: visible;
    }

    .top-bar {
        padding: 0 1rem;
    }

    .content-wrapper {
        overflow: visible;
        padding: 1rem;
    }

    .view-section.view-fill.active {
        height: auto;
        grid-template-rows: none;
    }

    .sidebar-toggle-btn {
        display: none !important;
    }
}
/* the minimal sign-in card: fields 12px apart, the button a little below */
.login-card-form {
    gap: 12px !important;
}
.login-card-form .login-btn-primary {
    margin-top: 8px !important;
}

/* sign-in page: both columns start at the same top line, close to the header */
.home-section {
    align-items: flex-start;
    padding-top: clamp(2rem, 9vh, 5rem);
}
.home-hero {
    align-items: start;
}
