/* ================================================================
   PRIMEFORGE AI — GLOBAL RESPONSIVE SYSTEM
   Loaded last on every client page so every surface shares the same
   responsive behavior without changing product logic or page markup.
================================================================ */

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

*, *::before, *::after {
    min-width: 0;
}

img, video, canvas, svg {
    max-width: 100%;
}

input, textarea, select, button {
    max-width: 100%;
}

pre, code {
    max-width: 100%;
}

pre {
    overflow-x: auto;
    white-space: pre;
}

/* ---------- shared app shell ---------- */
@media (max-width: 900px) {
    .page-content,
    .content,
    .workspace-page,
    .templates-page,
    .history-page,
    .campaign-page,
    .business-page,
    .smart-campaign-page {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: none !important;
        padding-left: 20px !important;
        padding-right: 20px !important;
    }

    .sidebar {
        position: sticky !important;
        top: 0;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        padding: 14px 16px !important;
        flex-direction: column;
        gap: 10px;
        overflow: visible !important;
        z-index: 1000;
    }

    #sidebar {
        width: 100% !important;
        height: auto !important;
    }

    .sidebar h2 {
        margin: 0 4px 4px !important;
        font-size: 13px !important;
    }

    .sidebar nav {
        width: 100%;
        flex-direction: row !important;
        gap: 6px !important;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 2px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar nav::-webkit-scrollbar {
        display: none;
    }

    .sidebar nav a {
        flex: 0 0 auto;
        min-height: 38px !important;
        padding: 9px 11px !important;
        white-space: nowrap;
        font-size: 12px !important;
    }

    #logoutBtn {
        width: auto !important;
        align-self: flex-end;
        margin-top: 2px !important;
        padding: 8px 12px !important;
    }

    .cards,
    .biz-grid,
    .featured-grid,
    .category-grid,
    .template-grid,
    .tool-grid,
    .pricing-grid,
    .plan-grid,
    .workspace-grid,
    .campaign-grid,
    .campaign-card-grid,
    .project-grid,
    .project-detail-grid,
    .comparison-table,
    .roi-results,
    .upgrade-benefits {
        grid-template-columns: 1fr !important;
    }

    .workspace-grid {
        gap: 14px !important;
    }

    .workspace-form,
    .workspace-output {
        min-height: auto !important;
    }

    .workspace-form {
        padding: 20px !important;
    }

    .workspace-header h1,
    .page-header h1 {
        font-size: clamp(22px, 5vw, 28px) !important;
    }

    .biz-header,
    .biz-section-header,
    .project-detail-actions,
    .campaign-header,
    .output-header,
    .workflow-header {
        align-items: flex-start !important;
        flex-wrap: wrap !important;
    }

    .biz-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .biz-table th,
    .biz-table td {
        white-space: nowrap;
    }

    .biz-input,
    .biz-select,
    .role-select,
    .workspace-card input,
    .workspace-card textarea,
    .workspace-card select,
    .settings-form input,
    .settings-form textarea,
    .settings-form select {
        width: 100%;
        max-width: 100%;
    }

    .invite-form,
    .add-member-row,
    .project-detail-row,
    .project-detail-actions,
    .range-selector,
    .hero-buttons,
    .upgrade-buttons,
    .wizardButtons,
    .output-tools {
        width: 100%;
        flex-wrap: wrap;
    }

    .invite-form,
    .add-member-row,
    .project-detail-actions {
        gap: 10px;
    }

    .invite-form > *,
    .add-member-row > * {
        min-width: min(100%, 220px);
    }

    .btn-primary,
    .btn-remove,
    .btn-revoke,
    .create-btn,
    .wizardButtons button {
        min-height: 42px;
    }

    .recent,
    .biz-section,
    .workspace-form,
    .workspace-output,
    .campaign-builder,
    .campaign-preview,
    .biz-card,
    .card,
    .featured-card,
    .app-card,
    .tool-card,
    .plan-card,
    .roi-card {
        max-width: 100%;
    }
}

/* ---------- medium phones / tablets ---------- */
@media (max-width: 700px) {
    .page-content,
    .content,
    .workspace-page,
    .templates-page,
    .history-page,
    .campaign-page,
    .business-page {
        padding: 16px 14px 28px !important;
    }

    .sidebar {
        padding: 12px 12px !important;
    }

    .sidebar nav a {
        font-size: 11px !important;
        padding: 8px 10px !important;
    }

    .cards {
        margin-top: 18px !important;
    }

    .card {
        min-height: 118px !important;
        padding: 17px !important;
    }

    .card p {
        margin-top: 18px !important;
        font-size: clamp(28px, 9vw, 38px) !important;
    }

    .biz-section-header,
    .recent h2 {
        padding: 13px 14px !important;
    }

    .biz-section {
        margin-bottom: 16px !important;
    }

    .biz-card {
        padding: 14px !important;
    }

    .workspace-form {
        padding: 16px !important;
    }

    .workspace-header h1 {
        font-size: 22px !important;
    }

    .workspace-output {
        padding: 0 !important;
    }

    .history-page {
        display: block !important;
        background: var(--bg) !important;
        overflow: visible !important;
    }

    .history-list {
        height: auto !important;
        max-height: 42vh;
        margin-bottom: 14px;
    }

    .history-view {
        min-height: 55vh;
    }

    .campaign-builder,
    .campaign-preview,
    #wizardContent {
        padding: 14px !important;
    }

    .campaign-header-actions {
        position: static !important;
        width: 100%;
        justify-content: flex-start !important;
        margin-bottom: 10px;
    }

    .templates-page .page-header p {
        font-size: 12px !important;
    }

    .featured-card,
    .app-card,
    .tool-card,
    .plan-card {
        min-height: 0 !important;
    }

    .settings-modal {
        width: calc(100vw - 20px) !important;
        max-width: none !important;
        height: min(92vh, 760px) !important;
        max-height: 92vh !important;
    }

    .settings-body {
        grid-template-columns: 1fr !important;
        min-height: 0;
    }

    .settings-sidebar {
        flex-direction: row !important;
        overflow-x: auto;
        flex-wrap: nowrap !important;
        border-right: 0 !important;
        border-bottom: 1px solid var(--border) !important;
    }

    .settings-tab {
        flex: 0 0 auto !important;
        width: auto !important;
    }

    .settings-content {
        padding: 16px !important;
        overflow-y: auto;
    }

    .theme-options,
    .plan-grid {
        grid-template-columns: 1fr !important;
    }

    .danger-card {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px;
    }

    .pf-chat-panel {
        width: min(94vw, 420px) !important;
        right: 3vw !important;
        left: auto !important;
    }
}

/* ---------- small phones ---------- */
@media (max-width: 480px) {
    .page-content,
    .content,
    .workspace-page,
    .templates-page,
    .history-page,
    .campaign-page,
    .business-page {
        padding: 12px 10px 24px !important;
    }

    .sidebar {
        padding: 10px !important;
    }

    .sidebar h2 {
        font-size: 12px !important;
    }

    .sidebar nav a {
        min-height: 36px !important;
        padding: 8px 9px !important;
        font-size: 10px !important;
    }

    #logoutBtn {
        font-size: 10px !important;
    }

    .content h1,
    .biz-header h1,
    .page-header h1 {
        font-size: 21px !important;
    }

    .content h1::after {
        margin-top: 7px !important;
        font-size: 9px !important;
    }

    .card {
        min-height: 108px !important;
        padding: 14px !important;
    }

    .card p {
        font-size: 28px !important;
    }

    .biz-card p {
        font-size: 18px !important;
    }

    .btn-primary,
    .btn-remove,
    .btn-revoke,
    .create-btn,
    .wizardButtons button,
    .hero-buttons > *,
    .upgrade-buttons > * {
        width: 100%;
    }

    .invite-form > *,
    .add-member-row > * {
        min-width: 100%;
        width: 100%;
    }

    .range-selector {
        overflow-x: auto;
        flex-wrap: nowrap !important;
    }

    .range-btn {
        flex: 0 0 auto;
    }

    .settings-modal {
        width: calc(100vw - 12px) !important;
        height: calc(100vh - 12px) !important;
        max-height: calc(100vh - 12px) !important;
    }

    .settings-content {
        padding: 13px !important;
    }

    .pf-chat-panel {
        width: calc(100vw - 20px) !important;
        right: 10px !important;
        bottom: 10px !important;
    }
}

/* ---------- authentication ---------- */
@media (max-width: 960px) {
    .auth-container {
        grid-template-columns: 1fr !important;
    }

    .auth-left {
        padding: 28px 24px !important;
        border-right: 0 !important;
        border-bottom: 1px solid var(--auth-border) !important;
    }

    .auth-right {
        padding: 28px 20px !important;
    }

    .auth-card {
        width: 100%;
        max-width: 520px !important;
    }

    .pf-footer-container {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 560px) {
    .auth-left {
        padding: 22px 16px !important;
    }

    .auth-right {
        padding: 18px 12px !important;
    }

    .auth-card {
        padding: 20px 16px !important;
    }

    .brand h1 {
        font-size: 25px !important;
    }

    .hero-text h2 {
        font-size: 24px !important;
    }

    .pf-footer {
        padding: 40px 16px !important;
    }

    .pf-footer-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 24px !important;
    }
}

/* ---------- legacy app / upgrade surfaces ---------- */
@media (max-width: 900px) {
    .app-container {
        height: auto !important;
        min-height: 100vh;
        overflow: visible !important;
        flex-direction: column !important;
    }

    .app-container > .sidebar {
        width: 100% !important;
        height: auto !important;
    }

    .app-header,
    .generator-card,
    .result-card,
    .upgrade-page > * {
        max-width: 100% !important;
    }

    .app-header {
        padding: 20px !important;
        flex-wrap: wrap;
        gap: 12px;
    }

    .generator-card,
    .result-card {
        margin-left: 16px !important;
        margin-right: 16px !important;
    }

    .upgrade-page {
        width: 100% !important;
        padding: 24px 16px !important;
    }

    .upgrade-header,
    .hero {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .hero-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .comparison-section,
    .comparison-table {
        overflow-x: auto !important;
    }
}

@media (max-width: 480px) {
    .hero-stats {
        grid-template-columns: 1fr !important;
    }
}

/* ---------- landing page ---------- */
@media (max-width: 900px) {
    .section-wrap,
    .site-header {
        width: min(calc(100% - 40px), var(--max)) !important;
    }

    .hero {
        grid-template-columns: 1fr !important;
        min-height: 0 !important;
        gap: 28px !important;
    }

    .hero-copy {
        max-width: 760px;
    }

    .hero-stage {
        min-height: 500px !important;
    }

    .intro-grid {
        grid-template-columns: 1fr !important;
    }

    .business-panel {
        grid-template-columns: 1fr !important;
    }

    .business-orbit {
        opacity: .72;
    }

    .site-footer {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }
}

@media (max-width: 720px) {
    .section-wrap,
    .site-header {
        width: calc(100% - 28px) !important;
    }

    .site-header {
        height: 68px !important;
    }

    .desktop-nav,
    .site-header .text-link,
    .site-header .button-small {
        display: none !important;
    }

    .menu-toggle {
        display: flex !important;
    }

    .hero {
        padding: 54px 0 42px !important;
    }

    .hero h1 {
        font-size: clamp(43px, 13vw, 68px) !important;
        line-height: .94 !important;
    }

    .hero-lede {
        font-size: 15px !important;
        line-height: 1.65 !important;
    }

    .hero-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .hero-actions .button {
        width: 100%;
    }

    .hero-stage {
        min-height: 390px !important;
        margin-top: 0 !important;
    }

    .creative-window {
        transform: none !important;
        width: 100% !important;
    }

    .window-body {
        grid-template-columns: 34px 1fr !important;
        min-height: 285px !important;
    }

    .window-sidebar {
        gap: 15px !important;
    }

    .campaign-canvas {
        padding: 26px 20px !important;
    }

    .campaign-canvas h2 {
        font-size: clamp(25px, 8vw, 34px) !important;
    }

    .floating-card {
        transform: scale(.78) !important;
    }

    .card-copy {
        left: -25px !important;
    }

    .card-media {
        right: -25px !important;
    }

    .intro,
    .business,
    .closing {
        padding-top: 70px !important;
        padding-bottom: 70px !important;
    }

    .intro h2,
    .workflow h2,
    .business h2 {
        font-size: clamp(38px, 10vw, 52px) !important;
    }

    .capability-grid {
        grid-template-columns: 1fr !important;
    }

    .business-panel {
        min-height: 0 !important;
    }

    .business-copy {
        padding: 36px 22px !important;
    }

    .business-orbit {
        width: 320px !important;
        height: 320px !important;
        right: -135px !important;
        top: 300px !important;
    }

    .closing h2 {
        font-size: clamp(44px, 12vw, 60px) !important;
    }
}

@media (max-width: 420px) {
    .section-wrap,
    .site-header {
        width: calc(100% - 22px) !important;
    }

    .hero {
        padding-top: 42px !important;
    }

    .hero h1 {
        font-size: clamp(39px, 12.5vw, 54px) !important;
    }

    .hero-stage {
        min-height: 320px !important;
    }

    .window-sidebar {
        display: none !important;
    }

    .window-body {
        grid-template-columns: 1fr !important;
    }

    .campaign-canvas {
        padding: 22px 17px !important;
    }

    .floating-card {
        display: none !important;
    }

    .signal-strip {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* ---------- reduced motion / touch ---------- */
@media (hover: none) and (pointer: coarse) {
    .button:hover,
    .tab-btn:hover,
    .card:hover,
    .biz-card:hover,
    .featured-card:hover,
    .history-item:hover {
        transform: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
