:root {
    --sidebar-width: 252px;
    --app-bg: #f3f6fb;
    --card-bg: #ffffff;
    --text-main: #111827;
    --text-muted: #667085;
    --border: #e5e7eb;
    --primary: #1f5f3a;
    --primary-2: #2563eb;
    --primary-soft: #eaf3ee;
    --sidebar-bg: #ffffff;
    --link: #344054;
    --link-hover: #f1f5f9;
    --link-active: #eaf3ee;
    --shadow: 0 12px 32px rgba(15, 23, 42, .07);
    --radius: 18px;
}

html[data-theme="dark"] {
    --app-bg: #0f172a;
    --card-bg: #111827;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --border: #1f2937;
    --primary-soft: rgba(34, 197, 94, .12);
    --sidebar-bg: #111827;
    --link: #d1d5db;
    --link-hover: #1f2937;
    --link-active: rgba(34, 197, 94, .14);
    --shadow: 0 12px 32px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    min-height: 100%;
    margin: 0;
    background: var(--app-bg);
    color: var(--text-main);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

a { color: inherit; }
.app-wrapper { display: flex; min-height: 100vh; width: 100%; }

.app-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1040;
    scrollbar-width: thin;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--primary), #0f766e);
    color: #ffffff;
    font-size: 20px;
    box-shadow: 0 10px 22px rgba(31, 95, 58, .24);
}

.brand-title { font-weight: 850; font-size: 18px; letter-spacing: -.02em; }
.brand-subtitle { color: var(--text-muted); font-size: 12px; margin-top: 1px; }

.sidebar-profile {
    margin: 14px 14px 6px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(234, 243, 238, .84), rgba(255,255,255,.68));
    display: flex;
    gap: 10px;
    align-items: center;
}

html[data-theme="dark"] .sidebar-profile {
    background: rgba(34, 197, 94, .08);
}

.profile-avatar,
.user-chip-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--primary);
    font-weight: 800;
    flex: 0 0 auto;
}
.profile-name { font-weight: 750; line-height: 1.2; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-role { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.sidebar-menu { padding: 8px 12px 24px; }
.sidebar-heading {
    margin: 18px 8px 7px;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .09em;
    font-weight: 850;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    color: var(--link);
    text-decoration: none;
    padding: 10px 11px;
    border-radius: 12px;
    margin-bottom: 3px;
    line-height: 1.3;
    font-weight: 560;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}
.sidebar-link i { width: 19px; text-align: center; color: #64748b; }
.sidebar-link:hover { background: var(--link-hover); color: var(--primary); transform: translateX(2px); }
.sidebar-link:hover i { color: var(--primary); }
.sidebar-link.active {
    background: var(--link-active);
    color: var(--primary);
    font-weight: 800;
}
.sidebar-link.active i { color: var(--primary); }

.app-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
}

.app-header {
    min-height: 68px;
    padding: 13px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 1030;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

html[data-theme="dark"] .app-header { background: rgba(17, 24, 39, .9); }
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.page-title { margin: 0; font-size: 20px; font-weight: 850; letter-spacing: -.02em; color: var(--text-main); }
.page-subtitle { color: var(--text-muted); font-size: 12px; margin-top: 1px; }
.header-actions { display: flex; align-items: center; gap: 9px; }

.btn-icon {
    border: 1px solid var(--border);
    color: var(--text-main);
    background: var(--card-bg);
    border-radius: 12px;
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
}
.btn-icon:hover { background: var(--link-hover); border-color: #cbd5e1; }
.btn-logout {
    border: 1px solid #fecaca;
    color: #b91c1c;
    background: #fff;
    border-radius: 12px;
    height: 38px;
    padding: 0 12px;
    display: inline-flex;
    gap: 7px;
    align-items: center;
    font-weight: 750;
}
.btn-logout:hover { background: #fef2f2; color: #991b1b; border-color: #fca5a5; }
.user-chip {
    align-items: center;
    gap: 9px;
    padding: 5px 9px 5px 5px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 999px;
}
.user-chip-copy { display: flex; flex-direction: column; line-height: 1.1; }
.user-chip-copy strong { font-size: 13px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-copy small { color: var(--text-muted); font-size: 11px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-main { padding: 18px; }
.container, .container-fluid { max-width: 100% !important; padding-left: 0 !important; padding-right: 0 !important; }
.card { background: var(--card-bg); color: var(--text-main); border-color: var(--border); }
.table { color: var(--text-main); }
.app-breadcrumb { background: transparent; margin-bottom: 10px; font-size: 12px; }
.app-alert { border: 0; box-shadow: var(--shadow); border-radius: 14px; }

.app-loading {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,.68);
    z-index: 3000;
    display: grid;
    place-items: center;
    text-align: center;
    font-weight: 700;
}
.app-loading.d-none { display: none !important; }
.app-loading-box {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 22px 26px;
}
html[data-theme="dark"] .app-loading { background: rgba(15, 23, 42, .72); }

.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    .app-sidebar.show { transform: translateX(0); }
    .app-content { margin-left: 0; width: 100%; }
    .app-header { padding: 11px 12px; }
    .app-main { padding: 12px; }
    .page-title { font-size: 17px; }
    .sidebar-backdrop.show {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .42);
        z-index: 1035;
    }
}
