@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800;900&family=Roboto:wght@400;500;700&display=swap");

:root {
    --bg: #0b0f14;
    --panel: #121821;
    --card: #0f151e;
    --muted: #9aa6b2;
    --text: #e6edf6;
    --ok: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --primary: #2563eb;
    --border: #1f2937;
    --input: #0c1118;
    --input-b: #243041;
    --chip: #171c24;
    --chip-b: #2a3442;
    --radius: 12px;
    --shadow: 0 10px 24px rgba(0, 0, 0, .25), 0 2px 6px rgba(0, 0, 0, .2);
    --focus: 0 0 0 3px rgba(37, 99, 235, .25);
    --header-bg: #11161c;
    --header-border: #1e2630;
    --header-text: #e6e6e6;
    --hc-bg: #0f141b;
    --hc-fg: #e6e6e6;
    --hc-border: #273244;
    --hc-hover: #161c26;
    --hc-focus: rgba(96, 165, 250, .45);
    --btn-h: 36px;
    --btn-radius: 10px;
    --btn-pad-x: 16px;
    --btn-bg: #1f2937;
    --btn-fg: #f8fafc;
    --btn-border: rgba(255, 255, 255, .14);
    --btn-hover: #2b3442;
    --btn-shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 10px rgba(0, 0, 0, .22);
    --btn-ghost-fg: #e6edf6;
    --btn-ghost-border: rgba(255, 255, 255, .2);
    --btn-ghost-hover: rgba(255, 255, 255, .08);
    --ui-accent: #f2b705;
}

:root[data-theme="light"] {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --card: #f8fafc;
    --muted: #6b7280;
    --text: #1f2937;
    --ok: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;
    --primary: #2563eb;
    --border: #d7dee8;
    --input: #ffffff;
    --input-b: #cbd5e1;
    --chip: #eef2f7;
    --chip-b: #d7dee8;
    --header-bg: #f8fafc;
    --header-border: #d7dee8;
    --header-text: #1f2937;
    --shadow: 0 10px 20px rgba(15, 23, 42, .08);
    --focus: 0 0 0 3px rgba(37, 99, 235, .18);
    --hc-bg: #eef2f7;
    --hc-fg: #1f2937;
    --hc-border: #d7dee8;
    --hc-hover: #e9eef4;
    --hc-focus: rgba(37, 99, 235, .35);
    --btn-bg: #111827;
    --btn-fg: #ffffff;
    --btn-border: #0f172a;
    --btn-hover: #0f172a;
    --btn-shadow: 0 1px 2px rgba(15, 23, 42, .16), 0 6px 12px rgba(15, 23, 42, .12);
    --btn-ghost-fg: #1f2937;
    --btn-ghost-border: #cbd5e1;
    --btn-ghost-hover: #e5edf7;
    --ui-accent: #f2b705;
}

:root[data-theme="light"] svg {
    stroke: #000;
}

:root[data-theme="light"] svg path[fill="currentColor"] {
    fill: #000;
}

* {
    box-sizing: border-box
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.55 "Montserrat", "Roboto", sans-serif;
}

:root[data-theme="light"] body {
    background: #e6ebf2;
}

/* ===== Skeleton (configuracion) ===== */
:root {
    --cfg-sk-base: #1a2030;
    --cfg-sk-hi: #222a3b;
}
:root[data-theme="light"] {
    --cfg-sk-base: #e2e8f0;
    --cfg-sk-hi: #f1f5f9;
}

.cfg-skeleton {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg);
    display: block;
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    overflow: auto;
}

.cfg-skeleton-inner {
    width: 100%;
    padding: 0 0 32px;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 12px;
}

.cfg-sk-head {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 6px 12px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    box-shadow: 0 8px 18px rgba(0, 0, 0, .2);
}

.cfg-sk-tabs,
.cfg-sk-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cfg-sk-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.cfg-sk-main {
    margin-top: 16px;
    padding: 0 22px;
}

.cfg-sk-title,
.cfg-sk-tab,
.cfg-sk-btn,
.cfg-sk-field,
.cfg-sk-cell,
.cfg-sk-foot {
    background: linear-gradient(90deg, var(--cfg-sk-base) 25%, var(--cfg-sk-hi) 37%, var(--cfg-sk-base) 63%);
    background-size: 400% 100%;
    animation: skel 1.2s ease-in-out infinite;
    border-radius: 8px;
}

.cfg-sk-title { width: 160px; height: 18px; margin-bottom: 12px; }
.cfg-sk-tab { width: 120px; height: 28px; border-radius: 999px; }
.cfg-sk-tab.sm { width: 90px; }
.cfg-sk-btn { width: 120px; height: 34px; }
.cfg-sk-btn.lg { width: 150px; }
.cfg-sk-field { height: 36px; width: 160px; }
.cfg-sk-field.wide { width: 260px; }
.cfg-sk-foot { height: 18px; width: 140px; margin-top: 12px; }

.cfg-sk-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    margin-bottom: 12px;
    padding: 10px 12px;
}
.cfg-sk-spacer {
    flex: 1 1 auto;
    min-width: 12px;
}

.cfg-sk-table {
    display: grid;
    gap: 8px;
}
.cfg-sk-row {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 160px 220px 120px 120px;
    gap: 10px;
    align-items: center;
    min-height: 52px;
}
.cfg-sk-row.head .cfg-sk-cell {
    height: 14px;
}
.cfg-sk-cell { height: 18px; width: 100%; }
.cfg-sk-cell.wide { width: 100%; }
.cfg-sk-cell.md { width: 100%; }
.cfg-sk-cell.lg { width: 100%; }
.cfg-sk-cell.sm { width: 100%; }

html[data-config-ready="1"] .cfg-skeleton {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility 0s linear .2s;
}
html:not([data-config-ready="1"]) .wrap,
html:not([data-config-ready="1"]) header {
    opacity: 0;
    pointer-events: none;
}
html[data-config-ready="1"] .wrap,
html[data-config-ready="1"] header {
    opacity: 1;
    transition: opacity .2s ease;
}

header {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 6px 12px;
    background: var(--header-bg);
    color: var(--header-text);
    border-bottom: 1px solid var(--header-border);
    box-shadow: 0 8px 18px rgba(0, 0, 0, .2);
}


header .title {
    font-weight: 800;
    letter-spacing: .3px;
    font-size: 16px;
}

header .page-title {
    display: none;
}
header .controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: flex-start;
}
.header-tabs.toolbar {
    padding: 6px;
    background: transparent;
    border: none;
    box-shadow: none;
}
.header-tabs .tab-btn {
    height: var(--btn-h);
    padding: 0 var(--btn-pad-x);
    font-size: 13px;
    letter-spacing: .2px;
    border-radius: 999px;
}

.hdr-controls button,
.hdr-controls .btn {
    height: var(--btn-h);
    padding: 0 var(--btn-pad-x);
    border-radius: var(--btn-radius);
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: 1px solid var(--btn-border);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--btn-shadow);
    transition: background .12s ease, box-shadow .12s ease, border-color .12s ease, color .12s ease, transform .04s ease;
}

.hdr-controls button:hover,
.hdr-controls .btn:hover {
    background: var(--btn-hover);
}
.hdr-controls button:active,
.hdr-controls .btn:active {
    transform: translateY(1px);
    box-shadow: none;
}
.hdr-controls button:focus-visible,
.hdr-controls .btn:focus-visible {
    outline: 2px solid var(--hc-focus);
    outline-offset: 2px;
}
.hdr-controls select {
    height: var(--btn-h);
    padding: 0 36px 0 12px;
    border-radius: var(--btn-radius);
    background: var(--hc-bg);
    color: var(--hc-fg);
    border: 1px solid var(--hc-border);
    font: inherit;
    font-weight: 600;
}
.hdr-controls select:hover {
    background: var(--hc-hover);
}

.btn {
    height: var(--btn-h);
    padding: 0 var(--btn-pad-x);
    border-radius: var(--btn-radius);
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: 1px solid var(--btn-border);
    cursor: pointer;
    font-weight: 600;
    box-shadow: var(--btn-shadow);
    transition: background .12s ease, box-shadow .12s ease, border-color .12s ease, color .12s ease, transform .04s ease;
}

.btn:hover {
    background: var(--btn-hover);
}
.btn:active {
    transform: translateY(1px);
    box-shadow: none;
}

.btn.ok {
    background: var(--ok);
    border-color: rgba(0, 0, 0, .15);
    color: #0b1210
}

.btn.primary {
    background: var(--primary);
    border-color: rgba(0, 0, 0, .15);
    color: #f8fafc;
}

.btn.ghost {
    background: transparent;
    border-color: var(--btn-ghost-border);
    color: var(--btn-ghost-fg);
    box-shadow: none;
}
.btn.ghost:hover {
    background: var(--btn-ghost-hover);
}

.btn.danger {
    background: var(--danger);
    border-color: rgba(0, 0, 0, .15);
    color: #fff;
}

.wrap {
    max-width: none;
    width: 100%;
    margin: 16px 0 36px;
    padding: 0 22px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px
}

.wrap > .card:first-child {
    width: 100%;
    max-width: none;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.card h3 {
    margin: 0 0 12px;
    font-size: 15px;
    letter-spacing: .4px;
    font-weight: 800;
}

.row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap
}

.row .grow {
    flex: 1 1 auto
}

.input, select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--input-b);
    background: var(--input);
    color: var(--text);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    font-family: "Montserrat", "Roboto", sans-serif;
}

.input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: var(--focus);
}
.input::placeholder {
    color: var(--muted);
}

.muted {
    color: var(--muted)
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 6px;
    table-layout: fixed;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
}

.table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.table th {
    font-weight: 600;
    text-align: left;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: .6px;
    text-transform: uppercase;
    padding: 8px 12px 12px
}

.table tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.table tbody tr:hover {
    background: rgba(255, 255, 255, .04);
    border-color: rgba(255, 255, 255, .16);
    transform: translateY(-1px);
}

.table td {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border)
}

.table th, .table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#tblUsers th:nth-child(1), #tblUsers td:nth-child(1) {
    width: 34%;
}

#tblUsers th:nth-child(2), #tblUsers td:nth-child(2) {
    width: 14%;
}

#tblUsers th:nth-child(3), #tblUsers td:nth-child(3) {
    width: 26%;
}

#tblUsers th:nth-child(4), #tblUsers td:nth-child(4) {
    width: 12%;
}

#tblUsers th:nth-child(5), #tblUsers td:nth-child(5) {
    width: 14%;
}

.table tr td:first-child {
    border-left: 1px solid var(--border);
    border-radius: 10px 0 0 10px
}

.table tr td:last-child {
    border-right: 1px solid var(--border);
    border-radius: 0 10px 10px 0
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--chip);
    border: 1px solid var(--chip-b);
    font-size: 12px
}

.pill {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%
}

.pill.green {
    background: var(--ok)
}

.pill.red {
    background: var(--danger)
}

.pill.blue {
    background: var(--primary)
}

.right {
    display: flex;
    gap: 8px;
    justify-content: flex-end
}

.help {
    font-size: 12px;
    margin-top: -6px;
    margin-bottom: 8px;
    color: var(--muted)
}

.sep {
    height: 1px;
    background: var(--border);
    margin: 10px 0
}

.hint {
    font-size: 12px;
    color: var(--muted)
}

.k {
    color: var(--muted);
    font-size: 12px
}

/* Mini modal */
.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: none;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1200
}

.backdrop.show {
    display: flex
}

.modal {
    width: min(520px, 92vw);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    box-shadow: var(--shadow);
}

.modal .head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px
}

.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
    flex-wrap: nowrap;
    padding: 10px 12px;
    border-radius: 12px;
    background: transparent;
    border: none;
    overflow-x: auto;
    box-shadow: none;
}

.toolbar .spacer {
    flex: 1
}

.toolbar .input, .toolbar select, .toolbar .btn {
    flex: 0 0 auto;
}

.toolbar .input, .toolbar select {
    min-width: 140px;
    width: auto;
    max-width: 240px;
}

.toolbar .input.search {
    flex: 1 1 260px;
    min-width: 200px;
}

.toolbar select {
    min-width: 140px;
}
.toolbar #q {
    flex: 1 1 220px;
    min-width: 180px;
    max-width: 320px;
}
.toolbar #filterRole,
.toolbar #filterActive {
    min-width: 120px;
}

.toolbar::-webkit-scrollbar {
    height: 6px;
}

.toolbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .12);
    border-radius: 999px;
}

.inline {
    display: flex;
    gap: 8px;
    align-items: center
}

.danger-link {
    color: #ff809d;
    cursor: pointer
}

.danger-link:hover {
    text-decoration: underline
}

.fake-btn {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px dashed var(--border);
    background: #141925;
    cursor: pointer
}

.badge {
    font-weight: 700;
    font-size: 12px;
    background: #24304a;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid #2e3c59
}

.btn.sm {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(140deg, #f59e0b, #fbbf24);
    border: 1px solid rgba(245, 158, 11, .35);
    font-weight: 800;
    color: #111827;
    letter-spacing: .4px;
    flex: 0 0 auto;
    box-shadow: 0 6px 14px rgba(245, 158, 11, .25);
}

.user-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.user-meta .name {
    font-weight: 700;
}

.user-meta .sub {
    color: var(--muted);
    font-size: 12px;
}

.cell-right {
    text-align: right;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .wrap {
        grid-template-columns: 1fr 360px
    }
}

@media (max-width: 992px) {
    .wrap {
        grid-template-columns: 1fr
    }

    #formCard {
        order: -1;
        margin-bottom: 18px
    }
}

@media (max-width: 720px) {
    header {
        position: fixed;
        width: 100%;
        left: 0;
        right: 0;
    }
    main {
        padding-top: calc(var(--hdr-h, 88px) + 8px);
    }

    header {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    header .controls {
        width: 100%;
        justify-content: flex-start;
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .header-tabs.toolbar {
        width: 100%;
    }

    .wrap {
        padding: 0 12px;
        margin-top: 153px;
    }

    .card {
        padding: 14px
    }

    .toolbar {
        gap: 6px
    }

    .btn {
        padding: 10px 12px
    }

    .input, select {
        padding: 12px
    }
}

@media (max-width: 640px) {
    header .controls {
        flex-wrap: wrap;
        gap: 8px;
    }
    .header-tabs.toolbar {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }
    .header-tabs.toolbar::-webkit-scrollbar {
        display: none;
    }
    .toolbar {
        flex-wrap: wrap;
        gap: 8px;
    }
    .toolbar .input,
    .toolbar select,
    .toolbar .btn {
        flex: 1 1 100%;
        max-width: none;
    }
    .toolbar .spacer {
        display: none;
    }
    .perm-toolbar .spacer {
        display: none;
    }
    .perm-pagination {
        flex-direction: column;
        align-items: stretch;
    }
    .perm-pagination .btn,
    .perm-pagination .input {
        width: 100%;
        max-width: none;
    }
    .claims-grid > div {
        min-height: auto;
    }
    .drawer {
        border-radius: 0;
    }
}

/* Botones full-width en móviles cuando tenga sentido */
@media (max-width: 480px) {
    .toolbar .spacer {
        display: none
    }

    .right {
        flex-wrap: wrap
    }

    .right .btn {
        flex: 1 1 48%
    }

    header .controls .btn {
        width: 100%;
    }

    .header-tabs .tab-btn {
        flex: 1 1 auto;
        width: auto;
        text-align: center;
    }
}

/* Tabla -> Cards en móviles */
@media (max-width: 768px) {
    .table th, .table td {
        white-space: normal;
        text-overflow: unset;
    }

    .user-cell {
        align-items: flex-start;
    }

    .user-meta .name,
    .user-meta .sub {
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }

    .table {
        border-spacing: 0 12px
    }

    .table thead {
        display: none
    }

    .table tbody tr {
        display: block;
        padding: 12px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--panel);
        position: relative;
    }

    .table tbody tr + tr {
        margin-top: 12px
    }

    .table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        padding: 8px 0;
        border: none;
        font-size: 14px;
        white-space: normal;
        overflow: visible;
    }

    #tblUsers tbody td {
        gap: 10px;
    }

    #tblUsers tbody td:first-child {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    #tblUsers tbody td:first-child {
        padding-right: 88px;
    }

    #tblUsers .user-cell {
        width: 100%;
        gap: 10px;
    }

    #tblUsers .user-avatar {
        width: 34px;
        height: 34px;
        font-size: 13px;
    }

    #tblUsers .cell-right {
        width: 100%;
        justify-content: flex-end;
    }

    #tblUsers .cell-right .btn {
        width: auto;
    }

    #tblUsers tbody td {
        padding: 6px 0;
    }

    #tblUsers tbody tr {
        padding: 10px;
    }

    #tblUsers tbody td:last-child {
        position: absolute;
        right: 12px;
        top: 12px;
        padding: 0;
        border: none;
    }

    #tblUsers tbody td:last-child::before {
        display: none;
    }

    .table tbody td:first-child {
        border-left: none;
        border-radius: 0
    }

    .table tbody td:last-child {
        border-right: none;
        border-radius: 0
    }

    /* Etiquetas por columna */
    #tblUsers tbody td:nth-child(1)::before {
        content: 'Usuario';
        color: var(--muted);
        margin-right: 10px
    }

    #tblUsers tbody td:nth-child(2)::before {
        content: 'Rol';
        color: var(--muted);
        margin-right: 10px
    }

    #tblUsers tbody td:nth-child(3)::before {
        content: 'Técnico';
        color: var(--muted);
        margin-right: 10px
    }

    #tblUsers tbody td:nth-child(4)::before {
        content: 'Estado';
        color: var(--muted);
        margin-right: 10px
    }

    #tblUsers tbody td:nth-child(5)::before {
        content: 'Acciones';
        color: var(--muted);
        margin-right: 10px
    }

    #permTable tbody td:nth-child(1)::before {
        content: 'Codigo';
        color: var(--muted);
        margin-right: 10px
    }

    #permTable tbody td:nth-child(2)::before {
        content: 'Etiqueta';
        color: var(--muted);
        margin-right: 10px
    }

    #permTable tbody td:nth-child(3)::before {
        content: 'Acciones';
        color: var(--muted);
        margin-right: 10px
    }

    /* Acciones eliminadas */
}

@media (max-width: 480px) {
    .modal {
        width: 92vw;
        padding: 12px
    }

    .fake-btn {
        width: 100%;
        text-align: center;
        padding: 10px
    }
}

@media (max-width: 480px) {
    .input, select {
        font-size: 16px
    }

    /* evita zoom en iOS */
    .btn {
        min-height: 44px
    }
}

/* Accesibilidad: foco visible coherente */
:focus-visible {
    outline: 2px solid #7aa2ff;
    outline-offset: 2px;
    border-radius: 8px;
}

.btn:focus-visible {
    outline-color: #ffc400;
}

.input:disabled, select:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* Estado cargando y vacío */
.skeleton {
    background: linear-gradient(90deg, #1a2030 25%, #222a3b 37%, #1a2030 63%);
    background-size: 400% 100%;
    animation: skel 1.2s ease-in-out infinite;
    border-radius: 8px;
    height: 36px;
}

@keyframes skel {
    0% {
        background-position: 100% 0
    }
    100% {
        background-position: 0 0
    }
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 18px 8px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: rgba(18, 22, 34, .8);
}

/* Botón icono */
.btn.icon {
    padding: 8px;
    width: 36px;
    text-align: center
}

/* Icon-only buttons: avoid inherited spacing from global icon styles */
.btn.icon .icon-ico,
.drawer-section-toggle .icon-ico,
.user-perm-toggle .icon-ico {
    margin-right: 0;
    display: block;
    width: 16px;
    height: 16px;
}

/* Modal accesible */
.backdrop[aria-hidden="false"] {
    display: flex
}

.modal {
    outline: 0
}

.btn.warn {
    background: var(--warn);
    border-color: #e0a800;
    color: #1a1600;
}

:root[data-theme="light"] header {
    box-shadow: 0 8px 18px rgba(15, 23, 42, .08);
}


:root[data-theme="light"] .btn.ok {
    background: #16a34a;
    border-color: #15803d;
    color: #fff;
}

:root[data-theme="light"] .btn.danger {
    background: #dc2626;
    border-color: #b91c1c;
    color: #fff;
}

:root[data-theme="light"] .btn.warn {
    background: #f59e0b;
    border-color: #d97706;
    color: #1a1600;
}

:root[data-theme="light"] .table tr {
    background: #ffffff;
    border-color: #e2e8f0;
}

:root[data-theme="light"] .table tbody tr:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

:root[data-theme="light"] .toolbar {
    background: transparent;
}

:root[data-theme="light"] .drawer-backdrop {
    background: rgba(15, 23, 42, .2);
}


:root[data-theme="light"] .badge {
    background: #eef2f7;
    border-color: #d7dee8;
    color: #1f2937;
}

:root[data-theme="light"] .empty {
    background: #f8fafc;
    border-color: #d7dee8;
}

.btn:disabled {
    opacity: .6;
    cursor: not-allowed;
    transform: none;
}

.tab-btn {
    border-radius: 999px;
    padding: 6px 14px;
    font-weight: 600;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    color: var(--btn-fg);
    box-shadow: var(--btn-shadow);
    transition: background .12s ease, box-shadow .12s ease, border-color .12s ease, color .12s ease, transform .04s ease;
}

.tab-btn.is-active {
    background: var(--btn-hover);
    border-color: var(--btn-border);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, .25), inset 0px 0px 0 2px var(--ui-accent);
}
.tab-btn:hover:not(.is-active) {
    background: var(--btn-hover);
    border-color: var(--btn-border);
    transform: translateY(-1px);
}

:root[data-theme="light"] .tab-btn,
:root[data-theme="light"] .tab-btn:hover:not(.is-active),
:root[data-theme="light"] .tab-btn.is-active {
    background: #111827;
    border-color: #0f172a;
    color: #ffffff;
}

.tab-panel {
    display: none;
}

.tab-panel.is-active {
    display: block;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(9, 11, 16, .55);
    backdrop-filter: none;
    display: none;
    z-index: 1100;
}

.drawer-backdrop.show {
    display: block;
}

.drawer {
    position: fixed;
    top: 0;
    right: -440px;
    width: 440px;
    height: 100vh;
    z-index: 1200;
    padding: 24px 20px 28px;
    background: var(--card);
    overflow: auto;
    border-left: 1px solid var(--border);
    box-shadow: none;
    transition: right .2s ease;
    border-radius: 16px 0 0 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drawer.is-open {
    right: 0;
    box-shadow: -6px 0 16px rgba(0, 0, 0, .22);
}

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.drawer-head .btn.icon {
    width: 34px;
    height: 34px;
    padding: 0;
}

.drawer-title h3 {
    margin: 0;
}

.drawer-sub {
    font-size: 12px;
    color: var(--muted);
}

.drawer-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drawer-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}

.is-hidden {
    display: none !important;
}

.drawer-section-head {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.drawer-section-head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-right: 12px;
}

.drawer-section-toggle {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0;
}

.user-perm-toggle {
    margin-right: 0;
}

.drawer-section.is-collapsed .drawer-section-body {
    display: none;
}

.drawer-section.is-collapsed .drawer-section-toggle svg {
    transform: rotate(-90deg);
}

.drawer-section-toggle svg {
    transition: transform .15s ease;
}

.drawer-section-head h4 {
    margin: 0;
    font-size: 12px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
}

.tech-field {
    position: relative;
}

.tech-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 220px;
    overflow: auto;
    z-index: 5;
}

.tech-option {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.tech-option:last-child {
    border-bottom: none;
}

.tech-option:hover,
.tech-option.is-active {
    background: var(--btn-hover);
}

:root[data-theme="light"] .tech-option:hover,
:root[data-theme="light"] .tech-option.is-active {
    background: #111827;
    color: #ffffff;
}

.user-perm-picker {
    position: relative;
}
.user-perm-picker .input {
    padding-right: 48px;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    max-height: 260px;
    overflow: auto;
    z-index: 6;
}

.user-dropdown.is-hidden {
    display: none;
}

.user-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.user-option:last-child {
    border-bottom: none;
}

.user-option:hover,
.user-option.is-active {
    background: var(--btn-hover);
}

:root[data-theme="light"] .user-option:hover,
:root[data-theme="light"] .user-option.is-active {
    background: #0f172a;
    color: #ffffff;
}
:root[data-theme="light"] .user-option:hover .sub,
:root[data-theme="light"] .user-option.is-active .sub {
    color: rgba(255, 255, 255, .8);
}
:root[data-theme="light"] .user-option:hover .chip,
:root[data-theme="light"] .user-option.is-active .chip {
    color: #000000;
}

.user-option .avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(140deg, #f59e0b, #fbbf24);
    border: 1px solid rgba(245, 158, 11, .35);
    font-weight: 700;
    color: #0f172a;
    font-size: 12px;
    flex: 0 0 auto;
}

.user-option .meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.user-option .meta .name {
    font-weight: 700;
    line-height: 1.1;
}

.user-option .meta .sub {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.user-option .badges {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.user-option .mini {
    padding: 2px 6px;
    font-size: 11px;
}

.user-perm-toggle {
    position: absolute;
    right: 12px;
    top: 6px;
    transform: none;
    width: 36px;
    height: 36px;
    padding: 0;
    z-index: 2;
    border: none;
    box-shadow: none;
    background: transparent;
    margin-top: -3px;
}
.user-perm-toggle:hover,
.user-perm-toggle.btn:hover,
.user-perm-toggle.btn.ghost:hover {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}
.user-perm-toggle:active {
    transform: none;
    box-shadow: none;
}
.user-perm-toggle svg {
    transition: transform .15s ease;
}
.user-perm-picker.is-open .user-perm-toggle svg {
    transform: rotate(180deg);
}

.btn.icon-left {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn.icon-left svg {
    flex: 0 0 auto;
    color: inherit;
}

.pwd-gen-ico {
    color: #ffffff;
    width: 14px;
    height: 14px;
}
:root[data-theme="light"] .pwd-gen-ico {
    color: #ffffff;
}
:root[data-theme="light"] .pwd-gen-ico path {
    fill: #ffffff;
}
:root[data-theme="light"] .drawer .pwd-gen-ico,
:root[data-theme="light"] .drawer .pwd-gen-ico path {
    color: #ffffff;
    fill: #ffffff;
}

.drawer-section .row:last-child {
    margin-bottom: 0;
}

.drawer-section-body .row {
    margin-bottom: 14px;
}
.drawer-section-body .row:last-child {
    margin-bottom: 0;
}

.perm-list.compact {
    max-height: 520px;
    padding: 8px;
}


.perm-override-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.perm-override-row:last-child {
    border-bottom: none;
}

.perm-override-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.perm-override-label .code {
    font-size: 11px;
    color: var(--muted);
}

.perm-select {
    min-width: 110px;
    max-width: 130px;
}

.drawer-actions {
    position: sticky;
    bottom: 0;
    padding-top: 12px;
    padding-bottom: 12px;
    margin-top: 4px;
    background-color: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 2;
}

.drawer-actions .btn {
    min-height: 40px;
}

.claims-grid .btn.ok {
    min-width: 160px;
    height: 36px;
}

.claims-col-right .row {
    flex-wrap: nowrap;
    align-items: center;
}

.claims-col-right .row .grow {
    min-width: 0;
}

.drawer-actions .btn.primary {
    padding: 0 18px;
    box-shadow: 0 10px 20px rgba(37, 99, 235, .22);
}

.drawer-actions .btn.warn,
.drawer-actions .btn.danger {
    opacity: .95;
}

.drawer-actions .btn.warn:hover,
.drawer-actions .btn.danger:hover {
    opacity: 1;
}

.drawer-actions .btn.warn {
    color: #ffffff;
}

:root[data-theme="light"] .drawer-actions .btn.warn {
    color: #ffffff;
}

@media (max-width: 720px) {
    .drawer {
        width: 100%;
        right: -100%;
    }
}

.span-2 {
    grid-column: 1 / -1;
}

.claims-grid {
    display: grid;
    grid-template-columns: minmax(520px, 1fr) minmax(520px, 1fr);
    gap: 12px;
    align-items: stretch;
}
.claims-grid > div {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-height: 560px;
}

.claims-col-left,
.claims-col-right {
    min-height: 620px;
}

.perm-list {
    max-height: 520px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    background: var(--card);
    flex: 1 1 auto;
}

.perm-create-wrap {
    display: none;
}

@media (min-width: 1024px) {
    .perm-list {
        max-height: 520px;
    }
}

.perm-group {
    margin-bottom: 12px;
}

.perm-group h4 {
    margin: 6px 0 8px;
    font-size: 11px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
}

.perm-item {
    display: grid;
    grid-template-columns: 20px 1fr;
    gap: 8px;
    padding: 6px 6px;
    border-radius: 8px;
}

.perm-item:hover {
    background: rgba(255, 255, 255, .03);
}

.perm-label {
    font-weight: 600;
}

.perm-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    color: var(--muted);
}

.perm-hint {
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.perm-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.perm-pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 10px;
    flex-wrap: wrap;
}
.claims-grid .table-wrap {
    flex: 1 1 auto;
}
.claims-grid > div:last-child .toolbar .spacer {
    flex: 1;
}
.claims-grid > div:last-child .toolbar .btn.primary {
    margin-left: auto;
}
.perm-pagination .input {
    min-width: 80px;
    max-width: 100px;
}

@media (max-width: 992px) {
    .claims-grid {
        grid-template-columns: 1fr;
    }
    .claims-grid > div {
        padding: 10px;
    }
    .claims-col-left,
    .claims-col-right {
        min-height: auto;
    }
    .perm-list {
        max-height: 360px;
    }
    .perm-list.compact {
        max-height: 360px;
    }
    .claims-grid .toolbar {
        gap: 6px;
    }
    .claims-grid .toolbar .input,
    .claims-grid .toolbar select {
        min-width: 160px;
    }

    .perm-toolbar {
        flex-wrap: wrap;
    }
    .perm-toolbar #permRole {
        flex: 0 0 180px;
        order: 1;
    }
    .perm-toolbar .spacer {
        flex-basis: 100%;
        width: 100%;
        height: 0;
        order: 3;
    }
    .perm-toolbar #permReload {
        order: 2;
    }
    .perm-toolbar #permSave {
        order: 4;
        margin-left: auto;
    }

    .claims-col-right .row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .claims-col-right .row .btn.ok {
        width: 100%;
    }
}

@media (max-width: 1200px) {
    .claims-grid {
        grid-template-columns: minmax(360px, 1.1fr) minmax(300px, .9fr);
    }
}
