:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #101828;
    --muted: #667085;
    --line: #e4e7ec;
    --line-strong: #d0d5dd;
    --primary: #101828;
    --primary-hover: #293056;
    --success: #067647;
    --success-bg: #ecfdf3;
    --warning: #b54708;
    --warning-bg: #fffaeb;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --info: #175cd3;
    --info-bg: #eff8ff;
    --shadow:
        0 1px 2px rgba(16, 24, 40, .04),
        0 3px 12px rgba(16, 24, 40, .05);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

a {
    color: var(--info);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.page {
    width: min(1240px, calc(100% - 40px));
    margin: 0 auto;
    padding: 34px 0 70px;
}

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

.header-main {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

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

.brand-logo {
    display: block;
    width: 102px;
    height: auto;
}

.brand-platform {
    padding-left: 13px;
    border-left: 1px solid var(--line-strong);
    font-size: 24px;
    font-weight: 650;
    letter-spacing: -.02em;
}

.user-line,
.subtitle,
.muted {
    color: var(--muted);
}

.admin-badge,
.type-badge,
.status-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 650;
}

.admin-badge {
    margin-left: 5px;
    padding: 2px 8px;
    background: #eef4ff;
    color: #3538cd;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 650;
    line-height: 1.2;
    cursor: pointer;
    transition:
        transform .12s ease,
        background .12s ease,
        border-color .12s ease,
        box-shadow .12s ease;
}

.btn:hover {
    text-decoration: none;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    border-color: var(--line-strong);
    background: white;
    color: #344054;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-soft);
}

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

.btn-danger:hover:not(:disabled) {
    background: var(--danger-bg);
}

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

.metric-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.card,
.metric-card {
    border: 1px solid rgba(228, 231, 236, .9);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric-card {
    padding: 19px 20px;
}

.metric-label {
    color: #475467;
    font-size: 13px;
    font-weight: 650;
}

.metric-value {
    margin-top: 7px;
    font-size: 28px;
    font-weight: 720;
    letter-spacing: -.025em;
}

.metric-detail {
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

.text-success {
    color: var(--success);
}

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

.alert {
    margin: 0 0 22px;
    padding: 14px 16px;
    border: 1px solid;
    border-radius: 10px;
}

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

.alert-warning {
    border-color: #fedf89;
    background: var(--warning-bg);
    color: #93370d;
}

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

.section {
    margin-top: 34px;
}

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 14px;
}

.section-head h2 {
    margin: 0;
    font-size: 21px;
    letter-spacing: -.015em;
}

.section-head p {
    margin: 4px 0 0;
    color: var(--muted);
}

.table-card {
    overflow: hidden;
}

.table-wrap {
    overflow-x: auto;
}

.vm-table {
    width: 100%;
    border-collapse: collapse;
}

.vm-table th {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-soft);
    color: #475467;
    font-size: 12px;
    font-weight: 650;
    text-align: left;
    white-space: nowrap;
}

.vm-table td {
    padding: 14px;
    border-bottom: 1px solid #f0f1f3;
    vertical-align: middle;
    white-space: nowrap;
}

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

.vm-name {
    font-weight: 650;
}

.status-pill {
    gap: 7px;
    padding: 4px 9px;
}

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

.status-stopped {
    background: #f2f4f7;
    color: #475467;
}

.status-working {
    background: var(--info-bg);
    color: var(--info);
}

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

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.status-working .status-dot {
    animation: pulse 1.25s ease-in-out infinite;
}

@keyframes pulse {
    0%,
    100% {
        opacity: .35;
        transform: scale(.85);
    }

    50% {
        opacity: 1;
        transform: scale(1.18);
    }
}

.action-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
}

.action-group form {
    display: inline-flex;
    margin: 0;
}

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

.create-shell {
    padding: 22px;
}

.create-intro {
    margin-bottom: 18px;
}

.vm-type-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.vm-type-card {
    position: relative;
    min-height: 126px;
    padding: 17px;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: white;
}

.vm-type-card.selected {
    border-color: #667085;
    box-shadow: inset 0 0 0 1px #667085;
}

.vm-type-card.disabled {
    border-style: dashed;
    background: var(--surface-soft);
    color: #98a2b3;
}

.type-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.vm-type-card h3 {
    margin: 0;
    color: var(--text);
    font-size: 16px;
}

.vm-type-card.disabled h3 {
    color: #667085;
}

.vm-type-card p {
    max-width: 460px;
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.type-badge {
    flex: none;
    padding: 3px 8px;
}

.type-badge.available {
    background: var(--success-bg);
    color: var(--success);
}

.type-badge.soon {
    background: #f2f4f7;
    color: #667085;
}

.form-info-grid {
    display: grid;
    grid-template-columns:
        minmax(0, 2fr)
        minmax(250px, .85fr);
    gap: 18px;
    align-items: stretch;
}

.form-panel,
.info-panel {
    padding: 20px;
    border-radius: 12px;
}

.form-panel {
    border: 1px solid var(--line);
    background: white;
}

.info-panel {
    border: 1px solid #b2ddff;
    background: #f5faff;
}

.form-panel h3,
.info-panel h3 {
    margin: 0 0 15px;
    font-size: 15px;
}

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

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field[hidden] {
    display: none;
}

.field label {
    color: #344054;
    font-size: 13px;
    font-weight: 650;
}

.field input,
.field select,
.login-card input {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    outline: none;
    background: white;
    color: var(--text);
    transition:
        border-color .12s ease,
        box-shadow .12s ease;
}

.field input:focus,
.field select:focus,
.login-card input:focus {
    border-color: #667085;
    box-shadow:
        0 0 0 3px rgba(102, 112, 133, .12);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 18px;
}

.form-hint {
    color: var(--muted);
    font-size: 12px;
}

.info-list {
    display: grid;
    gap: 13px;
    margin: 0;
}

.info-row {
    display: grid;
    grid-template-columns: 82px 1fr;
    gap: 8px;
}

.info-row dt {
    color: #475467;
    font-size: 12px;
    font-weight: 650;
}

.info-row dd {
    margin: 0;
    color: #1849a9;
    font-size: 13px;
    font-weight: 650;
}

.info-note {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid #d1e9ff;
    color: #475467;
    font-size: 12px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
}

.login-shell {
    width: min(100%, 420px);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 22px;
    text-align: center;
}

.login-brand img {
    display: block;
    width: 132px;
    height: auto;
}

.login-platform {
    margin-top: 10px;
    font-size: 25px;
    font-weight: 680;
    letter-spacing: -.025em;
}

.login-card {
    padding: 28px;
}

.login-card h1 {
    margin: 0;
    font-size: 20px;
}

.login-card > p {
    margin: 5px 0 22px;
    color: var(--muted);
}

.login-card .field {
    margin-bottom: 15px;
}

.login-card .btn {
    width: 100%;
    margin-top: 5px;
}

.login-error {
    margin: 0 0 17px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 13px;
}

@media (max-width: 850px) {
    .vm-type-grid,
    .form-info-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .portal-header {
        align-items: flex-start;
    }
}

@media (max-width: 600px) {
    .page {
        width: min(100% - 24px, 1240px);
        padding-top: 20px;
    }

    .portal-header {
        flex-direction: column;
    }

    .brand-logo {
        width: 90px;
    }

    .brand-platform {
        font-size: 20px;
    }

    .create-shell {
        padding: 15px;
    }
}


/* ==========================================================
   Async VM lifecycle UX
   ========================================================== */

.vm-table tbody tr {
    transition:
        opacity .2s ease,
        background .2s ease;
}

.vm-row-working td {
    background: #f8fbff;
}

.vm-row-working {
    animation:
        vmRowWorking 1.8s ease-in-out infinite;
}

@keyframes vmRowWorking {
    0%,
    100% {
        opacity: .78;
    }

    50% {
        opacity: 1;
    }
}

.btn.is-loading {
    pointer-events: none;
}

.btn.is-loading::before {
    content: "";
    width: 13px;
    height: 13px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation:
        buttonSpin .65s linear infinite;
}

@keyframes buttonSpin {
    to {
        transform: rotate(360deg);
    }
}

.portal-toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 1000;
    display: grid;
    gap: 9px;
    width: min(
        390px,
        calc(100vw - 36px)
    );
}

.portal-toast {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
    box-shadow:
        0 8px 30px rgba(
            16,
            24,
            40,
            .14
        );
    color: #344054;
    animation:
        toastEnter .18s ease-out;
}

.portal-toast.success {
    border-color: #abefc6;
    background: #ecfdf3;
    color: #05603a;
}

.portal-toast.error {
    border-color: #fecdca;
    background: #fef3f2;
    color: #912018;
}

@keyframes toastEnter {
    from {
        opacity: 0;
        transform: translateY(-7px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.async-refresh-indicator {
    position: fixed;
    right: 20px;
    bottom: 18px;
    z-index: 999;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background:
        rgba(255,255,255,.94);
    box-shadow: var(--shadow);
    color: var(--muted);
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}

.async-refresh-indicator.visible {
    opacity: 1;
}

.async-refresh-indicator::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--info);
    animation:
        pulse 1.2s ease-in-out infinite;
}


/* ==========================================================
   Portal Audit
   ========================================================== */

.audit-admin-badge {
    display: inline-flex;
    align-items: center;

    padding: 5px 9px;

    border: 1px solid #d0d5dd;
    border-radius: 999px;

    background: #f9fafb;

    color: #475467;
    font-size: 12px;
    font-weight: 700;
}

.audit-card {
    padding: 0;
    overflow: hidden;
}

.audit-list {
    display: grid;
}

.audit-event {
    display: grid;
    grid-template-columns: 145px 1fr;
    gap: 20px;

    padding: 15px 20px;

    border-bottom:
        1px solid var(--line);
}

.audit-event:last-child {
    border-bottom: 0;
}

.audit-time {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.audit-message {
    color: #101828;
    font-weight: 650;
}

.audit-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;

    margin-top: 4px;

    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 700px) {
    .audit-event {
        grid-template-columns: 1fr;
        gap: 5px;
    }
}


/* ==========================================================
   Audit collapse + server-side paging
   ========================================================== */

.audit-details {
    margin-top: 34px;
}

.audit-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;

    margin-bottom: 0;

    cursor: pointer;
    user-select: none;
    list-style: none;
}

.audit-summary::-webkit-details-marker {
    display: none;
}

.audit-summary h2 {
    margin-bottom: 4px;
}

.audit-summary p {
    margin: 0;
    color: var(--muted);
}

.audit-summary-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.audit-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 28px;
    height: 28px;

    color: var(--muted);
    font-size: 18px;

    transition:
        transform .18s ease;
}

.audit-details[open]
.audit-chevron {
    transform: rotate(180deg);
}

.audit-details > .audit-card {
    margin-top: 16px;
}

.audit-loading,
.audit-empty {
    padding: 26px 20px;

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

.audit-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;

    min-height: 58px;

    padding: 12px 18px;

    border-top:
        1px solid var(--line);
}

.audit-page-info {
    color: var(--muted);
    font-size: 13px;
}

.audit-page-buttons {
    display: flex;
    align-items: center;
    gap: 7px;
}

.audit-page-button {
    min-width: 38px;

    padding: 7px 10px;

    border: 1px solid #d0d5dd;
    border-radius: 8px;

    background: white;

    color: #344054;

    font: inherit;
    font-size: 13px;
    font-weight: 650;

    cursor: pointer;
}

.audit-page-button:hover:not(:disabled) {
    background: #f9fafb;
}

.audit-page-button.current {
    border-color: #98a2b3;
    background: #f2f4f7;
    color: #101828;
}

.audit-page-button:disabled {
    opacity: .45;
    cursor: default;
}

@media (max-width: 700px) {
    .audit-pagination {
        align-items: flex-start;
        flex-direction: column;
    }

    .audit-summary {
        align-items: flex-start;
    }
}



/* CREATE_PROFILE_SELECTOR_V1 */

.vm-type-card.profile-option {
    width: 100%;
    appearance: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.vm-type-card.profile-option:hover {
    border-color: #98a2b3;
    background: #fcfcfd;
}

.vm-type-card.profile-option.selected:hover {
    border-color: #667085;
    background: white;
}

.vm-type-card.profile-option:focus-visible {
    outline: 3px solid rgba(102, 112, 133, .22);
    outline-offset: 2px;
}


.software-info {
    margin: -4px 0 22px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
}

.software-info[hidden] {
    display: none;
}

.software-info-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.software-info-head h3 {
    margin: 0;
    font-size: 16px;
}

.software-info-head p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}


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

.software-item {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 11px;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
}

.software-item > span {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.software-item strong {
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.software-item small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

.software-icon {
    display: block;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    object-fit: contain;
}


@media (max-width: 850px) {
    .software-grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .software-grid {
        grid-template-columns: 1fr;
    }

    .software-info-head {
        flex-direction: column;
    }
}
