/* ================================
   DESKTOP ENHANCEMENT FRAMEWORK
   ================================ */

/* Enhanced Container Sizing for Different Screen Sizes */
.container {
    max-width: 1000px; /* Default for small screens */
    width: 100%;
    margin: 0 auto;
}

/* ================================
   PROGRESSIVE ENHANCEMENT BREAKPOINTS
   ================================ */

/* Large screens stay intentionally compact. The original rules expanded every
   page at each desktop breakpoint, making the application feel zoomed in. */
@media (min-width: 1024px) {
    .container {
        max-width: 1080px;
        padding: 20px 32px;
    }
    
    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 25px;
    }
    
    .header-section {
        padding: 56px 40px 40px;
    }
    
    .content-section {
        padding: 40px;
    }
    
    h1 {
        font-size: clamp(2.2rem, 3vw, 3rem);
    }
    
    .subtitle {
        font-size: 1.15rem;
        max-width: 700px;
    }
}

/* Standard Desktops (1200px - 1439px) */
@media (min-width: 1200px) {
    .container {
        max-width: 1120px;
        padding: 20px 36px;
    }
    
    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 30px;
        max-width: 1000px;
        margin: 0 auto 40px;
    }
    
    .header-section {
        padding: 60px 44px 44px;
    }
    
    .content-section {
        padding: 44px;
    }
    
    .action-buttons {
        max-width: 800px;
        margin: 40px auto 0;
    }
    
    .ai-callout,
    .disclaimer {
        max-width: 900px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Large Desktops (1440px - 1919px) */
@media (min-width: 1440px) {
    .container {
        max-width: 1120px;
        padding: 20px 36px;
    }
    
    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
        gap: 35px;
        max-width: 1200px;
    }
    
    .header-section {
        padding: 64px 44px 46px;
    }
    
    .content-section {
        padding: 44px;
    }
    
    h1 {
        font-size: clamp(2.35rem, 3vw, 3.1rem);
    }
    
    .subtitle {
        font-size: 1.15rem;
        max-width: 800px;
    }
    
    .action-buttons {
        max-width: 1000px;
    }
    
    .btn {
        padding: 14px 26px;
        font-size: 1rem;
    }
}

/* Ultra-wide & 4K Screens (1920px+) */
@media (min-width: 1920px) {
    .container {
        max-width: 1120px;
        padding: 20px 36px;
    }
    
    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
        gap: 40px;
        max-width: 1400px;
    }
    
    .header-section {
        padding: 64px 44px 46px;
    }
    
    .content-section {
        padding: 44px;
    }
    
    h1 {
        font-size: clamp(2.35rem, 3vw, 3.1rem);
    }
    
    .subtitle {
        font-size: 1.15rem;
        max-width: 900px;
    }
    
    .feature-card {
        padding: 28px;
    }
    
    .feature-icon {
        font-size: 2.5rem;
    }
    
    .feature-title {
        font-size: 1.3rem;
    }
    
    .feature-desc {
        font-size: 1rem;
    }
}

/* ================================
   GRID IMPROVEMENTS
   ================================ */

/* Prevent too many columns on ultra-wide screens */
.features-grid {
    display: grid;
    gap: 20px;
    margin-bottom: 40px;
}

/* Ensure grids never exceed 4 columns */
@media (min-width: 1200px) {
    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        max-width: calc(4 * 280px + 3 * 30px); /* Max 4 columns with gaps */
    }
}

/* ================================
   FORM & INPUT SCALING
   ================================ */

@media (min-width: 1200px) {
    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 1.1rem;
        padding: 14px 18px;
    }
    
    .btn-group {
        max-width: 600px;
        margin: 0 auto;
    }
}

@media (min-width: 1440px) {
    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 1rem;
        padding: 14px 18px;
    }
}

/* ================================
   CONTENT SPECIFIC IMPROVEMENTS
   ================================ */

/* Navigation improvements for larger screens */
@media (min-width: 1200px) {
    .navigation {
        max-width: 800px;
        margin: 0 auto;
    }
    
    .nav-button {
        padding: 14px 24px;
        font-size: 1.05rem;
    }
}

/* Progress tracking improvements */
@media (min-width: 1200px) {
    .progress-container {
        max-width: 1000px;
        margin: 0 auto;
    }
    
    .phase-card {
        padding: 30px;
    }
}

/* Modal and overlay improvements */
@media (min-width: 1200px) {
    .modal-content {
        max-width: 800px;
        padding: 40px;
    }
}

@media (min-width: 1440px) {
    .modal-content {
        max-width: 900px;
        padding: 50px;
    }
}

/* ================================
   TYPOGRAPHY SCALING
   ================================ */

@media (min-width: 1200px) {
    body {
        font-size: 16px;
        line-height: 1.6;
    }
    
    h2 {
        font-size: clamp(1.8rem, 2.5vw, 2.2rem);
    }
    
    h3 {
        font-size: clamp(1.4rem, 2vw, 1.8rem);
    }
}

@media (min-width: 1440px) {
    body {
        font-size: 16px;
        line-height: 1.6;
    }
}

@media (min-width: 1920px) {
    body {
        font-size: 16px;
        line-height: 1.6;
    }
}

/* ================================
   SPACING OPTIMIZATIONS
   ================================ */

@media (min-width: 1200px) {
    .mode-toggle-section {
        padding: 40px 50px;
    }
    
    .disclaimer {
        margin: 30px auto 0;
        max-width: 900px;
    }
}

@media (min-width: 1440px) {
    .mode-toggle-section {
        padding: 50px 60px;
    }
    
    .disclaimer {
        margin: 40px auto 0;
        max-width: 1000px;
    }
}

/* ================================
   UTILITY CLASSES
   ================================ */

/* Center content on large screens */
.desktop-center {
    max-width: 1200px;
    margin: 0 auto;
}

/* Responsive padding */
.responsive-padding {
    padding: 20px;
}

@media (min-width: 1024px) {
    .responsive-padding {
        padding: 40px;
    }
}

@media (min-width: 1440px) {
    .responsive-padding {
        padding: 40px;
    }
}

@media (min-width: 1920px) {
    .responsive-padding {
        padding: 40px;
    }
}

/* ================================
   PERFORMANCE OPTIMIZATIONS
   ================================ */

/* Smooth transitions for all screen sizes */
button, a, input, textarea, select {
    transition: color 0.2s ease, background-color 0.2s ease,
                border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

/* Optimized animations for larger screens */
@media (min-width: 1200px) {
    .feature-card:hover {
        transform: translateY(-8px);
    }
    
    .btn:hover {
        transform: translateY(-3px);
    }
}

/* ================================
   THEME TOGGLE POSITIONING
   ================================ */

@media (min-width: 1200px) {
    .theme-toggle {
        top: 30px;
        right: 30px;
        padding: 14px 20px;
    }
}

@media (min-width: 1440px) {
    .theme-toggle {
        top: 40px;
        right: 40px;
        padding: 16px 24px;
    }
}

/* ================================
   ACCESSIBILITY IMPROVEMENTS
   ================================ */

/* Better focus indicators on larger screens */
@media (min-width: 1200px) {
    .btn:focus,
    input:focus,
    textarea:focus,
    select:focus {
        outline: 3px solid var(--text-hover);
        outline-offset: 3px;
    }
}

/* ================================
   PRINT OPTIMIZATIONS
   ================================ */

@media print {
    .container {
        max-width: none;
        padding: 20px;
        box-shadow: none;
        background: white !important;
    }
    
    .theme-toggle {
        display: none;
    }
    
    .features-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

/* ================================
   SHARED SYSTEM HEADER + LAYERS
   (nav-component.js)
   ================================ */

:root {
    --layer-chat: 300;
    --layer-header: 500;
    --layer-modal: 1000;
}

html[data-discern-section="repair"] {
    --bg-primary: linear-gradient(135deg, #132238 0%, #2f6f73 100%);
    --accent-primary: #5b4b8a;
    --accent-secondary: #2f6f73;
}

html[data-discern-section="liberate"] {
    --bg-primary: linear-gradient(135deg, #4f3438 0%, #a45a52 100%);
    --accent-primary: #a45a52;
    --accent-secondary: #7f4b59;
    --border-color: rgba(164, 90, 82, 0.24);
    --shadow-hover: rgba(164, 90, 82, 0.3);
}

html[data-theme="dark"][data-discern-section="repair"] {
    --bg-primary: linear-gradient(135deg, #0b1422 0%, #173f43 100%);
}

html[data-theme="dark"][data-discern-section="liberate"] {
    --bg-primary: linear-gradient(135deg, #251b22 0%, #573b40 100%);
    --accent-primary: #df938a;
    --accent-secondary: #bd7882;
}

/* Pathway semantics: one shared DISCERN language, two unmistakable routes. */
html[data-discern-section="repair"] .btn-primary,
html[data-discern-section="repair"] .protocol-badge,
html[data-discern-section="repair"] .header-title,
html[data-discern-section="repair"] .step-circle.active,
html[data-discern-section="repair"] .phase-nav-item.active {
    background: linear-gradient(135deg, var(--pathway-primary), var(--pathway-secondary)) !important;
    box-shadow: 0 5px 18px var(--pathway-glow) !important;
}

html[data-discern-section="liberate"] .btn-primary,
html[data-discern-section="liberate"] .protocol-badge,
html[data-discern-section="liberate"] .header-title,
html[data-discern-section="liberate"] .phase-number,
html[data-discern-section="liberate"] .phase-nav-item.active {
    background: linear-gradient(135deg, var(--pathway-primary), var(--pathway-secondary)) !important;
    box-shadow: 0 5px 18px var(--pathway-glow) !important;
}

html[data-discern-section="repair"] .header h1,
html[data-discern-section="liberate"] .header h1 {
    background: linear-gradient(135deg, var(--pathway-primary), var(--pathway-secondary)) !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
}

html[data-discern-section="repair"] input:focus,
html[data-discern-section="repair"] textarea:focus,
html[data-discern-section="repair"] select:focus,
html[data-discern-section="liberate"] input:focus,
html[data-discern-section="liberate"] textarea:focus,
html[data-discern-section="liberate"] select:focus {
    border-color: var(--pathway-secondary) !important;
    box-shadow: 0 0 0 3px var(--pathway-glow) !important;
}

nav.system-header {
    width: auto;
    max-width: none;
    margin-inline: 0;
    background: var(--bg-secondary);
    backdrop-filter: var(--backdrop-blur);
    padding: 0;
    box-shadow: 0 1px 0 var(--border-color);
    position: sticky;
    top: 0;
    z-index: var(--layer-header);
    border: 0;
}

.system-header-row {
    width: 100%;
    max-width: none;
    min-height: 62px;
    margin: 0 auto;
    padding: 8px clamp(18px, 3vw, 42px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 16px;
}

.system-brand {
    grid-column: 2;
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.28em;
    text-decoration: none;
    white-space: nowrap;
}

.system-home {
    grid-column: 1;
    justify-self: start;
}

.system-header .system-theme-toggle {
    grid-column: 3;
    justify-self: end;
    position: static !important;
    inset: auto !important;
    z-index: auto !important;
    width: auto !important;
    min-width: 118px;
    max-width: none !important;
    margin: 0 !important;
    padding: 9px 14px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 999px !important;
    background: var(--bg-glass) !important;
    box-shadow: none !important;
    color: var(--text-primary) !important;
    font: 700 0.83rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
    white-space: nowrap;
    transform: none !important;
}

.system-theme-icon {
    font-size: 1rem;
    line-height: 1;
    opacity: 0.72;
}

.system-header .system-theme-toggle[aria-pressed="false"] .system-theme-icon:first-child,
.system-header .system-theme-toggle[aria-pressed="true"] .system-theme-icon:last-child {
    color: var(--accent-secondary);
    opacity: 1;
}

.system-header .system-theme-toggle:hover,
.system-header .system-theme-toggle:focus-visible {
    background: var(--bg-glass-hover) !important;
    color: var(--text-primary) !important;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.16) !important;
    outline: none;
}

.system-context-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 5px max(18px, calc((100% - 1060px) / 2 + 18px));
    overflow-x: auto;
    border-top: 1px solid var(--border-color);
    scrollbar-width: thin;
}

.system-header .nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 8px 11px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.system-header .nav-link:hover {
    background: var(--bg-glass-hover);
    color: var(--text-hover);
}

.system-header .nav-link.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    cursor: default;
}

.system-header .nav-link.active:hover {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.ai-nav-link {
    background: linear-gradient(135deg, #3e7c59 0%, #2f6f73 100%);
    color: white;
    padding: 10px 20px;
    font-weight: 700;
    box-shadow: 0 2px 10px rgba(47, 111, 115, 0.26);
}

.ai-nav-link:hover {
    background: linear-gradient(135deg, #356a4c 0%, #285d60 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(47, 111, 115, 0.34);
}

.nav-api-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
}

@media (max-width: 640px) {
    .system-header-row {
        min-height: 56px;
        padding: 7px 12px;
        gap: 8px;
    }

    .system-brand { font-size: 0.92rem; letter-spacing: 0.18em; }
    .system-header .system-theme-toggle { min-width: 94px; padding: 8px 9px !important; font-size: 0.76rem !important; }
    .system-header .system-home { padding: 8px 6px; font-size: 0.86rem; }
    .system-context-nav { justify-content: flex-start; min-height: 42px; padding: 4px 12px; }
    .system-context-nav .nav-link { padding: 7px 9px; font-size: 0.84rem; }
}


/* ================================
   SHARED CHAT WIDGET COMPONENT
   (chat-widget.js)
   ================================ */

.floating-chat-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    color: white;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: var(--layer-chat) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    animation: chat-pulse 2s infinite;
}

@keyframes chat-pulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.1); }
}

.floating-chat-button:hover {
    transform: scale(1.15);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.floating-chat-button.hidden { display: none; }

.chat-widget-panel {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 400px;
    height: 600px;
    background: var(--bg-secondary);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    transform: translateY(calc(100% + 60px));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: var(--layer-chat) !important;
    overflow: hidden;
}

/* REPAIR has a legacy chat implementation; keep it on the same system layer. */
.agent-panel {
    z-index: var(--layer-chat) !important;
}

/* Every known modal family must remain above every chat implementation. */
.modal,
.api-config-modal,
.ai-analysis-overlay {
    z-index: var(--layer-modal) !important;
}

/* REPAIR's connection badge is useful, but must not cover the system header. */
.ai-status-badge {
    top: 118px !important;
    z-index: calc(var(--layer-header) - 1) !important;
}

.notification {
    top: 118px !important;
    z-index: calc(var(--layer-header) - 1) !important;
}

@media (max-width: 640px) {
    .ai-status-badge {
        top: 104px !important;
        right: 12px !important;
    }

    .notification { top: 104px !important; }
}

.chat-widget-panel.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.chat-widget-panel.maximized {
    width: 90vw;
    max-width: 1200px;
    height: 90vh;
    bottom: 5vh;
    right: 5vw;
}

.chat-widget-header {
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 20px 20px 0 0;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1.1rem;
}

.chat-icon { font-size: 1.5rem; }

.chat-header-actions { display: flex; gap: 0.5rem; }

.chat-action-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 1.2rem;
}

.chat-action-btn:hover { background: rgba(255, 255, 255, 0.3); }

.chat-widget-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg-secondary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: transparent;
    min-height: 300px;
    max-height: 400px;
}

.chat-message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    align-items: flex-start;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.chat-avatar.user {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

.chat-bubble {
    background: var(--bg-glass);
    backdrop-filter: var(--backdrop-blur);
    padding: 0.875rem 1.125rem;
    border-radius: 16px;
    max-width: 75%;
    line-height: 1.5;
    color: var(--text-primary);
}

.chat-bubble.assistant { border-top-left-radius: 4px; }
.chat-bubble.user { border-top-right-radius: 4px; margin-left: auto; }

.chat-input-area {
    padding: 0 1rem 1rem 1rem;
    background: var(--bg-secondary);
    display: flex;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-glass);
    backdrop-filter: var(--backdrop-blur);
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    min-height: 80px;
    font-family: inherit;
    transition: all 0.2s ease;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input::placeholder { color: var(--text-tertiary); }

.send-button {
    width: 48px;
    height: 48px;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
    align-self: flex-end;
}

.send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

@media (max-width: 768px) {
    .chat-widget-panel {
        width: calc(100vw - 40px);
        height: calc(100vh - 40px);
        bottom: 20px;
        right: 20px;
    }

    .floating-chat-button {
        bottom: 20px;
        right: 20px;
    }
}
