* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #172033;
    background: #f4f6fb;
}

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at top left, #dceafe, transparent 34%),
        linear-gradient(135deg, #eef2ff, #f8fafc);
}

.login-card {
    width: 390px;
    max-width: calc(100% - 32px);
    background: #ffffff;
    border-radius: 24px;
    padding: 34px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, .14);
}

.login-brand {
    text-align: center;
    margin-bottom: 26px;
}

.login-logo,
.sidebar-logo {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: #2563eb;
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    letter-spacing: -1px;
}

.login-brand h1 {
    margin: 14px 0 4px;
    font-size: 24px;
}

.login-brand p,
.login-help {
    margin: 0;
    color: #64748b;
    font-size: 14px;
}

.login-help {
    text-align: center;
    margin-top: 18px;
}

.login-help a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 700;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    margin: 16px 0 6px;
}

input {
    width: 100%;
    height: 44px;
    border: 1px solid #dbe3ef;
    border-radius: 12px;
    padding: 0 14px;
    font-size: 15px;
    outline: none;
    background: #f8fafc;
}

input:focus {
    border-color: #2563eb;
    background: white;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .10);
}

button,
.btn-mini {
    height: 46px;
    border: 0;
    border-radius: 12px;
    background: #2563eb;
    color: white;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    padding: 0 18px;
}

.login-card button {
    width: 100%;
    margin-top: 24px;
}

button:hover,
.btn-mini:hover {
    background: #1d4ed8;
}

.alert {
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 14px;
    margin-bottom: 18px;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-ok {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.app-body {
    min-height: 100vh;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 270px;
    background: #0f172a;
    color: white;
    padding: 22px;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.sidebar-brand strong {
    display: block;
    font-size: 17px;
}

.sidebar-brand span {
    display: block;
    font-size: 13px;
    color: #94a3b8;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-menu a {
    color: #cbd5e1;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 14px;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: rgba(255, 255, 255, .10);
    color: white;
}

.sidebar-menu a span {
    width: 24px;
    text-align: center;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 86px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
}

.topbar p {
    margin: 4px 0 0;
    color: #64748b;
    font-size: 14px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user strong {
    display: block;
    font-size: 14px;
}

.topbar-user span {
    display: block;
    color: #64748b;
    font-size: 12px;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: #e0ecff;
    color: #1d4ed8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
}

.logout-link {
    color: #ef4444;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    margin-left: 8px;
}

.content-card {
    margin: 24px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 24px;
    min-height: calc(100vh - 134px);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .04);
}

.loading,
.empty-state {
    color: #64748b;
    padding: 24px;
    text-align: center;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
    gap: 16px;
}

.page-header h2 {
    margin: 0;
    font-size: 24px;
}

.page-header p {
    margin: 4px 0 0;
    color: #64748b;
}

.stats-grid,
.info-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 18px;
}

.stat-card,
.info-box {
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 20px;
    background: #f8fafc;
}

.stat-card span,
.info-box span {
    color: #64748b;
    font-size: 14px;
}

.stat-card strong {
    display: block;
    font-size: 34px;
    margin: 8px 0;
}

.info-box strong {
    display: block;
    font-size: 18px;
    margin-top: 8px;
}

.stat-card small {
    color: #94a3b8;
}

.table-wrap {
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
}

.app-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.app-table th,
.app-table td {
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 14px;
}

.app-table th {
    background: #f8fafc;
    color: #475569;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.app-table tr:last-child td {
    border-bottom: 0;
}

.app-table small {
    color: #64748b;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 800;
}

.badge.ok {
    background: #ecfdf5;
    color: #047857;
}

.badge.off {
    background: #f1f5f9;
    color: #64748b;
}

@media (max-width: 900px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .stats-grid,
    .info-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        height: auto;
        padding: 18px;
        align-items: flex-start;
        gap: 16px;
        flex-direction: column;
    }

    .content-card {
        margin: 14px;
    }
}

.page-header-actions {
    gap: 16px;
}

.btn-primary,
.btn-secondary,
.btn-mini,
.btn-icon,
.btn-small {
    width: auto;
    height: auto;
    margin: 0;
    border: 0;
    cursor: pointer;
    font-weight: 800;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary,
.btn-mini {
    background: #2563eb;
    color: #fff;
    border-radius: 12px;
    padding: 11px 16px;
}

.btn-primary:hover,
.btn-mini:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #f1f5f9;
    color: #334155;
    border-radius: 12px;
    padding: 11px 16px;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-small {
    padding: 8px 11px;
    font-size: 12px;
}

.btn-icon {
    background: #eef2ff;
    color: #1d4ed8;
    border-radius: 10px;
    padding: 7px 10px;
    font-size: 12px;
}

.btn-icon:hover {
    background: #dbeafe;
}

.btn-icon.danger {
    background: #fef2f2;
    color: #b91c1c;
}

.btn-icon.danger:hover {
    background: #fee2e2;
}

.toolbar-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 14px;
    margin-bottom: 18px;
}

.toolbar-search {
    flex: 1;
    max-width: 520px;
}

.toolbar-search input {
    margin: 0;
    background: #fff;
}

.toolbar-info {
    color: #64748b;
    font-size: 14px;
}

.toolbar-info strong {
    color: #172033;
}

.row-actions {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
}

.app-table td strong + small,
.permissions-user-box span,
.permissions-user-box small,
.permission-item small {
    display: block;
}

.badge.role {
    background: #eef2ff;
    color: #3730a3;
}

body.modal-open {
    overflow: hidden;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .52);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    width: 640px;
    max-width: 100%;
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: #fff;
    border-radius: 22px;
    box-shadow: 0 28px 90px rgba(15, 23, 42, .26);
    border: 1px solid #e2e8f0;
}

.modal-lg {
    width: 920px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 22px 24px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
    margin: 0;
    font-size: 22px;
}

.modal-header p {
    margin: 4px 0 0;
    color: #64748b;
    font-size: 14px;
}

.modal-close {
    width: 38px;
    height: 38px;
    margin: 0;
    border-radius: 12px;
    background: #f1f5f9;
    color: #334155;
    font-size: 24px;
    line-height: 1;
}

.modal-close:hover {
    background: #e2e8f0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 24px;
}

.form-field label {
    margin-top: 0;
}

.form-field select,
.form-field input {
    width: 100%;
}

select {
    width: 100%;
    height: 44px;
    border: 1px solid #dbe3ef;
    border-radius: 12px;
    padding: 0 14px;
    font-size: 15px;
    outline: none;
    background: #f8fafc;
}

select:focus {
    border-color: #2563eb;
    background: white;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .10);
}

.form-field small {
    display: block;
    margin-top: 6px;
    color: #64748b;
    font-size: 12px;
}

.full-row {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 10px;
}

.permissions-user-box {
    margin: 20px 24px 14px;
    padding: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
}

.permissions-user-box strong {
    font-size: 16px;
}

.permissions-user-box span,
.permissions-user-box small {
    color: #64748b;
    margin-top: 3px;
}

.permissions-actions-top {
    display: flex;
    gap: 8px;
    padding: 0 24px 14px;
}

.permissions-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 0 24px 24px;
}

.permission-group {
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    overflow: hidden;
}

.permission-group h4 {
    margin: 0;
    padding: 14px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.permission-item {
    display: flex;
    gap: 12px;
    margin: 0;
    padding: 13px 16px;
    border-bottom: 1px solid #edf2f7;
    cursor: pointer;
}

.permission-item:last-child {
    border-bottom: 0;
}

.permission-item:hover {
    background: #fafcff;
}

.permission-item input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex: 0 0 auto;
}

.permission-item strong {
    display: block;
    color: #172033;
    font-size: 14px;
}

.permission-item small {
    color: #64748b;
    margin-top: 3px;
    line-height: 1.35;
}

.app-toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    max-width: 420px;
    z-index: 80;
    background: #0f172a;
    color: #fff;
    padding: 14px 16px;
    border-radius: 14px;
    box-shadow: 0 18px 60px rgba(15, 23, 42, .24);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: .18s ease;
    font-weight: 700;
    font-size: 14px;
}

.app-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.app-toast.error {
    background: #991b1b;
}

@media (max-width: 900px) {
    .toolbar-card,
    .permissions-user-box {
        align-items: flex-start;
        flex-direction: column;
    }

    .form-grid,
    .permissions-grid {
        grid-template-columns: 1fr;
    }

    .modal-backdrop {
        padding: 12px;
        align-items: flex-start;
    }

    .modal-card {
        max-height: calc(100vh - 24px);
    }
}
.app-toast {
    min-width: 280px;
    max-width: 420px;
    padding: 15px 18px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .22);
    transition: all .25s ease;
}

.app-toast-ok {
    background: #0f172a;
    color: #fff;
}

.app-toast-error {
    background: #991b1b;
    color: #fff;
}