:root {
    --sidebar-width: 280px;
    --ink: #172033;
    --muted: #697386;
    --line: #e5e9f0;
    --soft: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f9fbfd;
    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --accent-soft: #e8f0ff;
    --success-soft: #e8f8ef;
    --warning-soft: #fff5dd;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --shadow-sm: 0 8px 22px rgb(23 32 51 / 7%);
    --shadow-md: 0 18px 48px rgb(23 32 51 / 10%);
}

* {
    letter-spacing: 0;
}

body {
    background:
        radial-gradient(circle at top left, rgb(37 99 235 / 8%), transparent 34rem),
        linear-gradient(135deg, #f8fbff 0%, var(--soft) 48%, #eef4fb 100%);
    color: var(--ink);
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    min-height: 100vh;
}

body.sidebar-open {
    overflow: hidden;
}

a,
button,
.btn,
.form-control,
.form-select {
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: var(--sidebar-width);
    background: rgb(255 255 255 / 88%);
    border-right: 1px solid rgb(229 233 240 / 82%);
    box-shadow: 12px 0 32px rgb(23 32 51 / 4%);
    backdrop-filter: blur(18px);
    padding: 22px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1040;
}

.sidebar-backdrop {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #0f766e);
    color: #ffffff;
    display: grid;
    place-items: center;
    font-size: 21px;
    font-weight: 800;
    box-shadow: 0 14px 30px rgb(37 99 235 / 22%);
}

.brand strong {
    display: block;
    font-size: 16px;
    line-height: 1.15;
}

.brand span,
.user-chip small {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.menu {
    display: grid;
    gap: 5px;
}

.menu a {
    color: #344054;
    text-decoration: none;
    padding: 10px 11px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.menu a i {
    width: 21px;
    color: #8a94a6;
    font-size: 17px;
}

.menu a:hover,
.menu a.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    transform: translateX(2px);
}

.menu a:hover i,
.menu a.active i {
    color: var(--accent-strong);
}

.menu-label {
    color: #98a2b3;
    font-size: 11px;
    font-weight: 800;
    margin: 18px 10px 6px;
    text-transform: uppercase;
}

.logout-link {
    margin-top: 18px;
    color: var(--danger) !important;
}

.logout-link:hover {
    background: var(--danger-soft) !important;
    color: #991b1b !important;
}

.app-main {
    min-width: 0;
    flex: 1;
}

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

.menu-toggle {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    display: none;
    place-items: center;
    align-content: center;
    gap: 4px;
    padding: 10px;
    box-shadow: var(--shadow-sm);
}

.menu-toggle span:not(.visually-hidden) {
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: var(--ink);
    display: block;
}

.topbar {
    min-height: 78px;
    background: rgb(255 255 255 / 74%);
    border-bottom: 1px solid rgb(229 233 240 / 78%);
    backdrop-filter: blur(18px);
    padding: 18px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    position: sticky;
    top: 0;
    z-index: 1010;
}

.topbar h1 {
    font-size: 23px;
    font-weight: 800;
    line-height: 1.2;
    margin: 0;
    overflow-wrap: anywhere;
}

.user-chip {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 9px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    padding: 9px 12px;
    max-width: min(260px, 42vw);
}

.user-chip i {
    color: var(--accent);
    font-size: 22px;
    grid-row: span 2;
}

.user-chip span,
.user-chip small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-chip span {
    font-weight: 700;
    line-height: 1.1;
}

.content-wrap {
    padding: 28px 30px 42px;
}

.panel {
    background: rgb(255 255 255 / 92%);
    border: 1px solid rgb(229 233 240 / 88%);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.stat-card {
    background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
    border: 1px solid rgb(229 233 240 / 90%);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    padding: 20px 16px;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 12px;
    min-height: 148px;
    text-align: center;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    display: grid;
    place-items: center;
    font-size: 21px;
    flex: 0 0 auto;
}

.stat-card span {
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
    min-height: 36px;
}

.stat-card strong {
    display: block;
    color: #0f172a;
    font-size: 30px;
    line-height: 1.1;
    margin-top: 7px;
}

.table-responsive {
    border-radius: 8px;
}

.table {
    margin-bottom: 0;
    --bs-table-bg: transparent;
}

.table thead th {
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    color: #475467;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.table tbody td {
    border-color: #edf1f6;
    color: #344054;
    padding-top: 14px;
    padding-bottom: 14px;
}

.table-hover > tbody > tr:hover > * {
    --bs-table-bg-state: #f8fbff;
}

.table-actions {
    white-space: nowrap;
}

.action-dropdown {
    display: inline-flex;
    justify-content: flex-end;
}

.action-toggle {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    color: #475467;
    padding: 0;
}

.action-toggle::after {
    display: none;
}

.action-toggle:hover,
.action-toggle:focus {
    background: var(--accent-soft);
    border-color: #c7d8ff;
    color: var(--accent-strong);
}

.dropdown-menu {
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    padding: 6px;
}

.dropdown-item {
    border-radius: 7px;
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    min-height: 36px;
}

.dropdown-item i {
    width: 18px;
    color: #8a94a6;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: #f3f6fb;
}

.dropdown-item.text-danger i {
    color: var(--danger);
}

.dropdown-divider {
    border-color: var(--line);
    margin: 6px 0;
}

.empty-state {
    color: var(--muted);
    text-align: center;
    padding: 38px 12px !important;
}

.badge {
    border-radius: 7px;
    font-weight: 700;
    padding: 0.45em 0.65em;
}

.btn {
    border-radius: 8px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 10px 22px rgb(37 99 235 / 18%);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.btn-outline-secondary {
    --bs-btn-color: #475467;
    --bs-btn-border-color: #d0d5dd;
    --bs-btn-hover-bg: #f2f4f7;
    --bs-btn-hover-border-color: #c5ccd8;
    --bs-btn-hover-color: #101828;
}

.form-label {
    color: #344054;
    font-size: 13px;
    font-weight: 700;
}

.form-control,
.form-select {
    border-color: #d8dee8;
    border-radius: 8px;
    min-height: 42px;
}

.form-control:focus,
.form-select:focus {
    border-color: #93b4ff;
    box-shadow: 0 0 0 4px rgb(37 99 235 / 11%);
}

.input-icon {
    position: relative;
}

.input-icon i {
    color: #98a2b3;
    font-size: 17px;
    left: 14px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
}

.input-icon .form-control {
    padding-left: 42px;
}

.alert {
    border-radius: 8px;
    border-width: 1px;
    box-shadow: var(--shadow-sm);
}

.pagination {
    margin-top: 18px;
}

.page-link {
    border-color: var(--line);
    color: var(--accent-strong);
    font-weight: 700;
}

.active > .page-link,
.page-link.active {
    background: var(--accent);
    border-color: var(--accent);
}

.form-page {
    width: 100%;
    max-width: none;
}

.form-page form {
    width: 100%;
}

.form-page .row > * {
    min-width: 0;
}

.form-page .form-control,
.form-page .form-select {
    max-width: 100%;
}

.login-page {
    background:
        linear-gradient(135deg, rgb(37 99 235 / 12%), transparent 34%),
        linear-gradient(315deg, rgb(15 118 110 / 12%), transparent 32%),
        #f6f9fc;
}

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
}

.login-card {
    width: min(440px, 100%);
    padding: 28px;
    box-shadow: var(--shadow-md);
}

@media (max-width: 900px) {
    .sidebar {
        width: min(84vw, 320px);
        max-width: 100%;
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        transition: transform 220ms ease;
        box-shadow: 18px 0 44px rgb(23 32 51 / 16%);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1030;
        border: 0;
        background: rgb(15 23 42 / 48%);
        opacity: 0;
        pointer-events: none;
        transition: opacity 220ms ease;
        display: block;
    }

    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .topbar {
        padding: 14px 18px;
    }

    .menu-toggle {
        display: grid;
        flex: 0 0 auto;
    }

    .content-wrap {
        padding: 18px;
    }

    .panel {
        padding: 16px;
    }

    .user-chip {
        padding: 8px 10px;
        max-width: 40vw;
    }

    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    body {
        font-size: 14px;
    }

    .topbar {
        min-height: 66px;
        gap: 12px;
        padding: 12px 14px;
    }

    .topbar h1 {
        font-size: 19px;
    }

    .user-chip small {
        display: none;
    }

    .user-chip {
        grid-template-columns: auto auto;
    }

    .stat-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        min-height: 132px;
    }

    .content-wrap {
        padding: 14px 12px 28px;
    }

    .panel > .d-flex:first-child,
    .panel > form.d-flex:first-child {
        align-items: stretch !important;
        flex-direction: column;
    }

    .panel > .d-flex:first-child form,
    .panel > form.d-flex:first-child {
        width: 100%;
    }

    .panel > .d-flex:first-child .btn,
    .panel > form.d-flex:first-child .btn {
        width: 100%;
    }

    .table-responsive {
        overflow: visible;
    }

    .table thead {
        display: none;
    }

    .table tbody {
        display: grid;
        gap: 12px;
    }

    .table tbody tr {
        background: #ffffff;
        border: 1px solid var(--line);
        border-radius: 8px;
        box-shadow: 0 8px 20px rgb(23 32 51 / 6%);
        display: grid;
        padding: 5px 12px;
    }

    .table tbody td {
        align-items: start;
        border: 0;
        border-bottom: 1px solid #edf1f6;
        display: grid;
        gap: 12px;
        grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
        overflow-wrap: anywhere;
        padding: 11px 0;
    }

    .table tbody td::before {
        color: var(--muted);
        content: attr(data-label);
        font-size: 12px;
        font-weight: 800;
    }

    .table tbody td:last-child {
        border-bottom: 0;
    }

    .table tbody td[colspan],
    .table tbody td.empty-state {
        display: block;
        text-align: center;
        border-bottom: 0;
        padding: 30px 10px !important;
    }

    .table tbody td[colspan]::before,
    .table tbody td.empty-state::before {
        content: none;
    }

    .table-actions {
        display: block !important;
        white-space: normal;
    }

    .table-actions::before {
        display: block;
        margin-bottom: 4px;
    }

    .table-actions .btn,
    .table-actions form,
    .table-actions form .btn {
        width: 100%;
    }

    .action-dropdown {
        display: block;
        width: 100%;
    }

    .action-toggle {
        width: 100%;
    }

    .action-toggle i {
        margin: 0 auto;
    }

    .table-actions form {
        display: block !important;
    }

    .table-actions .btn,
    .table-actions form {
        margin-top: 6px;
    }

    .form-page .mt-3 {
        display: grid;
        gap: 8px;
    }

    .form-page .btn {
        width: 100%;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
    }
}

@media (max-width: 380px) {
    .user-chip {
        display: none;
    }
}
