* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
    color: #0f172a;
    background: #0b1220;
    letter-spacing: 0.2px;
}

:root {
    --topbar-height: 64px;
}

.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #1e293b, #0b1220 55%);
}

.card {
    width: min(420px, 90%);
    background: #0f172a;
    border: 1px solid #1f2a44;
    border-radius: 18px;
    padding: 32px;
    box-shadow: 0 12px 50px rgba(2, 6, 23, 0.45);
}

.card h1 {
    margin: 0 0 8px;
    font-size: 26px;
    color: #f8fafc;
}

.muted {
    margin: 0 0 24px;
    color: #94a3b8;
}

.form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 8px;
    font-size: 14px;
    color: #cbd5f5;
}

input {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #334155;
    background: #111827;
    color: #e2e8f0;
}

input:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.primary {
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #0b1220;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(14, 165, 233, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(14, 165, 233, 0.35);
}

.links {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
}

.links a {
    color: #93c5fd;
    text-decoration: none;
    font-size: 14px;
}

.alert {
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert.error {
    background: rgba(239, 68, 68, 0.15);
    color: #fecaca;
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.alert.success {
    background: rgba(34, 197, 94, 0.15);
    color: #bbf7d0;
    border: 1px solid rgba(34, 197, 94, 0.4);
}

.app {
    min-height: 100vh;
    background: #0b1220;
    color: #e2e8f0;
    overflow-x: hidden;
}

.topbar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(15, 23, 42, 0.92);
    border-bottom: 1px solid #1f2a44;
    backdrop-filter: blur(8px);
}

.logo {
    font-weight: 700;
    font-size: 18px;
}

.user {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #cbd5f5;
}

.user-label {
    font-size: 12px;
    color: #cbd5f5;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ghost {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid #334155;
    background: transparent;
    color: #e2e8f0;
    cursor: pointer;
}

.ghost.danger {
    border-color: rgba(248, 113, 113, 0.6);
    color: #f87171;
}

.icon-only {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-svg {
    width: 18px;
    height: 18px;
    display: inline-flex;
}

.icon-svg svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: calc(100vh - 64px);
}

.sidebar {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(9, 14, 26, 0.98));
    border-right: 1px solid #1f2a44;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-content: start;
}

.sidebar-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #64748b;
    margin-bottom: 4px;
}

.menu-item {
    background: rgba(17, 24, 39, 0.9);
    border: 1px solid transparent;
    color: #e2e8f0;
    padding: 8px 10px;
    border-radius: 14px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s ease, border 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    font-size: 13px;
    min-height: 44px;
}

.menu-item:hover {
    background: rgba(30, 41, 59, 0.9);
    border-color: rgba(56, 189, 248, 0.35);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(2, 6, 23, 0.35);
}

.menu-item.active {
    background: rgba(14, 165, 233, 0.2);
    border-color: rgba(56, 189, 248, 0.6);
    color: #e0f2fe;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.2);
}

.menu-item .icon {
    width: 26px;
    height: 26px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(56, 189, 248, 0.3);
    display: grid;
    place-items: center;
    font-size: 10px;
    letter-spacing: 0.08em;
    color: #7dd3fc;
}



.workspace {
    padding: 20px;
    display: grid;
    gap: 16px;
    grid-template-rows: auto 1fr;
    align-content: start;
    overflow-x: hidden;
}

.tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.tab {
    background: #111827;
    border: 1px solid #1f2a44;
    padding: 6px 10px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    min-width: 120px;
    max-width: 170px;
    height: 32px;
    transition: border 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.tab span {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab button {
    flex: 0 0 auto;
}

.tab.active {
    border-color: #38bdf8;
    color: #38bdf8;
}

.tab button {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.tab-content {
    background: #0f172a;
    border: 1px solid #1f2a44;
    border-radius: 16px;
    padding: 24px;
    min-height: 360px;
    box-shadow: 0 16px 40px rgba(2, 6, 23, 0.35);
    overflow-x: hidden;
}

.tab-content[data-active-menu="clients"] {
    width: min(1200px, 100%);
    margin: 0 auto;
}

.tab-content[data-active-menu="clients"] .table-wrap {
    overflow-x: auto;
}

.tab-content[data-active-menu="clients"] .data-table {
    table-layout: auto;
    min-width: 100%;
}

.tab-content[data-active-menu="clients"] .data-table th,
.tab-content[data-active-menu="clients"] .data-table td {
    white-space: nowrap;
}

.empty-state {
    color: #94a3b8;
}

.tab-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.pill {
    border: 1px solid #1f2a44;
    background: rgba(15, 23, 42, 0.6);
    color: #94a3b8;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 999px;
}

.tab-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.ghost.small {
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 11px;
}

.table-wrap {
    background: #0b1220;
    border: 1px solid #1f2a44;
    border-radius: 14px;
    padding: 12px;
    overflow: auto;
    position: relative;
    user-select: text;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.08);
}

.table-wrap.loading .table-overlay {
    opacity: 1;
}

.table-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 18, 32, 0.55);
    color: #94a3b8;
    display: grid;
    place-items: center;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.icon-button {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid #38bdf8;
    background: rgba(14, 165, 233, 0.15);
    color: #7dd3fc;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    z-index: 50;
}

.modal.hidden {
    display: none;
}

.details-panel.hidden,
.details-panel-backdrop.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.7);
}

.modal-content {
    position: relative;
    width: min(640px, 92%);
    background: #0f172a;
    border: 1px solid #1f2a44;
    border-radius: 16px;
    padding: 16px;
    z-index: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.modal-title {
    font-size: 14px;
    color: #e2e8f0;
    font-weight: 600;
}

.columns-list {
    display: grid;
    gap: 8px;
    max-height: 320px;
    overflow: auto;
    padding: 6px 2px 12px;
}

.columns-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #cbd5f5;
}

.details-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.5);
    z-index: 50;
}

.details-panel {
    position: fixed;
    top: 64px;
    right: 16px;
    bottom: 16px;
    width: min(420px, 92vw);
    background: #0f172a;
    border: 1px solid #1f2a44;
    border-radius: 16px;
    padding: 16px;
    z-index: 55;
    box-shadow: 0 16px 40px rgba(2, 6, 23, 0.45);
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 12px;
}

.details-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.details-panel-title {
    font-size: 14px;
    font-weight: 600;
    color: #e2e8f0;
}

.details-panel-title.small {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
}

.details-panel-body {
    overflow: auto;
    display: grid;
    gap: 10px;
}

.details-panel-section {
    border-top: 1px solid #1f2a44;
    padding-top: 10px;
    display: grid;
    gap: 8px;
}

.audit-row {
    border: 1px solid #1f2a44;
    border-radius: 10px;
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.4);
    display: grid;
    gap: 4px;
}

.audit-action {
    font-size: 12px;
    font-weight: 600;
    color: #e2e8f0;
}

.audit-meta {
    font-size: 11px;
    color: #94a3b8;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.details-item {
    border: 1px solid #1f2a44;
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.4);
}

.details-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    margin-bottom: 6px;
}

.details-value {
    font-size: 13px;
    color: #e2e8f0;
    word-break: break-word;
}

.toast-container {
    position: fixed;
    right: 16px;
    bottom: 16px;
    display: grid;
    gap: 8px;
    z-index: 60;
}

.toast {
    background: #0f172a;
    border: 1px solid #1f2a44;
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.success {
    border-color: rgba(34, 197, 94, 0.5);
    color: #86efac;
}

.toast.error {
    border-color: rgba(239, 68, 68, 0.5);
    color: #fecaca;
}

.toast.hide {
    opacity: 0;
    transform: translateY(6px);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid #1f2a44;
    user-select: text;
    -webkit-user-select: text;
    -webkit-touch-callout: default;
}

.data-table td {
    cursor: text;
}

.actions-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.cell-link {
    color: #93c5fd;
    text-decoration: none;
}

.cell-link:hover {
    text-decoration: underline;
}

body.light .cell-link {
    color: #0ea5e9;
}

.data-table {
    -webkit-user-select: text;
    user-select: text;
}

.data-table thead th {
    color: #94a3b8;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.data-table thead th[data-sort] {
    cursor: pointer;
    user-select: none;
}

mark {
    background: rgba(56, 189, 248, 0.25);
    color: #e2e8f0;
    padding: 0 2px;
    border-radius: 4px;
}

.data-table tbody tr:hover {
    background: rgba(30, 41, 59, 0.4);
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status.active {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.55);
}

.status.inactive {
    background: rgba(248, 113, 113, 0.2);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.5);
}

.loader {
    color: #94a3b8;
    font-size: 13px;
}

.form-card {
    border: 1px solid #1f2a44;
    border-radius: 14px;
    padding: 12px;
    background: rgba(15, 23, 42, 0.7);
}

.form-title {
    font-size: 13px;
    color: #cbd5f5;
    margin-bottom: 8px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    align-items: center;
}

.primary.small {
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 12px;
}

.form-message {
    margin-top: 8px;
    font-size: 12px;
    color: #94a3b8;
}

.form-message.success {
    color: #86efac;
}

.form-message.error {
    color: #fecaca;
}

.filter-select.small {
    padding: 6px 8px;
    font-size: 12px;
    border-radius: 8px;
}

.permissions-grid {
    display: grid;
    gap: 8px;
    max-height: 360px;
    overflow: auto;
    padding: 8px 0;
}

.admin-perms-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.perm-group {
    border: 1px solid #1f2a44;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(15, 23, 42, 0.4);
}

.perm-group-toggle {
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.perm-group-body {
    padding: 6px 12px;
}

.perm-group.collapsed .perm-group-body {
    display: none;
}

.perm-row {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 12px;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #1f2a44;
}

.perm-name {
    font-size: 12px;
    color: #cbd5f5;
}

body.light .perm-group {
    border-color: #d5dbe7;
    background: #f8fafc;
}

body.light .perm-group-toggle {
    color: #0b1324;
}

body.light .perm-row {
    border-bottom-color: #d5dbe7;
}

body.light .perm-name {
    color: #475569;
}

.modal-actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

.admin-panels {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.admin-card {
    border: 1px solid #1f2a44;
    border-radius: 12px;
    padding: 12px;
    background: rgba(15, 23, 42, 0.4);
}

.admin-toolbar {
    display: grid;
    gap: 8px;
}

.admin-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.file-button {
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.file-button input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.admin-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    align-items: center;
}

.perm-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #cbd5f5;
    padding: 4px 0;
}

body.light .admin-card {
    border-color: #d5dbe7;
    background: #f8fafc;
}

body.light .perm-check {
    color: #475569;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.filter-input,
.filter-select {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #1f2a44;
    background: #0b1220;
    color: #e2e8f0;
    font-size: 12px;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.pagination {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 12px;
    color: #94a3b8;
}

.pagination-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.pagination .ghost[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 980px) {
    .filters {
        grid-template-columns: 1fr;
    }

    .details-panel {
        left: 10px;
        right: 10px;
        top: 76px;
        bottom: 96px;
        width: auto;
    }

    .pagination {
        flex-direction: column;
        align-items: flex-start;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid #1f2a44;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(120px, 1fr);
        gap: 10px;
        overflow-x: auto;
        padding: 12px;
        scroll-snap-type: x mandatory;
    }

    .sidebar-title {
        width: 100%;
    }

    .menu-item {
        flex: 0 0 auto;
        justify-content: center;
        text-align: center;
        flex-direction: column;
        gap: 6px;
        padding: 10px 12px;
        scroll-snap-align: start;
    }

    .topbar {
        flex-wrap: wrap;
        gap: 12px;
        height: auto;
        padding: 12px 16px;
    }

    .workspace {
        padding: 16px;
    }

    .tab-content {
        padding: 16px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 40;
        background: rgba(15, 23, 42, 0.98);
        backdrop-filter: blur(8px);
        border-top: 1px solid #1f2a44;
        border-bottom: none;
        grid-auto-flow: column;
        grid-auto-columns: minmax(70px, 1fr);
        padding: 8px 10px;
        gap: 6px;
    }

    .sidebar-footer {
        display: block;
        border-top: none;
        padding-top: 0;
    }

    .tabs {
        overflow-x: auto;
        padding-bottom: 6px;
    }

    .tab {
        min-width: 110px;
        max-width: 150px;
    }

    .table-wrap {
        padding: 8px;
    }

    .data-table {
        font-size: 12px;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    input,
    .filter-input,
    .filter-select {
        font-size: 16px;
    }

    .sidebar-title {
        display: none;
    }

    .menu-item {
        min-height: 56px;
        padding: 8px 6px;
        font-size: 11px;
    }

    .menu-item .icon {
        width: 22px;
        height: 22px;
        font-size: 9px;
    }

    .workspace {
        padding-bottom: 84px;
    }
}

@media (max-width: 520px) {
    .menu-item .icon {
        width: 22px;
        height: 22px;
        font-size: 9px;
    }

    .menu-item {
        min-height: 56px;
    }

    .tab {
        height: 30px;
        font-size: 11px;
    }
}

body.light {
    background: #f7f8fb;
    color: #0f172a;
}

body.light .auth {
    background: radial-gradient(circle at top, #e7edf6, #f7f8fb 55%);
}

body.light .card,
body.light .topbar,
body.light .tab-content,
body.light .modal-content {
    background: #ffffff;
    border-color: #e2e8f0;
    color: #0f172a;
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
}

body.light .sidebar {
    background: #f1f4f9;
    border-right-color: #e2e8f0;
}

body.light .menu-item {
    background: #ffffff;
    color: #0f172a;
    border-color: #e2e8f0;
}

body.light .menu-item:hover {
    background: #f8fafc;
    border-color: #cbd5f5;
}

body.light .menu-item.active {
    background: rgba(14, 165, 233, 0.14);
    border-color: rgba(14, 165, 233, 0.55);
    color: #0f172a;
}

body.light .user-chip {
    color: #0f172a;
    background: #ffffff;
    border-color: #e2e8f0;
}

body.light .tab,
body.light .table-wrap,
body.light .filter-input,
body.light .filter-select,
body.light input {
    background: #ffffff;
    border-color: #e2e8f0;
    color: #0f172a;
}

body.light .tab.active {
    border-color: #0ea5e9;
    color: #0284c7;
}

body.light .ghost,
body.light .pill {
    border-color: #e2e8f0;
    color: #0f172a;
}

body.light .muted,
body.light .user,
body.light .sidebar-title,
body.light .pagination {
    color: #64748b;
}

body.light .data-table thead th {
    color: #64748b;
}

body.light .data-table tbody tr:hover {
    background: #f3f6fb;
}

body.light .ghost.danger {
    border-color: rgba(248, 113, 113, 0.5);
    color: #ef4444;
}

body.light .details-item {
    border-color: #e2e8f0;
    background: #ffffff;
}

body.light .details-label {
    color: #94a3b8;
}

body.light .details-value {
    color: #0f172a;
}

body.light .table-overlay {
    background: rgba(247, 248, 251, 0.7);
    color: #475569;
}

body.light .toast {
    background: #ffffff;
    border-color: #e2e8f0;
    color: #0f172a;
}

body.light .columns-check {
    color: #475569;
}

body.light .details-panel {
    background: #ffffff;
    border-color: #e2e8f0;
}

body.light .details-panel-title {
    color: #0f172a;
}

body.light .details-panel-title.small,
body.light .audit-meta {
    color: #64748b;
}

body.light .details-panel-section,
body.light .audit-row {
    border-color: #e2e8f0;
    background: #ffffff;
}

body.light .audit-action {
    color: #0f172a;
}
