/* ============================================
   Shared UI Primitives — FundSignal & AuthorPilot
   ============================================ */

/* ── Toast Container ────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 14px 20px;
    font-size: 0.82rem;
    color: #e2e8f0;
    max-width: 360px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.toast-success {
    border-left: 3px solid #22c55e;
}

.toast.toast-error {
    border-left: 3px solid #ef4444;
}

.toast.toast-loading {
    border-left: 3px solid #60a5fa;
}

.toast.toast-info {
    border-left: 3px solid #94a3b8;
}

.toast .toast-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* ── Button Loading State ──────────────────── */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.btn-loading::before {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ── Accessibility ────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

[aria-live="polite"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles */
:focus-visible {
    outline: 2px solid #22c55e;
    outline-offset: 2px;
}

/* ── Mobile Tap Targets ────────────────────── */
@media (max-width: 640px) {
    button,
    a.btn,
    .btn,
    input[type="submit"],
    .sidebar-item,
    .nav-links a {
        min-height: 44px;
        min-width: 44px;
    }

    /* Sidebar icon-only mode */
    .sidebar {
        width: 56px !important;
    }

    .sidebar-item .label-text {
        display: none;
    }

    .sidebar-item {
        justify-content: center;
        padding: 8px 0;
    }

    /* Header stacking */
    .header {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 16px !important;
        gap: 8px;
    }

    .header-left,
    .header-right {
        flex-wrap: wrap;
    }

    /* Stats grid 2-column */
    .stats-grid,
    .widgets-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Filters bar stacking */
    .filters-bar {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* Main content padding */
    .main {
        padding: 16px !important;
    }

    /* Tables horizontal scroll */
    .table-scroll-wrapper {
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Lead cards flex-wrap */
    .card-meta {
        flex-wrap: wrap;
    }
}

/* ── Hamburger Menu ────────────────────────── */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    color: #e2e8f0;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    min-height: 44px;
    min-width: 44px;
    align-items: center;
    justify-content: center;
}

@media (max-width: 640px) {
    .hamburger-btn {
        display: flex;
    }

    .nav-links {
        display: none !important;
    }

    .nav-links.open {
        display: flex !important;
        flex-direction: column;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: rgba(10, 15, 30, 0.98);
        border-bottom: 1px solid rgba(255, 255, 255, 0.07);
        padding: 16px;
        gap: 4px;
    }
}

/* ── Loading Overlay ──────────────────────── */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 15, 30, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    border-radius: inherit;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #22c55e;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ── Form Validation ──────────────────────── */
.form-input.error {
    border-color: #ef4444;
}

.form-error {
    color: #ef4444;
    font-size: 0.78rem;
    margin-top: 4px;
    display: none;
}

.form-error.show {
    display: block;
}

input[aria-describedby="errorMsg"] {
    border-color: #ef4444;
}

/* ── Disabled Elements ─────────────────────── */
[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Skip Link ─────────────────────────────── */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #22c55e;
    color: #011a0d;
    padding: 8px 16px;
    z-index: 10000;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}