:root {
    --ink: #111827;
    --ink-soft: #374151;
    --muted: #6b7280;
    --line: #d9e0ea;
    --surface: #ffffff;
    --surface-soft: #f5f7fb;
    --sidebar: #111827;
    --sidebar-2: #182234;
    --primary: #0f766e;
    --primary-2: #0ea5a3;
    --blue: #2563eb;
    --amber: #b7791f;
    --red: #dc2626;
    --green: #059669;
    --shadow: 0 10px 28px rgba(15, 23, 42, .08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--surface-soft);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    display: flex;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-direction: column;
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
    color: #f8fafc;
    padding: 22px 16px;
}

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

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: var(--radius);
    background: #f8fafc;
    color: var(--primary);
    font-size: 22px;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 18px;
}

.brand small {
    color: #a8b3c7;
    font-size: 12px;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
    margin-top: 28px;
}

.nav-item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: #cbd5e1;
    padding: 11px 12px;
    font-size: 14px;
    text-align: left;
    transition: .18s ease;
}

.nav-item i {
    width: 20px;
    font-size: 17px;
}

.nav-item:hover,
.nav-item.active {
    border-color: rgba(255, 255, 255, .12);
    background: rgba(255, 255, 255, .08);
    color: #ffffff;
}

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, .12);
    padding-top: 18px;
    color: #a8b3c7;
    font-size: 13px;
}

.live-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 5px rgba(5, 150, 105, .18);
}

.main {
    min-width: 0;
}

.topbar {
    display: flex;
    position: sticky;
    z-index: 10;
    top: 0;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(245, 247, 251, .92);
    padding: 22px 30px;
    backdrop-filter: blur(14px);
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 760;
}

.topbar p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.topbar-actions,
.toolbar-actions,
.action-strip,
.pager {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-soft);
    transition: .18s ease;
}

.icon-btn:hover {
    border-color: #b7c3d4;
    color: var(--ink);
    transform: translateY(-1px);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 8px 11px;
    color: var(--ink-soft);
    font-size: 14px;
}

.content {
    padding: 26px 30px 38px;
}

.loading-panel,
.empty-state {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 26px;
    color: var(--muted);
}

.btn {
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 650;
}

.btn-primary {
    border-color: var(--primary);
    background: var(--primary);
}

.btn-primary:hover,
.btn-primary:focus {
    border-color: #0b5e58;
    background: #0b5e58;
}

.btn-light {
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink-soft);
}

.action-strip {
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.kpi-card,
.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.kpi-card {
    padding: 18px;
}

.kpi-card span,
.kpi-card small {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.kpi-card strong {
    display: block;
    margin: 8px 0 4px;
    color: var(--ink);
    font-size: 30px;
    line-height: 1;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 18px;
}

.panel {
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    padding: 16px 18px;
}

.panel-head h2,
.roles-page h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 750;
}

.roles-page p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.text-btn {
    border: 0;
    background: transparent;
    color: var(--primary);
    font-weight: 700;
}

.mini-table,
.crud-table,
.role-matrix {
    margin: 0;
    min-width: 760px;
}

.table > :not(caption) > * > * {
    border-bottom-color: #edf1f6;
    padding: 12px 14px;
    vertical-align: middle;
}

.table thead th {
    color: #64748b;
    font-size: 12px;
    font-weight: 760;
    text-transform: uppercase;
}

.table tbody td {
    color: var(--ink-soft);
    font-size: 13px;
}

.badge-soft {
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 750;
}

.badge-success {
    background: rgba(5, 150, 105, .12);
    color: var(--green);
}

.badge-warning {
    background: rgba(183, 121, 31, .13);
    color: var(--amber);
}

.badge-danger {
    background: rgba(220, 38, 38, .11);
    color: var(--red);
}

.badge-neutral {
    background: #edf2f7;
    color: #475569;
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.search-box {
    display: flex;
    width: min(460px, 100%);
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 0 12px;
}

.search-box i {
    color: var(--muted);
}

.search-box .form-control {
    border: 0;
    box-shadow: none;
    padding-left: 0;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.filter-row .form-control {
    width: 190px;
    border-radius: var(--radius);
    font-size: 13px;
}

.table-panel {
    box-shadow: var(--shadow);
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--line);
    padding: 12px 14px;
    color: var(--muted);
    font-size: 13px;
}

.pager .form-select {
    width: 76px;
}

.row-actions {
    display: flex;
    gap: 6px;
}

.row-actions .icon-btn {
    width: 32px;
    height: 32px;
}

.modal-content {
    border: 0;
    border-radius: var(--radius);
    box-shadow: 0 24px 70px rgba(15, 23, 42, .22);
}

.modal-header,
.modal-footer {
    border-color: var(--line);
}

.form-label {
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 700;
}

.form-control,
.form-select {
    border-color: var(--line);
    border-radius: var(--radius);
    font-size: 14px;
}

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

.record-view {
    display: grid;
    gap: 10px;
}

.record-view-row {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 12px;
    border-bottom: 1px solid #edf1f6;
    padding-bottom: 10px;
}

.record-view-row strong {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.json-block {
    max-height: 360px;
    overflow: auto;
    border-radius: var(--radius);
    background: #111827;
    color: #d1fae5;
    padding: 14px;
    font-size: 12px;
}

.role-select-wrap {
    max-width: 320px;
    padding: 18px 18px 0;
}

.role-matrix {
    margin-top: 8px;
}

.role-matrix input {
    width: 18px;
    height: 18px;
}

.login-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, .12), transparent 34%),
        linear-gradient(315deg, rgba(37, 99, 235, .12), transparent 38%),
        var(--surface-soft);
    padding: 24px;
}

.login-card {
    width: min(430px, 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 28px;
}

.login-brand {
    margin-bottom: 24px;
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 28px;
    font-weight: 780;
}

.login-card p {
    margin: 0 0 22px;
    color: var(--muted);
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 82px minmax(0, 1fr);
    }

    .sidebar {
        padding: 18px 12px;
    }

    .brand span:not(.brand-mark),
    .nav-item span,
    .sidebar-footer span {
        display: none;
    }

    .nav-item {
        justify-content: center;
    }

    .kpi-grid,
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 700px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .sidebar-nav {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .topbar,
    .content {
        padding: 18px;
    }

    .kpi-grid,
    .dashboard-grid,
    .record-grid {
        grid-template-columns: 1fr;
    }

    .table-toolbar,
    .table-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-actions {
        flex-wrap: wrap;
    }

    .record-view-row {
        grid-template-columns: 1fr;
    }
}
