/* =========================================================
   SCM SaaS Platform — SPA Layout CSS
   Phong cách: MISA AMIS App Launcher
   ========================================================= */

/* Reset hoàn toàn — ghi đè mọi theme WordPress */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0 !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: #1a202c;
}

/* Xóa admin bar nếu vẫn còn render */
#wpadminbar {
    display: none !important;
}

html.wp-toolbar {
    padding-top: 0 !important;
}

/* Đè theme container phổ biến */
.site, #page, #content, .site-content, .container, .wrapper,
.entry-content, .site-inner, .content-area, #main {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    transform: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

/* =========================================================
   DASHBOARD ROOT — Full Viewport
   ========================================================= */
#scm-spa-dashboard-root {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Background landscape image — tương tự MISA AMIS */
#scm-spa-dashboard-root::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        var(--scm-bg-image, none),
        linear-gradient(160deg, #b8d4f0 0%, #c9dff5 25%, #dde9f7 50%, #e8c8a0 75%, #d4a574 100%);
    background-size: cover;
    background-position: center;
    z-index: 0;
}

/* =========================================================
   HEADER — Thanh tiêu đề nổi trên background
   ========================================================= */
.spa-header {
    position: relative;
    z-index: 100;
    height: 56px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 16px;
    flex-shrink: 0;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
}

.spa-header-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.spa-header-left img {
    height: 36px;
    width: auto;
    object-fit: contain;
}

.spa-header-center {
    flex: 1;
    max-width: 320px;
    margin: 0 auto;
}

.spa-search-bar {
    display: flex;
    align-items: center;
    background: #f5f7fa;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 6px 16px;
    gap: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.spa-search-bar:focus-within {
    border-color: #0073aa;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.12);
}

.spa-search-bar input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: #4a5568;
    width: 100%;
}

.spa-search-bar input::placeholder {
    color: #a0aec0;
}

.spa-search-icon {
    color: #a0aec0;
    font-size: 15px;
    flex-shrink: 0;
}

.spa-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.btn-marketplace {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.btn-marketplace:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-marketplace svg {
    width: 16px;
    height: 16px;
}

.spa-header-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #6b7280;
    font-size: 18px;
    transition: background 0.15s;
}

.spa-header-icon-btn:hover {
    background: rgba(0,0,0,0.06);
}

.spa-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid #e2e8f0;
    position: relative;
}

.spa-avatar-wrapper {
    position: relative;
    cursor: pointer;
}

.spa-notification-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #e53e3e;
    border-radius: 50%;
    border: 2px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    color: #fff;
    font-weight: 700;
}

/* =========================================================
   CATEGORY TABS — Thanh tab danh mục
   ========================================================= */
.spa-category-nav {
    position: relative;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 20px 0;
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.spa-category-nav::-webkit-scrollbar {
    display: none;
}

.spa-cat-tab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 7px 16px;
    border-radius: 20px;
    border: none;
    background: rgba(255, 255, 255, 0.55);
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    outline: none;
}

.spa-cat-tab:hover {
    background: rgba(255, 255, 255, 0.78);
}

.spa-cat-tab.active {
    background: #fff;
    color: #1a202c;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.spa-cat-tab-icon {
    font-size: 14px;
}

/* =========================================================
   BODY — Vùng chứa App Grid + nội dung SPA động
   ========================================================= */
.spa-body {
    position: relative;
    z-index: 80;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 60px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.spa-body::-webkit-scrollbar {
    width: 6px;
}

.spa-body::-webkit-scrollbar-track {
    background: transparent;
}

.spa-body::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.18);
    border-radius: 3px;
}

/* =========================================================
   APP GRID — Lưới ứng dụng kiểu MISA AMIS
   ========================================================= */
.apps-group-container {
    margin-bottom: 36px;
}

.apps-group-title {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 14px 4px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

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

/* App Card — kiểu icon launcher như MISA AMIS */
.app-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 12px 16px;
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    text-align: center;
    user-select: none;
    position: relative;
}

.app-card:hover {
    background: rgba(255, 255, 255, 0.32);
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.app-card:active {
    transform: translateY(-1px);
}

/* Icon container — màu nền tròn bo góc như MISA */
.app-icon-wrapper {
    width: 68px;
    height: 68px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    overflow: hidden; /* Cắt ảnh theo border-radius, không có viền thừa */
}

/* Badge trạng thái (active = dấu check xanh ở góc dưới phải icon) */
.app-icon-badge {
    position: absolute;
    bottom: -3px;
    right: -3px;
    width: 20px;
    height: 20px;
    background: #38a169;
    border-radius: 50%;
    border: 2px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-icon-badge svg {
    width: 10px;
    height: 10px;
    fill: #fff;
}

.app-card-name {
    font-size: 13px;
    font-weight: 500;
    color: #1a202c;
    line-height: 1.3;
    max-width: 100%;
    word-break: break-word;
}

/* Trạng thái chưa kích hoạt */
.app-card.inactive .app-card-name {
    color: #4a5568;
}

/* =========================================================
   VIEWS NỘI DUNG ĐỘNG (Plans, Cart, Checkout, Workspace)
   ========================================================= */
.spa-view-fade-in {
    animation: scmFadeIn 0.25s ease-out;
}

@keyframes scmFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Card nổi trên background dùng cho Plans/Cart/Checkout/Workspace */
.spa-floating-panel {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.14);
    padding: 36px;
    max-width: 760px;
    margin: 0 auto;
}

.spa-floating-panel h2 {
    margin: 0 0 6px 0;
    font-size: 20px;
    color: #1a202c;
}

.spa-floating-panel .spa-panel-subtitle {
    color: #718096;
    font-size: 14px;
    margin: 0 0 28px 0;
}

/* Plan Cards */
.plan-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.plan-card {
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 28px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.plan-card:hover {
    border-color: #0073aa;
    box-shadow: 0 4px 16px rgba(0, 115, 170, 0.12);
}

/* Gói trial đã dùng — mờ đi, không cho click */
.plan-card-disabled {
    opacity: 0.6;
    cursor: default;
    background: #f9fafb;
}

.plan-card-disabled:hover {
    border-color: #e2e8f0;
    box-shadow: none;
    transform: none;
}

.plan-card-name {
    font-size: 16px;
    font-weight: 600;
    color: #1a202c;
}

.plan-card-price {
    font-size: 28px;
    font-weight: 700;
    color: #1a202c;
}

.plan-card-price.free {
    color: #38a169;
}

.plan-card-desc {
    font-size: 13px;
    color: #718096;
    line-height: 1.5;
    flex: 1;
}

.plan-card-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.plan-card-badge.trial {
    background: #fef3c7;
    color: #92400e;
}

.plan-card-badge.paid {
    background: #ebf8ff;
    color: #2b6cb0;
}

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 24px;
    background: #0073aa;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    width: 100%;
}

.btn-primary:hover {
    background: #005a87;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 24px;
    background: #f7fafc;
    color: #4a5568;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    width: 100%;
}

.btn-secondary:hover {
    background: #edf2f7;
}

/* Form elements */
.spa-form-group {
    margin-bottom: 18px;
}

.spa-form-group label {
    display: block;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
    font-size: 13px;
}

.spa-form-group select,
.spa-form-group input[type="text"],
.spa-form-group input[type="number"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    font-size: 14px;
    color: #1a202c;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.spa-form-group select:focus,
.spa-form-group input:focus {
    border-color: #0073aa;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.12);
}

/* Info row trong checkout */
.checkout-info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

.checkout-info-row:last-child {
    border-bottom: none;
}

.checkout-info-label {
    color: #718096;
}

.checkout-info-value {
    font-weight: 600;
    color: #1a202c;
    text-align: right;
    max-width: 60%;
    word-break: break-all;
}

/* Ẩn mũi tên spin mặc định của input[type=number] trong giỏ hàng */
#cart-qty-input::-webkit-outer-spin-button,
#cart-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Payment code highlight */
.payment-code-box {
    background: #fffbeb;
    border: 1px dashed #d97706;
    border-radius: 8px;
    padding: 10px 14px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 15px;
    color: #92400e;
    word-break: break-all;
}

/* Polling status */
.polling-status {
    background: #f0f4f8;
    border-radius: 10px;
    padding: 16px 20px;
    text-align: center;
    color: #4a5568;
    font-weight: 500;
    margin-top: 20px;
}

/* Loading */
.spa-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 12px;
    color: #718096;
    font-size: 15px;
}

.spa-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e2e8f0;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Error box */
.spa-error-box {
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 10px;
    padding: 20px 24px;
    color: #c53030;
    text-align: center;
    margin: 20px 0;
}

/* =========================================================
   FOOTER
   ========================================================= */
.spa-footer {
    position: relative;
    z-index: 80;
    height: 52px;
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255,255,255,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    flex-shrink: 0;
}

.spa-footer a {
    font-size: 13px;
    color: #4a5568;
    text-decoration: none;
    transition: color 0.15s;
}

.spa-footer a:hover {
    color: #0073aa;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1024px) {
    .apps-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 12px;
    }

    .spa-body {
        padding: 20px 32px;
    }
}

@media (max-width: 768px) {
    .apps-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
        gap: 10px;
    }

    .spa-body {
        padding: 16px;
    }

    .spa-header-center {
        max-width: 180px;
    }

    .btn-marketplace span {
        display: none;
    }

    .app-icon-wrapper {
        width: 56px;
        height: 56px;
        font-size: 28px;
        border-radius: 14px;
    }

    .app-card {
        padding: 14px 8px 12px;
    }

    .app-card-name {
        font-size: 11px;
    }

    .spa-floating-panel {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .spa-category-nav {
        padding: 12px 12px 0;
        gap: 4px;
        justify-content: flex-start;
    }

    .spa-cat-tab {
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* =========================================================
   AUTH OVERLAY — Form login/register nổi lên trong dashboard
   ========================================================= */
#scm-auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

#scm-auth-overlay .auth-card-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0,0,0,0.3);
    padding: 40px;
    box-sizing: border-box;
    animation: scmFadeIn 0.2s ease-out;
}

.auth-overlay-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    font-size: 18px;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.auth-overlay-close:hover {
    color: #1a202c;
    background: #f1f5f9;
}

#scm-auth-overlay .auth-card h2 {
    margin: 0 0 8px;
    color: #0f172a;
    font-size: 22px;
    font-weight: 700;
    text-align: center;
}
#scm-auth-overlay .auth-subtitle {
    margin: 0 0 28px;
    color: #64748b;
    font-size: 13px;
    text-align: center;
    line-height: 1.5;
}
#scm-auth-overlay .form-group {
    margin-bottom: 18px;
    position: relative;
}
#scm-auth-overlay .form-group label {
    display: block;
    margin-bottom: 6px;
    color: #334155;
    font-size: 13px;
    font-weight: 600;
}
#scm-auth-overlay .form-group input[type="text"],
#scm-auth-overlay .form-group input[type="email"],
#scm-auth-overlay .form-group input[type="password"] {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    color: #0f172a;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}
#scm-auth-overlay .form-group input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 3px rgba(0,115,170,0.12);
}
#scm-auth-overlay .password-input-wrapper {
    position: relative;
}
#scm-auth-overlay .toggle-password-icon {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #94a3b8;
    font-size: 16px;
    user-select: none;
}
#scm-auth-overlay .form-utility-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 13px;
}
#scm-auth-overlay .remember-me-label {
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}
#scm-auth-overlay .form-utility-row a,
#scm-auth-overlay .auth-footer-redirect a {
    color: #0073aa;
    text-decoration: none;
    font-weight: 600;
}
#scm-auth-overlay .form-utility-row a:hover,
#scm-auth-overlay .auth-footer-redirect a:hover {
    text-decoration: underline;
}
#scm-auth-overlay .btn-auth-submit {
    width: 100%;
    padding: 13px;
    background: #0073aa;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
#scm-auth-overlay .btn-auth-submit:hover { background: #005a87; }
#scm-auth-overlay .btn-auth-submit:disabled { background: #94a3b8; cursor: not-allowed; }
#scm-auth-overlay .auth-footer-redirect {
    margin-top: 24px;
    text-align: center;
    font-size: 13px;
    color: #64748b;
}
.auth-alert-box {
    margin-top: 16px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    font-weight: 500;
}
.auth-alert-box.alert-success { background:#f0fdf4; color:#166534; border:1px solid #bbf7d0; }
.auth-alert-box.alert-error   { background:#fef2f2; color:#991b1b; border:1px solid #fca5a5; }
