﻿:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --sidebar: #ffffff;
    --sidebar-soft: #eef4ff;
    --border: #d9e0e7;
    --border-strong: #c2ccd6;
    --text: #1f2933;
    --muted: #667085;
    --primary: #2563eb;
    --primary-soft: #e8f0ff;
    --success: #148f63;
    --success-soft: #e8f7ef;
    --warning: #b7791f;
    --warning-soft: #fff3d6;
    --danger: #c24135;
    --danger-soft: #fdebea;
    --shadow: 0 16px 36px rgba(31, 41, 51, 0.08);
}

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

* {
    box-sizing: border-box;
}

button, input, select {
    font: inherit;
}

.login-shell {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--bg);
}

.login-card {
    width: min(400px, 100%);
    padding: 32px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 18px 42px rgba(31, 41, 51, 0.08);
}

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

.login-copy {
    margin-bottom: 22px;
    text-align: center;
}

.login-copy h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 760;
}

.login-button {
    margin-top: 18px;
    min-height: 42px;
}

.login-switch {
    margin-top: 8px;
    color: var(--primary);
    background: transparent;
    border-color: transparent;
}

.login-switch:hover:not(:disabled) {
    background: var(--primary-soft);
    filter: none;
}

.login-card > .field + .field {
    margin-top: 14px;
}

.login-card .notice {
    margin-top: 14px;
}

.admin-shell {
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
    min-height: 100vh;
    background: var(--bg);
}

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

.admin-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px 18px;
    color: var(--text);
    background: var(--sidebar);
    border-right: 1px solid var(--border);
}

.admin-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.session-avatar, .avatar-small, .brand-mark {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 8px;
    font-weight: 700;
}

.session-avatar {
    width: 40px;
    height: 40px;
    color: #ffffff;
    background: var(--primary);
}

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

.brand-mark {
    width: 42px;
    height: 42px;
    color: #ffffff;
    background: linear-gradient(135deg, #2563eb, #148f63);
}

.brand-title {
    font-size: 18px;
    font-weight: 750;
    letter-spacing: 0;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 13px;
}

.sidebar-brand {
    position: relative;
}

.sidebar-toggle {
    display: inline-grid;
    width: 38px;
    height: 38px;
    margin-left: auto;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    background: var(--surface-soft);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.sidebar-toggle:hover {
    color: var(--primary);
    border-color: rgba(37, 99, 235, 0.28);
    background: var(--primary-soft);
}

.content-stage {
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 24px;
}

.nav-list {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.nav-group-label {
    padding: 10px 12px 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}

.nav-button {
    display: flex;
    gap: 12px;
    width: 100%;
    min-height: 58px;
    align-items: center;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.nav-button:hover {
    background: var(--sidebar-soft);
}

.nav-button.active {
    color: #1d4ed8;
    border-color: rgba(37, 99, 235, 0.18);
    background: var(--sidebar-soft);
}

.nav-button strong,
.nav-button small {
    display: block;
}

.nav-button small {
    margin-top: 2px;
    color: var(--muted);
}

.nav-icon {
    display: inline-grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 8px;
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 700;
}

.sidebar-status {
    padding: 14px;
    border-radius: 8px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
}

.sidebar-footer {
    display: grid;
    gap: 10px;
    margin-top: auto;
}

.sidebar-session {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 14px;
    border-radius: 8px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
}

.sidebar-session strong,
.sidebar-session small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-session small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.sidebar-session .btn {
    grid-column: 1 / -1;
    width: 100%;
}

.page-panel {
    display: grid;
    gap: 18px;
}

.panel, .surface, .table-card, .metric-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(31, 41, 51, 0.04);
}

.panel {
    padding: 18px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.page-head h2 {
    margin: 2px 0 4px;
    font-size: 26px;
}

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

.metric-card {
    padding: 16px;
}

.metric-card strong {
    display: block;
    margin: 6px 0 2px;
    font-size: 24px;
}

.metric-card small,
.metric-label {
    color: var(--muted);
}

.work-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.85fr);
    gap: 14px;
}

.users-mode-list .work-grid {
    grid-template-columns: 1fr;
}

.users-mode-list .work-grid .surface:nth-child(1),
.users-mode-list .work-grid .surface:nth-child(2),
.users-mode-create .metric-grid,
.users-mode-create .work-grid .surface:nth-child(2),
.users-mode-create .work-grid .surface:nth-child(3),
.users-mode-create .table-card,
.users-mode-card .metric-grid,
.users-mode-card .work-grid .surface:nth-child(1),
.users-mode-card .work-grid .surface:nth-child(3),
.users-mode-card .table-card {
    display: none;
}

.users-mode-create .work-grid,
.users-mode-card .work-grid {
    grid-template-columns: minmax(420px, 760px);
}

.users-mode-create .work-grid .surface,
.users-mode-card .work-grid .surface {
    min-height: 280px;
}

.surface {
    padding: 16px;
}

.section-title, .table-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.section-title h3,
.table-head h3 {
    margin: 0 0 4px;
    font-size: 17px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
    margin-top: 14px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.field {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.field span {
    font-weight: 600;
}

.field-short {
    max-width: 120px;
}

.inline-field {
    display: inline-grid;
}

.input, .btn {
    min-height: 38px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    padding: 8px 11px;
}

.input:focus {
    outline: 3px solid rgba(37, 99, 235, 0.16);
    border-color: var(--primary);
}

.input.full, .btn.full {
    width: 100%;
}

.search-input {
    flex: 1 1 260px;
}

.filter-select {
    flex: 0 0 138px;
}

.input.page-input {
    width: 86px;
    min-width: 86px;
}

.input.password-input {
    width: 190px;
    min-width: 170px;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    color: #ffffff;
    background: var(--primary);
    border-color: var(--primary);
    cursor: pointer;
    font-weight: 650;
}

.btn:hover:not(:disabled) {
    filter: brightness(0.96);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.btn.small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
}

.btn.secondary {
    color: var(--text);
    background: #ffffff;
    border-color: var(--border-strong);
}

.btn.danger {
    color: #ffffff;
    background: var(--danger);
    border-color: var(--danger);
}

.create-button {
    width: 100%;
    grid-column: 1 / -1;
}

.generated-card-panel {
    grid-column: 1 / -1;
    display: grid;
    gap: 12px;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
}

.generated-card-actions,
.generated-card-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.generated-card-actions {
    justify-content: space-between;
    flex-wrap: wrap;
}

.generated-card-list {
    display: grid;
    gap: 8px;
    max-height: 360px;
    overflow: auto;
}

.generated-card-row {
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.generated-card-row code {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-family: Consolas, "Cascadia Mono", monospace;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-card {
    overflow: hidden;
}

.table-head {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    min-width: 1080px;
    border-collapse: collapse;
    table-layout: fixed;
}

.admin-table th,
.admin-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.admin-table th {
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

.admin-table th:nth-child(1),
.admin-table td:nth-child(1) {
    width: 22%;
}

.admin-table th:nth-child(2),
.admin-table td:nth-child(2),
.admin-table th:nth-child(3),
.admin-table td:nth-child(3),
.admin-table th:nth-child(6),
.admin-table td:nth-child(6) {
    width: 9%;
}

.admin-table th:nth-child(4),
.admin-table td:nth-child(4) {
    width: 16%;
}

.admin-table th:nth-child(5),
.admin-table td:nth-child(5) {
    width: 20%;
}

.admin-table th:nth-child(7),
.admin-table td:nth-child(7) {
    width: 15%;
}

.admin-table tbody tr:hover {
    background: #fbfdff;
}

.account-stack {
    display: flex;
    align-items: center;
    gap: 10px;
}

.account-stack strong,
.account-stack small {
    display: block;
}

.account-stack small {
    margin-top: 2px;
    color: var(--muted);
}

.avatar-small {
    width: 34px;
    height: 34px;
    color: var(--primary);
    background: var(--primary-soft);
}

.actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
    min-width: 146px;
}

.actions-cell {
    min-width: 154px;
}

.session-summary {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.session-summary strong,
.session-summary small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-summary strong {
    color: var(--text);
    font-weight: 700;
}

.session-summary small {
    color: var(--muted);
    font-size: 12px;
}

.settings-row td {
    padding: 0;
    background: #fbfcfd;
}

.detail-shell {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    padding: 16px 18px;
    border-top: 1px solid var(--border);
}

.session-list {
    display: grid;
    gap: 10px;
    background: transparent;
}

.session-list.compact {
    margin-top: 12px;
}

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.session-item strong,
.session-item small {
    display: block;
}

.session-item small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.detail-section {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.detail-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.detail-list span {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.detail-list strong {
    color: var(--text);
    text-align: right;
}

.settings-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: end;
    margin-top: 10px;
}

.settings-actions .field,
.settings-actions .btn {
    min-width: 0;
    width: 100%;
}

.password-field {
    grid-column: 1 / -1;
    min-width: 0;
}

.password-field .password-input {
    width: 100%;
    min-width: 0;
}

.pager {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 14px 18px;
    background: var(--surface-soft);
}

.status-badge,
.status-pill,
.type-pill,
.audit-pill,
.device-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 750;
    border: 1px solid transparent;
}

.status-badge.active,
.status-pill.ok,
.audit-pill.success {
    color: var(--success);
    background: var(--success-soft);
    border-color: rgba(20, 143, 99, 0.22);
}

.status-badge.frozen,
.status-badge.deleted,
.status-pill.danger,
.audit-pill.danger {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: rgba(194, 65, 53, 0.22);
}

.status-badge.locked,
.audit-pill.warning {
    color: var(--warning);
    background: var(--warning-soft);
    border-color: rgba(183, 121, 31, 0.25);
}

.status-pill.neutral,
.audit-pill.neutral,
.type-pill,
.device-count {
    color: #3f5367;
    background: #eef2f6;
    border-color: #dce4ec;
}

.muted-row {
    color: #7b8794;
}

.audit-table {
    min-width: 980px;
}

.nowrap {
    white-space: nowrap;
}

.detail-cell {
    max-width: 520px;
}

.settings-surface {
    max-width: 760px;
}

.settings-surface.wide {
    max-width: 1040px;
}

.settings-surface.full {
    width: 100%;
    max-width: none;
}

.settings-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
    margin-top: 16px;
}

.version-field {
    min-width: min(320px, 100%);
}

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

.textarea {
    width: 100%;
    min-height: 240px;
    resize: vertical;
    line-height: 1.45;
    font-family: Consolas, "Cascadia Mono", monospace;
}

.check-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
}

.check-row input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--primary);
}

.check-row strong,
.check-row small {
    display: block;
}

.check-row small {
    margin-top: 3px;
    color: var(--muted);
}

.inline-rule-form {
    display: grid;
    grid-template-columns: minmax(220px, 0.9fr) minmax(220px, 0.9fr) auto;
    gap: 12px;
    align-items: end;
    margin-top: 16px;
}

.inline-rule-form .btn {
    min-width: 112px;
}

.rule-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 16px;
}

.rule-toolbar .search-input {
    max-width: 420px;
}

.rule-table-card {
    margin-top: 16px;
    box-shadow: none;
}

.rule-table {
    min-width: 760px;
}

.rule-table th:nth-child(1),
.rule-table td:nth-child(1) {
    width: 40%;
}

.rule-table th:nth-child(2),
.rule-table td:nth-child(2) {
    width: 44%;
}

.rule-table th:nth-child(3),
.rule-table td:nth-child(3) {
    width: 16%;
}

.rule-table code {
    display: inline-block;
    max-width: 100%;
    padding: 3px 7px;
    border-radius: 6px;
    color: #1f2933;
    background: #eef2f6;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.modal-form {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.rule-modal {
    width: min(520px, 100%);
}

.info-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-top: 16px;
    padding: 12px;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--muted);
}

.info-strip strong {
    color: var(--text);
}

.eyebrow {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.admin-sidebar .eyebrow {
    color: var(--muted);
}

.hint {
    margin: 0;
    color: var(--muted);
    min-height: 1.2em;
}

.hint.compact {
    margin-top: 4px;
}

.hint.danger {
    color: var(--danger);
}

.sidebar-collapsed .admin-sidebar {
    padding: 18px 12px;
    align-items: center;
}

.sidebar-collapsed .brand-block {
    justify-content: center;
    width: 100%;
}

.sidebar-collapsed .sidebar-brand {
    display: grid;
    justify-items: center;
    gap: 10px;
}

.sidebar-collapsed .brand-block > div:not(.brand-mark),
.sidebar-collapsed .nav-group-label,
.sidebar-collapsed .nav-button span:not(.nav-icon),
.sidebar-collapsed .sidebar-session div,
.sidebar-collapsed .sidebar-session .btn,
.sidebar-collapsed .sidebar-status {
    display: none;
}

.sidebar-collapsed .sidebar-toggle {
    margin-left: 0;
}

.sidebar-collapsed .nav-list,
.sidebar-collapsed .sidebar-footer {
    width: 100%;
}

.sidebar-collapsed .nav-button {
    justify-content: center;
    min-height: 48px;
    padding: 8px;
}

.sidebar-collapsed .nav-icon {
    width: 36px;
    height: 36px;
}

.sidebar-collapsed .sidebar-session {
    display: flex;
    justify-content: center;
    padding: 8px;
}

.notice {
    padding: 11px 13px;
    border-radius: 8px;
    font-weight: 600;
}

.notice.success {
    color: var(--success);
    background: var(--success-soft);
    border: 1px solid rgba(20, 143, 99, 0.22);
}

.notice.danger {
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid rgba(194, 65, 53, 0.22);
}

.user-feedback {
    position: sticky;
    top: 86px;
    z-index: 30;
    box-shadow: 0 10px 24px rgba(31, 41, 51, 0.08);
}

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(17, 24, 39, 0.48);
}

.modal-panel {
    width: min(460px, 100%);
    padding: 22px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-panel h3 {
    margin: 6px 0 8px;
}

.modal-panel p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

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

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

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

    .work-grid,
    .metric-grid,
    .detail-shell {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 640px) {
    .content-stage,
    .admin-sidebar {
        padding: 16px;
    }

    .page-head,
    .section-title,
    .table-head {
        flex-direction: column;
        align-items: stretch;
    }

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

    .settings-actions,
    .settings-form,
    .inline-rule-form,
    .toolbar,
    .rule-toolbar {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

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

    .input.page-input,
    .input.password-input,
    .version-field,
    .field-short {
        width: 100%;
        max-width: none;
    }
}
