/**
 * WordPress Auto Post CRM — SaaS design system (Bootstrap 5 extension)
 * 8px grid, neutral + primary, Inter/system stack
 */

:root {
    --saas-bg: #f4f6f9;
    --saas-surface: #ffffff;
    --saas-border: #e8ecf1;
    --saas-text: #1a1d26;
    --saas-muted: #5c6370;
    --saas-primary: #2563eb;
    --saas-primary-soft: rgba(37, 99, 235, 0.1);
    --saas-success: #059669;
    --saas-danger: #dc2626;
    --saas-warning: #d97706;
    --saas-radius: 10px;
    --saas-radius-sm: 8px;
    --saas-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
    --saas-shadow-lg: 0 4px 24px rgba(15, 23, 42, 0.08);
    --saas-sidebar-w: 272px;
    --saas-sidebar-collapsed: 72px;
    --saas-topbar-h: 60px;
    --saas-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Base */
body.saas-app {
    font-family: var(--saas-font);
    background: var(--saas-bg);
    color: var(--saas-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Layout shell */
.saas-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.saas-sidebar {
    width: var(--saas-sidebar-w);
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    transition: width 0.22s ease, transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
}

.saas-app.sidebar-collapsed .saas-sidebar {
    width: var(--saas-sidebar-collapsed);
}

.saas-app.sidebar-collapsed .saas-brand-text,
.saas-app.sidebar-collapsed .saas-nav-label,
.saas-app.sidebar-collapsed .saas-sidebar-section-title,
.saas-app.sidebar-collapsed .saas-site-picker label,
.saas-app.sidebar-collapsed .saas-site-picker select {
    opacity: 0;
    width: 0;
    height: 0;
    overflow: hidden;
    position: absolute;
}

.saas-app.sidebar-collapsed .saas-brand {
    justify-content: center;
}

.saas-sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 16px 12px;
    overflow: hidden auto;
}

.saas-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px 16px;
    text-decoration: none;
    color: #fff !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 8px;
}

.saas-brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--saas-primary), #7c3aed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.saas-brand-text .saas-product-name {
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.saas-brand-text .saas-product-sub {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}

.saas-workspace-pill {
    font-size: 0.75rem;
    color: #94a3b8;
    padding: 8px;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.saas-site-picker {
    margin-bottom: 16px;
}

.saas-site-picker select {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
    border-radius: var(--saas-radius-sm);
    font-size: 0.8125rem;
}

.saas-site-picker label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 6px;
}

.saas-sidebar-section-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 8px 10px 4px;
}

.saas-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.saas-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--saas-radius-sm);
    color: #cbd5e1 !important;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.saas-nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff !important;
}

.saas-nav-link.active {
    background: rgba(37, 99, 235, 0.25);
    color: #fff !important;
}

.saas-nav-link i {
    font-size: 1.1rem;
    opacity: 0.9;
    width: 1.25rem;
    text-align: center;
}

.saas-sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.saas-btn-logout {
    width: 100%;
    border-radius: var(--saas-radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: transparent;
    color: #e2e8f0;
    padding: 8px 12px;
    font-size: 0.8125rem;
    transition: background 0.15s ease;
}

.saas-btn-logout:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

/* Main column */
.saas-main {
    flex: 1;
    margin-left: var(--saas-sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.22s ease;
}

.saas-app.sidebar-collapsed .saas-main {
    margin-left: var(--saas-sidebar-collapsed);
}

/* Topbar */
.saas-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--saas-topbar-h);
    background: var(--saas-surface);
    border-bottom: 1px solid var(--saas-border);
    display: flex;
    align-items: center;
    padding: 0 16px 0 8px;
    gap: 12px;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.saas-sidebar-toggle {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: var(--saas-radius-sm);
    color: var(--saas-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.saas-sidebar-toggle:hover {
    background: var(--saas-bg);
    color: var(--saas-text);
}

.saas-search-form {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.saas-search-form .form-control {
    padding-left: 40px;
    border-radius: 999px;
    border: 1px solid var(--saas-border);
    background: var(--saas-bg);
    font-size: 0.875rem;
}

.saas-search-form .bi {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--saas-muted);
    pointer-events: none;
}

.saas-topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.saas-icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: var(--saas-radius-sm);
    color: var(--saas-muted);
    position: relative;
}

.saas-icon-btn:hover {
    background: var(--saas-bg);
    color: var(--saas-text);
}

.saas-user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 6px;
    border-radius: 999px;
    border: 1px solid var(--saas-border);
    background: var(--saas-surface);
    text-decoration: none;
    color: var(--saas-text) !important;
    font-size: 0.8125rem;
    font-weight: 500;
}

.saas-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--saas-primary-soft);
    color: var(--saas-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

/* Content */
.saas-content {
    flex: 1;
    padding: 24px;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* Page header */
.saas-page-header {
    margin-bottom: 24px;
}

.saas-page-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0 0 4px;
}

.saas-page-desc {
    color: var(--saas-muted);
    font-size: 0.875rem;
    margin: 0;
    max-width: 720px;
}

/* Stat cards */
.saas-stat-card {
    background: var(--saas-surface);
    border-radius: var(--saas-radius);
    border: 1px solid var(--saas-border);
    box-shadow: var(--saas-shadow);
    padding: 20px;
    height: 100%;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.saas-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--saas-shadow-lg);
}

.saas-stat-card .saas-stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: 12px;
}

.saas-stat-card .saas-stat-icon.primary {
    background: var(--saas-primary-soft);
    color: var(--saas-primary);
}
.saas-stat-card .saas-stat-icon.success {
    background: rgba(5, 150, 105, 0.12);
    color: var(--saas-success);
}
.saas-stat-card .saas-stat-icon.warning {
    background: rgba(217, 119, 6, 0.12);
    color: var(--saas-warning);
}
.saas-stat-card .saas-stat-icon.neutral {
    background: var(--saas-bg);
    color: var(--saas-muted);
}
.saas-stat-card .saas-stat-icon.danger {
    background: rgba(220, 38, 38, 0.12);
    color: var(--saas-danger);
}

.saas-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.saas-stat-label {
    font-size: 0.8125rem;
    color: var(--saas-muted);
    margin-top: 4px;
}

.saas-stat-trend {
    font-size: 0.75rem;
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.saas-stat-trend.up {
    color: var(--saas-success);
}
.saas-stat-trend.down {
    color: var(--saas-danger);
}
.saas-stat-trend.neutral {
    color: var(--saas-muted);
}

/* Cards */
.saas-card {
    background: var(--saas-surface);
    border-radius: var(--saas-radius);
    border: 1px solid var(--saas-border);
    box-shadow: var(--saas-shadow);
    overflow: hidden;
}

.saas-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--saas-border);
    font-weight: 600;
    font-size: 0.9375rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.saas-card-body {
    padding: 20px;
}

/* Tables */
.saas-table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    justify-content: space-between;
}

.saas-table-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.saas-table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.saas-table-wrap {
    background: var(--saas-surface);
    border-radius: var(--saas-radius);
    border: 1px solid var(--saas-border);
    box-shadow: var(--saas-shadow);
    overflow: hidden;
}

.saas-table-scroll {
    overflow-x: auto;
    max-width: 100%;
}

.saas-table {
    width: 100%;
    margin: 0;
    font-size: 0.875rem;
}

.saas-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    border-bottom: 2px solid var(--saas-border);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--saas-muted);
    padding: 12px 16px;
    white-space: nowrap;
}

.saas-table tbody td {
    padding: 14px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--saas-border);
}

.saas-table tbody tr {
    transition: background 0.12s ease;
}

.saas-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.04);
}

.saas-table tbody tr:last-child td {
    border-bottom: none;
}

.saas-table a {
    color: var(--saas-primary);
    font-weight: 500;
    text-decoration: none;
}

.saas-table a:hover {
    text-decoration: underline;
}

/* Pagination */
.saas-pagination-wrap {
    padding: 12px 16px;
    border-top: 1px solid var(--saas-border);
    background: #fafbfc;
}

.saas-pagination-wrap .pagination {
    margin: 0;
    justify-content: flex-end;
}

.saas-pagination-wrap .page-link {
    border-radius: 8px;
    margin: 0 2px;
    border: 1px solid var(--saas-border);
    color: var(--saas-text);
    font-size: 0.8125rem;
}

.saas-pagination-wrap .page-item.active .page-link {
    background: var(--saas-primary);
    border-color: var(--saas-primary);
}

/* Badges */
.saas-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Buttons */
.saas-btn {
    border-radius: var(--saas-radius-sm);
    font-weight: 600;
    font-size: 0.875rem;
    padding: 8px 16px;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.saas-btn:active {
    transform: scale(0.98);
}

/* SEO score ring */
.saas-seo-ring {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    margin: 0 auto 16px;
    display: grid;
    place-items: center;
    position: relative;
    background: conic-gradient(
        var(--saas-primary) calc(var(--pct, 0) * 1%),
        #e8ecf1 0
    );
}

.saas-seo-ring-inner {
    width: 92px;
    height: 92px;
    border-radius: 50%;
    background: var(--saas-surface);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--saas-text);
}

/* Checklist */
.saas-checklist {
    list-style: none;
    padding: 0;
    margin: 0;
}

.saas-checklist li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--saas-border);
    font-size: 0.8125rem;
}

.saas-checklist li:last-child {
    border-bottom: none;
}

.saas-checklist .bi-check-circle-fill {
    color: var(--saas-success);
    flex-shrink: 0;
}

.saas-checklist .bi-x-circle-fill {
    color: var(--saas-danger);
    flex-shrink: 0;
}

/* Draft editor layout */
.saas-draft-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
}

@media (min-width: 992px) {
    .saas-draft-grid {
        grid-template-columns: 1fr 380px;
        align-items: start;
    }
    .saas-draft-sidebar {
        position: sticky;
        top: calc(var(--saas-topbar-h) + 16px);
    }
}

/* Forms floating */
.form-floating > label {
    color: var(--saas-muted);
}

/* Empty state */
.saas-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--saas-muted);
}

.saas-empty i {
    font-size: 2.5rem;
    opacity: 0.35;
    margin-bottom: 12px;
}

/* Skeleton */
.saas-skeleton {
    background: linear-gradient(90deg, #f0f2f5 25%, #e8ecf1 50%, #f0f2f5 75%);
    background-size: 200% 100%;
    animation: saas-shimmer 1.2s infinite;
    border-radius: 8px;
}

@keyframes saas-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Toast container */
#saas-toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}

.saas-toast {
    background: var(--saas-surface);
    border: 1px solid var(--saas-border);
    border-radius: var(--saas-radius-sm);
    box-shadow: var(--saas-shadow-lg);
    padding: 12px 16px;
    font-size: 0.875rem;
    animation: saas-toast-in 0.28s ease;
}

@keyframes saas-toast-in {
    from {
        opacity: 0;
        transform: translateX(12px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Mobile */
@media (max-width: 991.98px) {
    .saas-sidebar {
        transform: translateX(-100%);
    }
    .saas-app.sidebar-open .saas-sidebar {
        transform: translateX(0);
    }
    .saas-main {
        margin-left: 0 !important;
    }
    .saas-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        z-index: 1035;
    }
    .saas-app.sidebar-open .saas-sidebar-backdrop {
        display: block;
    }
}

/* Chart container */
.saas-chart-box {
    height: 260px;
    position: relative;
}
