:root {
    --bg: #f6f7f3;
    --surface: #ffffff;
    --surface-soft: #eef4ed;
    --text: #1e2924;
    --muted: #66736d;
    --line: #dbe2dc;
    --primary: #2f6f5e;
    --primary-dark: #25594c;
    --danger: #b42318;
    --danger-bg: #fff0ee;
    --success: #287045;
    --success-bg: #ecf8f0;
    --warning-bg: #fff7e8;
    --radius: 8px;
    --shadow: 0 12px 35px rgba(31, 41, 36, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

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

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

.app-shell.sidebar-collapsed {
    grid-template-columns: 82px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 74px);
    padding: 18px;
    background: #17231f;
    color: #f7fbf8;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 18px;
}

.sidebar-toggle {
    display: inline-grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

.sidebar-toggle span,
.sidebar-toggle span::before,
.sidebar-toggle span::after {
    display: block;
    width: 14px;
    height: 2px;
    background: #f7fbf8;
    content: "";
}

.sidebar-toggle span::before {
    transform: translateY(-5px);
}

.sidebar-toggle span::after {
    transform: translateY(3px);
}

.main-shell {
    display: flex;
    min-width: 0;
    min-height: calc(100vh - 74px);
    flex-direction: column;
}

.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 74px;
    padding: 14px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    min-width: 0;
    color: var(--text);
    font-size: 19px;
    font-weight: 700;
}

.brand small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.app-shell.sidebar-collapsed .sidebar {
    padding-inline: 14px;
}

.app-shell.sidebar-collapsed .sidebar-head {
    align-items: center;
    justify-content: center;
}

.app-shell.sidebar-collapsed .nav-text {
    display: none;
}

.app-shell.sidebar-collapsed .side-nav a {
    justify-content: center;
    padding-inline: 8px;
}

.app-shell.sidebar-collapsed .side-group-toggle {
    justify-content: center;
    padding-inline: 8px;
}

.app-shell.sidebar-collapsed .nav-caret,
.app-shell.sidebar-collapsed .side-subnav {
    display: none;
}

.side-nav {
    display: grid;
    gap: 6px;
}

.side-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #c9d8d1;
    font-weight: 700;
}

.side-nav a:hover,
.side-nav a.active,
.side-group-toggle:hover,
.side-group.open .side-group-toggle {
    background: #243832;
    color: #fff;
}

.side-group {
    display: grid;
    gap: 4px;
}

.side-group-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    gap: 12px;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #c9d8d1;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-align: left;
}

.nav-caret {
    margin-left: auto;
    transition: transform 0.18s ease;
}

.side-group.open .nav-caret {
    transform: rotate(90deg);
}

.side-subnav {
    display: none;
    gap: 3px;
    padding-left: 40px;
}

.side-group.open .side-subnav {
    display: grid;
}

.side-subnav a {
    min-height: 34px;
    padding: 7px 10px;
    color: #b6c9c0;
    font-size: 14px;
}

.nav-icon {
    display: inline-grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
}

.nav-icon svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.page {
    width: calc(100% - 32px);
    max-width: 1280px;
    flex: 1;
    margin: 28px auto;
}

.page-auth {
    min-height: calc(100vh - 74px);
}

.auth-shell {
    display: grid;
    min-height: calc(100vh - 110px);
    place-items: center;
}

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

.auth-panel {
    width: min(440px, 100%);
    padding: 32px;
}

.panel {
    padding: 28px;
}

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

.topbar-label {
    margin: 0 0 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.topbar-section {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 22px;
    min-width: 0;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 14px;
}

.footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 28px;
    color: var(--muted);
    font-size: 13px;
    border-top: 1px solid var(--line);
    background: #fff;
}

h1 {
    margin: 0 0 8px;
    font-size: 30px;
    line-height: 1.2;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

.form {
    display: grid;
    gap: 14px;
}

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

.form-full {
    grid-column: 1 / -1;
}

.compact {
    margin-bottom: 0;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.check-option {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
}

.check-option input {
    width: auto;
    min-height: auto;
}

label {
    display: block;
    margin-bottom: 6px;
    color: #34423b;
    font-size: 14px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid #cfd8d1;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(47, 111, 94, 0.16);
}

textarea {
    resize: vertical;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    white-space: nowrap;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.button-primary {
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-dark);
}

.button-secondary {
    background: #fff;
    border-color: var(--line);
    color: var(--text);
}

.button-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.actions,
.form-actions {
    display: flex;
    gap: 10px;
}

.form-actions {
    align-items: end;
}

.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.alert-hide {
    opacity: 0;
    transform: translateY(-4px);
}

.alert-close {
    display: inline-grid;
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
    place-items: center;
    border: 0;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.06);
    color: inherit;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.alert-error {
    background: var(--danger-bg);
    border-color: #ffd0ca;
    color: var(--danger);
}

.alert-success {
    background: var(--success-bg);
    border-color: #c9ebd3;
    color: var(--success);
}

.filter-card {
    margin-bottom: 16px;
    padding: 18px;
}

.users-filter {
    display: grid;
    align-items: end;
    grid-template-columns: minmax(260px, 1fr) 150px 150px 120px auto;
    gap: 14px;
}

.search-field input {
    padding-left: 14px;
}

.filter-actions {
    display: flex;
    gap: 8px;
}

.filter-summary {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.table-card {
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

th,
td {
    padding: 13px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.users-table th:nth-child(1) {
    width: 30%;
}

.users-table th:nth-child(2) {
    width: 10%;
}

.users-table th:nth-child(3) {
    width: 13%;
}

.users-table th:nth-child(4) {
    width: 11%;
}

.users-table th:nth-child(5),
.users-table th:nth-child(6) {
    width: 11%;
}

.users-table th:nth-child(7) {
    width: 14%;
}

.users-table td strong,
.table-muted {
    display: block;
}

.table-muted {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.membership-list {
    display: grid;
    gap: 3px;
    color: #3f4c46;
    font-size: 12px;
    font-weight: 700;
}

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

.text-right {
    text-align: right;
}

.actions-cell {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.actions-cell form {
    margin: 0;
}

.icon-button {
    display: inline-grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: #3f4c46;
    cursor: pointer;
}

.icon-button:hover {
    border-color: #b9c8c0;
    background: var(--surface-soft);
}

.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.icon-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.icon-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.icon-warning {
    background: var(--warning-bg);
    color: #8a5a00;
}

.icon-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge,
.status {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge {
    background: #edf2f7;
    color: #3d4b59;
}

.status-activo {
    background: var(--success-bg);
    color: var(--success);
}

.status-inactivo {
    background: var(--warning-bg);
    color: #8a5a00;
}

.empty {
    padding: 28px;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 720px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        min-height: auto;
        padding: 16px;
    }

    .sidebar-head {
        margin-bottom: 14px;
    }

    .app-shell.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .app-shell.sidebar-collapsed .nav-text {
        display: block;
    }

    .app-shell.sidebar-collapsed .nav-caret {
        display: inline;
    }

    .app-shell.sidebar-collapsed .side-subnav {
        display: none;
    }

    .app-shell.sidebar-collapsed .side-group.open .side-subnav {
        display: grid;
    }

    .app-shell.sidebar-collapsed .sidebar-head {
        align-items: center;
        flex-direction: row;
    }

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

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

    .user-menu {
        flex-wrap: wrap;
    }

    .page {
        margin: 20px auto;
    }

    .auth-panel,
    .panel {
        padding: 22px;
    }

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

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

    .users-filter {
        grid-template-columns: 1fr;
    }

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

    .footer {
        flex-direction: column;
    }

    .table-card {
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
    }

    table {
        table-layout: auto;
    }

    thead {
        display: none;
    }

    tr {
        margin-bottom: 12px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: #fff;
        box-shadow: var(--shadow);
        overflow: hidden;
    }

    td {
        display: flex;
        justify-content: space-between;
        gap: 14px;
        padding: 12px 14px;
    }

    td::before {
        color: var(--muted);
        content: attr(data-label);
        flex: 0 0 110px;
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
    }

    .actions-cell {
        justify-content: space-between;
    }
}
