* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #0f1115;
    color: #e2e8f0;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

.app-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.view-layer {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #0f1115;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s ease;
    pointer-events: none;
    z-index: 10;
}
.view-layer.active {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    z-index: 20;
}
.view-layer.exit-left {
    transform: translateX(-30%);
    opacity: 0;
}

#view-login,
#view-forgot-password {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at top, #1e293b 0%, #0f1115 100%);
}
.ambient-glow {
    position: absolute;
    top: 10%;
    right: 10%;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: rgba(14, 165, 233, 0.15);
    filter: blur(80px);
    z-index: 0;
}
.login-box {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 380px;
    padding: 2.5rem;
}
.eyebrow {
    font-size: 0.75rem;
    color: #0ea5e9;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}
.login-box h1 {
    font-size: 1.875rem;
    font-weight: 600;
    margin-bottom: 2rem;
    color: #fff;
}
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    color: #94a3b8;
    margin-bottom: 0.5rem;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: 8px;
    border: 1px solid #334155;
    background: #1e293b;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus {
    border-color: #0ea5e9;
}

.primary-button {
    width: 100%;
    padding: 1rem;
    background: #0ea5e9;
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
}
.primary-button:active { background: #0284c7; }
.primary-button:disabled {
    background: #334155;
    color: #94a3b8;
    cursor: not-allowed;
}
.primary-button.danger { background: #ef4444; }
.primary-button.danger:active { background: #dc2626; }
.text-link-button {
    margin-top: 0.75rem;
    width: 100%;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 0.875rem;
    text-align: right;
    cursor: pointer;
    padding: 0;
}
.text-link-button:hover {
    color: #cbd5e1;
    text-decoration: underline;
}
.text-link-button:active { color: #e2e8f0; }
.outline-button {
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.85rem;
    border-radius: 8px;
    border: 1px solid #64748b;
    background: transparent;
    color: #cbd5e1;
    cursor: pointer;
}

.feedback-msg {
    margin-top: 1rem;
    font-size: 0.875rem;
    text-align: center;
    min-height: 1.25rem;
    color: #94a3b8;
}
.feedback-msg.error { color: #f43f5e; }

.view-header {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    background: rgba(15, 17, 21, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid #1e293b;
    flex-shrink: 0;
    z-index: 2;
}
.view-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #f8fafc;
}
.icon-button {
    background: none;
    border: none;
    color: #0ea5e9;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
}
.back-btn::before {
    content: "<";
    font-size: 1.25rem;
    margin-right: 0.35rem;
    line-height: 1;
    margin-top: -1px;
}
.header-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.25rem;
}
.hidden { display: none !important; }

.content-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
}
@media (min-width: 768px) {
    .content-scroll {
        padding: 1.5rem 3rem;
        max-width: 960px;
        margin: 0 auto;
        width: 100%;
    }
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 1.125rem 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s, transform 0.1s;
}
.list-item:active { background: #334155; transform: scale(0.98); }
.list-item:disabled,
.list-item.disabled {
    cursor: default;
    opacity: 0.92;
}
.list-item:disabled:active,
.list-item.disabled:active {
    transform: none;
    background: #1e293b;
}
.item-main { display: flex; flex-direction: column; gap: 0.35rem; }
.item-title { font-size: 1.0625rem; font-weight: 500; color: #f8fafc; }
.item-meta { font-size: 0.8125rem; color: #64748b; }
.item-arrow { color: #475569; font-size: 1.2rem; font-weight: 300; }

.machine-card {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    width: 100%;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 1.125rem 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s, transform 0.1s;
}
.machine-card:active { background: #334155; transform: scale(0.98); }
.mc-head { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.mc-name { font-size: 1.0625rem; font-weight: 600; color: #fff; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #64748b; }
.status-dot.online { background: #10b981; box-shadow: 0 0 8px rgba(16, 185, 129, 0.4); }
.status-dot.warning { background: #f59e0b; }
.status-dot.danger { background: #f43f5e; }
.mc-body { display: flex; flex-direction: column; gap: 0.35rem; }
.mc-file {
    font-size: 0.875rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: block;
}
.mc-time { font-size: 0.75rem; color: #64748b; }

.detail-content { padding-bottom: 2rem; }
.detail-hero {
    padding: 1.5rem 0 2rem;
    text-align: center;
    border-bottom: 1px solid #1e293b;
    margin-bottom: 1.5rem;
}
.detail-hero h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: #f8fafc;
    margin-bottom: 0.75rem;
}
.status-badge {
    display: inline-flex;
    padding: 0.35rem 0.875rem;
    border-radius: 99px;
    font-size: 0.8125rem;
    font-weight: 600;
    background: #334155;
    color: #e2e8f0;
    margin-bottom: 0.75rem;
}
.status-badge.online { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.status-badge.warning { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.status-badge.danger { background: rgba(244, 63, 94, 0.15); color: #f43f5e; }
.detail-subtitle {
    font-size: 0.875rem;
    color: #94a3b8;
    word-break: break-all;
    padding: 0 1rem;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.metric-box {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.metric-label { font-size: 0.75rem; color: #94a3b8; font-weight: 500; }
.metric-value { font-size: 1.125rem; color: #f8fafc; font-weight: 600; }

.detail-card { margin-bottom: 1.5rem; }
.detail-card h3 {
    font-size: 0.8125rem;
    color: #64748b;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding-left: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.kv-list {
    background: #1e293b;
    border-radius: 12px;
    padding: 0.5rem 1rem;
    border: 1px solid #334155;
}
.kv-list dt { font-size: 0.875rem; color: #94a3b8; margin-top: 0.75rem; }
.kv-list dd {
    font-size: 0.875rem;
    color: #e2e8f0;
    font-weight: 500;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #334155;
    text-align: right;
    margin-top: -1.25rem;
}
.kv-list dd:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

.info-msg {
    background: rgba(245, 158, 11, 0.1);
    border-left: 4px solid #f59e0b;
    padding: 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #fcd34d;
    line-height: 1.5;
    word-break: break-word;
    font-weight: 500;
}

.user-card {
    background: rgba(30, 41, 59, 0.35);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 1rem;
}
.user-form .form-group { margin-bottom: 0.85rem; }

/* Keep create-user credentials inputs darker and avoid bright browser autofill look */
#create-role-username,
#create-role-password {
    background: #111827;
    border-color: #263244;
    color: #cbd5e1;
}

#create-role-username::placeholder,
#create-role-password::placeholder {
    color: #7b8aa3;
}

#create-role-username:focus,
#create-role-password:focus {
    border-color: #3b82f6;
}

#create-role-username:-webkit-autofill,
#create-role-username:-webkit-autofill:hover,
#create-role-username:-webkit-autofill:focus,
#create-role-password:-webkit-autofill,
#create-role-password:-webkit-autofill:hover,
#create-role-password:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #111827 inset;
    -webkit-text-fill-color: #cbd5e1;
    transition: background-color 5000s ease-in-out 0s;
}

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #cbd5e1;
    font-size: 0.9rem;
}
.checkbox-line input { width: auto; }

.empty-state {
    padding: 4rem 1rem;
    text-align: center;
    color: #64748b;
    font-size: 0.875rem;
    line-height: 1.5;
}

.admin-user-card { margin-bottom: 1rem; }
.admin-user-meta {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 0.75rem;
    padding-left: 0.5rem;
}
.admin-user-list { display: flex; flex-direction: column; gap: 0.5rem; }
.admin-user-row {
    border-radius: 10px;
    padding: 0.875rem 0.875rem;
    margin-bottom: 0;
}
.admin-user-row-static {
    cursor: default;
}
.admin-user-row-action {
    cursor: pointer;
}
.admin-user-row-action:hover {
    background: #233149;
}

.managed-group {
    background: rgba(30, 41, 59, 0.55);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 0.9rem;
    margin-bottom: 0.85rem;
}

.managed-group-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #334155;
}

.managed-group-title {
    font-size: 0.98rem;
    font-weight: 600;
    color: #f8fafc;
}

.managed-group-meta {
    font-size: 0.78rem;
    color: #94a3b8;
    white-space: nowrap;
}

.managed-role-section {
    margin-bottom: 0.7rem;
}

.managed-role-title {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-bottom: 0.45rem;
}

.managed-scope-section {
    margin-top: 0.8rem;
}

.managed-scope-section + .managed-scope-section {
    margin-top: 0.95rem;
    padding-top: 0.9rem;
    border-top: 1px solid #334155;
}

.managed-scope-title {
    font-size: 0.82rem;
    color: #cbd5e1;
    font-weight: 700;
    margin-bottom: 0.55rem;
}

.managed-role-grid {
    display: grid;
    gap: 0.65rem;
}

.managed-role-card {
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 0.72rem;
}

.managed-role-card-title {
    font-size: 0.88rem;
    color: #f8fafc;
    font-weight: 650;
}

.managed-role-card-subtitle {
    font-size: 0.78rem;
    color: #93c5fd;
    margin-top: 0.22rem;
}

.managed-role-card .managed-user-tags {
    margin-top: 0.56rem;
}

.managed-sites {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.managed-site-block {
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 0.65rem;
}

.managed-site-title {
    font-size: 0.8rem;
    color: #cbd5e1;
    margin-bottom: 0.45rem;
}

.managed-config-grid {
    display: grid;
    gap: 0.55rem;
}

.managed-config-item {
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.35);
}

.managed-config-key {
    font-size: 0.76rem;
    color: #94a3b8;
    margin-bottom: 0.2rem;
}

.managed-config-val {
    font-size: 0.83rem;
    color: #e2e8f0;
    word-break: break-all;
}

.managed-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.65rem;
}

.managed-row-actions .icon-button {
    padding: 0.3rem 0.55rem;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid #334155;
}

.managed-row-actions .icon-button.danger {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.55);
    background: rgba(127, 29, 29, 0.25);
}

.managed-expand-row {
    margin-top: 0.95rem;
}

.expand-toggle-button {
    padding: 0.55rem 1rem !important;
    font-size: 0.9rem;
    font-weight: 600;
}

.managed-submit-gap {
    height: 0.95rem;
}

.managed-advanced {
    margin-top: 0.7rem;
}

.risk-confirm-text {
    font-size: 1.05rem;
    line-height: 1.65;
    color: #cbd5e1;
    margin-top: 0.2rem;
    margin-bottom: 0.95rem;
}

.risk-confirm-actions {
    display: flex;
    justify-content: center;
    gap: 0.95rem;
}

.risk-btn {
    border: 1px solid #334155;
    border-radius: 8px;
    color: #cbd5e1;
    background: rgba(15, 23, 42, 0.45);
    padding: 0.42rem 0.95rem;
    font-size: 0.9rem;
}

.risk-btn-confirm {
    color: #f8fafc;
    background: #0ea5e9;
    border-color: #0ea5e9;
}

.managed-user-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.managed-tag {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    font-size: 0.78rem;
    padding: 0.25rem 0.55rem;
    border: 1px solid transparent;
    color: #e2e8f0;
    background: rgba(71, 85, 105, 0.28);
    cursor: pointer;
}

.managed-tag.role-admin {
    border-color: rgba(59, 130, 246, 0.6);
    background: rgba(59, 130, 246, 0.15);
    color: #bfdbfe;
}

.managed-tag.role-viewer {
    border-color: rgba(34, 197, 94, 0.55);
    background: rgba(34, 197, 94, 0.14);
    color: #bbf7d0;
}

.managed-tag.role-support {
    border-color: rgba(251, 146, 60, 0.55);
    background: rgba(251, 146, 60, 0.16);
    color: #fed7aa;
}

.managed-tag.inactive {
    border-color: rgba(244, 63, 94, 0.45);
    background: rgba(244, 63, 94, 0.14);
    color: #fecdd3;
}

.managed-tag.muted {
    color: #94a3b8;
    border-color: rgba(100, 116, 139, 0.45);
    background: rgba(100, 116, 139, 0.16);
    cursor: default;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-card {
    width: min(520px, 100%);
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 14px;
    padding: 1rem;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

@media (max-width: 720px) {
    #view-tenants .view-header {
        height: auto;
        min-height: 56px;
        padding: 8px 10px;
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
        gap: 6px;
    }

    #view-tenants .view-header h2 {
        font-size: 18px;
        white-space: nowrap;
        margin: 0;
    }

    #view-tenants .header-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        justify-items: start;
        gap: 6px;
        overflow: visible;
    }

    #view-tenants .header-actions .icon-button {
        width: auto;
        max-width: 100%;
        min-width: 0;
        justify-content: flex-start;
        font-size: 12px;
        padding: 7px 4px;
        line-height: 1.1;
        white-space: normal;
        text-align: left;
    }

    #view-tenants #btn-users-tenants {
        grid-column: 1;
    }

    #view-tenants #logout-button-tenants {
        grid-column: 2;
    }
}

@media (max-width: 360px) {
    #view-tenants .view-header h2 {
        font-size: 17px;
    }

    #view-tenants .header-actions .icon-button {
        font-size: 11px;
        padding-inline: 2px;
    }
}
