:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #1f2933;
    --muted: #617084;
    --line: #d8dee6;
    --soft-line: #e7ebf0;
    --soft-panel: #f8fafc;
    --primary: #094963;
    --accent: #B0A50F;
    --menu-bg: #083445;
    --menu-active: #0A5E86;
    --danger: #b42318;
    --success: #1f7a4d;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: var(--accent);
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    border-radius: 6px;
    background: var(--primary);
    color: #ffffff;
    cursor: pointer;
    font-weight: 700;
    padding: 0.65rem 0.95rem;
    transition: background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.button-link {
    background: var(--primary);
    border-radius: 6px;
    color: #ffffff;
    display: inline-block;
    font-weight: 700;
    padding: 0.65rem 0.95rem;
    text-decoration: none;
    transition: background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:hover,
.button-link:hover {
    box-shadow: 0 6px 16px rgba(9, 73, 99, 0.18);
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.button-secondary {
    background: var(--accent);
    color: #ffffff;
}

.new-user-button {
    background: #1CC885;
}

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

label {
    display: grid;
    gap: 0.35rem;
    color: var(--muted);
    font-weight: 600;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    padding: 0.7rem 0.8rem;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(9, 73, 99, 0.12);
    outline: none;
}

input::placeholder {
    color: #b9c1ca;
    opacity: 1;
}

.password-field {
    display: block;
    position: relative;
}

.password-field input {
    padding-right: 3rem;
}

.password-toggle {
    align-items: center;
    background: transparent;
    color: var(--primary);
    display: inline-flex;
    height: 2.4rem;
    justify-content: center;
    padding: 0;
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2.4rem;
}

.password-toggle:hover {
    filter: none;
}

.password-toggle svg {
    fill: none;
    height: 1.2rem;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    width: 1.2rem;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-box {
    width: min(100%, 420px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 2rem;
}

.auth-logo {
    display: block;
    height: auto;
    margin: 0 auto 1.5rem;
    max-width: 260px;
    width: 80%;
}

.auth-link {
    display: block;
    margin-top: 1.25rem;
    text-align: center;
}

.auth-box form,
#user-form,
#role-form,
#menu-form {
    display: grid;
    gap: 1rem;
}

#user-form,
#role-form,
#menu-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

#user-form input[type="hidden"],
#role-form input[type="hidden"],
#menu-form input[type="hidden"],
.form-actions {
    grid-column: 1 / -1;
}

.form-actions,
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.actions {
    flex-wrap: nowrap;
    gap: 0.3rem;
    white-space: nowrap;
}

.icon-button {
    align-items: center;
    display: inline-flex;
    height: 1.9rem;
    justify-content: center;
    padding: 0;
    width: 1.9rem;
}

.icon-button:hover {
    box-shadow: none;
    transform: none;
}

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

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    background: #083445 !important;
    color: #ffffff;
    max-height: 100vh;
    overflow-y: auto;
    padding: 1.5rem 1rem;
}

.brand {
    margin-bottom: 2rem;
}

.brand img {
    display: block;
    height: auto;
    max-width: 180px;
    width: 100%;
}

.sidebar nav {
    display: grid;
    gap: 0.35rem;
}

.submenu {
    display: grid;
    gap: 0.25rem;
}

.submenu > a[data-submenu-toggle] {
    align-items: center;
    display: flex;
    justify-content: space-between;
}

.submenu > a[data-submenu-toggle]::after {
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    content: "";
    height: 0.45rem;
    margin-left: 0.75rem;
    opacity: 0.8;
    transform: rotate(-45deg);
    transition: transform 160ms ease;
    width: 0.45rem;
}

.submenu.open > a[data-submenu-toggle]::after {
    transform: rotate(45deg);
}

.submenu-items {
    border-left: 1px solid rgba(255, 255, 255, 0.18);
    display: grid;
    gap: 0.25rem;
    margin: 0.1rem 0 0.15rem 0.85rem;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding-left: 0.65rem;
    transition: max-height 180ms ease, opacity 160ms ease;
}

.submenu.open .submenu-items {
    max-height: min(60vh, 32rem);
    opacity: 1;
    overflow-y: auto;
}

.submenu-items a {
    border-radius: 5px;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.92;
    padding: 0.5rem 0.65rem;
}

.sidebar a {
    border-radius: 6px;
    color: #ffffff;
    font-weight: 700;
    padding: 0.75rem 0.8rem;
    text-decoration: none;
}

.sidebar a.active {
    background: var(--menu-active);
    color: #ffffff;
}

.sidebar a:hover {
    background: rgba(13, 111, 157, 0.82);
    color: #ffffff;
}

.submenu.open > a[data-submenu-toggle] {
    background: rgba(10, 94, 134, 0.78);
}

.submenu-items a.active {
    background: rgba(28, 200, 133, 0.22);
    box-shadow: inset 3px 0 0 #1CC885;
}

.content {
    margin-left: 240px;
    padding: 2rem;
}

.topbar {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.topbar h1 {
    color: #12212c;
    font-size: 1.75rem;
    letter-spacing: 0;
    margin: 0;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--soft-line);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(31, 41, 51, 0.06);
    margin-bottom: 1.5rem;
    padding: 1.25rem;
}

.panel h2 {
    color: var(--primary);
    font-size: 1.15rem;
    margin-top: 0;
}

.list-header {
    align-items: center;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.list-actions {
    display: flex;
    gap: 0.5rem;
}

.list-header h2 {
    margin-bottom: 0;
}

.search-box {
    margin-bottom: 1rem;
}

.columns-panel {
    background: var(--soft-panel);
    border: 1px solid var(--soft-line);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 1rem;
    padding: 0.65rem;
}

.columns-panel[hidden] {
    display: none;
}

.columns-panel label {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--soft-line);
    border-radius: 6px;
    color: var(--text);
    display: flex;
    flex-direction: row;
    font-size: 0.88rem;
    gap: 0.4rem;
    line-height: 1;
    padding: 0.48rem 0.6rem;
}

.columns-panel input {
    accent-color: var(--primary);
    margin: 0;
    width: auto;
}

.filters-panel {
    background: var(--soft-panel);
    border: 1px solid var(--soft-line);
    border-radius: 8px;
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    margin-bottom: 1rem;
    padding: 0.85rem;
}

.filters-panel[hidden] {
    display: none;
}

.filter-actions {
    align-items: end;
    display: flex;
    gap: 0.5rem;
    grid-column: 1 / -1;
    justify-content: flex-end;
}

.totp-setup {
    background: #eef7f2;
    border: 1px solid #b7dec9;
    border-radius: 8px;
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 1rem;
}

.totp-setup[hidden] {
    display: none;
}

.totp-secret-row {
    align-items: end;
    display: grid;
    gap: 0.75rem;
    grid-template-columns: minmax(0, 1fr) auto auto;
}

.totp-secret-row button {
    min-height: 2.65rem;
}

table {
    font-size: 0.9rem;
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 0.7rem 0.75rem;
    text-align: left;
}

.users-list-table thead th,
.roles-list-table thead th,
.menus-list-table thead th {
    background: #1CC885;
    color: #ffffff;
}

tbody tr:hover {
    background: #fbfcfd;
}

.users-list-table .sort-button,
.roles-list-table .sort-button,
.menus-list-table .sort-button {
    color: #ffffff;
}

.sort-button {
    align-items: center;
    background: transparent;
    color: var(--text);
    display: inline-flex;
    font-size: 0.9rem;
    font-weight: 700;
    gap: 0.35rem;
    padding: 0;
}

.sort-button:hover {
    filter: none;
    text-decoration: underline;
}

.sort-button[data-dir="asc"]::after {
    content: "▲";
    font-size: 0.75rem;
}

.sort-button[data-dir="desc"]::after {
    content: "▼";
    font-size: 0.75rem;
}

.pagination-bar {
    align-items: center;
    background: var(--soft-panel);
    border: 1px solid var(--soft-line);
    border-radius: 8px;
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;
    margin-top: 1rem;
    padding: 0.75rem;
}

.pagination-bar label {
    align-items: center;
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
}

.pagination-bar select {
    width: auto;
}

.pagination-actions {
    align-items: center;
    display: flex;
    gap: 0.5rem;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.alert,
.notice {
    border-radius: 6px;
    margin: 0 0 1rem;
    padding: 0.8rem;
}

.alert {
    background: #fde7e4;
    color: var(--danger);
}

.notice {
    background: #e7f5ee;
    color: var(--success);
}

@media (max-width: 760px) {
    body {
        min-width: 320px;
    }

    .sidebar {
        position: static;
        width: auto;
        padding: 1rem;
    }

    .brand {
        margin-bottom: 1rem;
    }

    .brand img {
        max-width: 150px;
    }

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

    .content {
        margin-left: 0;
        padding: 1rem;
    }

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

    .topbar h1 {
        font-size: 1.45rem;
    }

    .panel {
        padding: 1rem;
    }

    .auth-box {
        padding: 1.25rem;
    }

    #user-form {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button {
        width: 100%;
    }

    .button-link {
        text-align: center;
        width: 100%;
    }

    .list-header {
        align-items: stretch;
        flex-direction: column;
    }

    .list-actions,
    .filter-actions {
        flex-direction: column;
    }

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

    .pagination-bar,
    .pagination-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .filters-panel {
        grid-template-columns: 1fr;
    }

    #role-form,
    #menu-form {
        grid-template-columns: 1fr;
    }

    .totp-secret-row {
        grid-template-columns: 1fr;
    }

    .totp-secret-row button {
        width: 100%;
    }

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

    thead {
        display: none;
    }

    tr {
        background: #ffffff;
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 1rem;
        overflow: hidden;
    }

    td {
        align-items: flex-start;
        border-bottom: 1px solid var(--line);
        display: flex;
        gap: 1rem;
        justify-content: space-between;
        padding: 0.8rem;
    }

    td::before {
        color: var(--muted);
        content: attr(data-label);
        font-weight: 700;
        min-width: 5.5rem;
    }

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

    .actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        white-space: normal;
    }

    .actions::before {
        margin-right: auto;
    }
}
