/* assets/css/main.css - KOMPLETT version med SPA integration och scroll-fix */

/* Font Face */
@font-face {
    font-family: 'Skierfe Logo';
    src: url('../fonts/logo.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Base Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #fafafa;
    color: #333;
    line-height: 1.6;
    transition: all 0.3s ease;
}

/* Layout */
.container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* Typography */
.logo {
    font-family: 'Skierfe Logo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1.5rem;
    font-weight: normal;
    color: #2c3e50;
    letter-spacing: -0.02em;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
    font-weight: 500;
    color: #2c3e50;
}

/* Form Elements */
input, textarea, select, button {
    font-family: inherit;
}

textarea {
    resize: vertical;
}

/* Focus States */
input:focus,
textarea:focus,
select:focus,
button:focus {
    outline: none;
}

/* Text Selection */
::selection {
    background: #e67e22;
    color: white;
}

::-moz-selection {
    background: #e67e22;
    color: white;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Code Font Family */
.code-input,
.results-output,
.code-output {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
}

/* Utility Classes */
.hide {
    display: none !important;
}

.show {
    display: block !important;
}

.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

/* Transitions */
.transition {
    transition: all 0.2s ease;
}

.transition-slow {
    transition: all 0.3s ease;
}

/* Color Variables (CSS Custom Properties) */
:root {
    --primary-color: #e67e22;
    --primary-dark: #d35400;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-muted: #95a5a6;
    --background: #fafafa;
    --background-card: white;
    --border-color: #ecf0f1;
    --border-hover: #e67e22;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --error-color: #e74c3c;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.15);
}

/* Base Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-in {
    animation: slideIn 0.3s ease;
}

/* Loading States */
.loading {
    position: relative;
    overflow: hidden;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.6),
        transparent
    );
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* ============================= */
/* SCROLL FIX - KRITISK SEKTION */
/* ============================= */

/* SCROLL FIX: Ensure proper overflow handling */
html {
    /* Never set overflow: hidden on html unless absolutely necessary */
    overflow-x: auto;
    overflow-y: auto;
}

body {
    /* Default overflow behavior - VIKTIGT för scroll-fix */
    overflow-x: auto;
    overflow-y: auto;
}

/* Language overlay specific fixes */
.language-overlay {
    /* Overlay should not interfere with body scroll */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow-y: auto; /* Allow scrolling within overlay if needed */
}

.language-overlay.show {
    opacity: 1;
    visibility: visible;
}

.language-overlay.hide {
    opacity: 0;
    visibility: hidden;
}

.language-content {
    /* Ensure content doesn't cause overflow issues */
    max-height: 95vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* iOS Safari fix */
}

/* Emergency scroll fix utility classes */
.force-scroll-enabled {
    overflow: auto !important;
}

.force-scroll-enabled body {
    overflow: auto !important;
}

/* Debug utility for scroll issues */
.debug-scroll {
    border: 2px solid red !important;
}

.debug-scroll::before {
    content: 'SCROLL DEBUG';
    position: fixed;
    top: 0;
    right: 0;
    background: red;
    color: white;
    padding: 4px 8px;
    z-index: 9999;
    font-size: 12px;
}

/* Ensure overlays don't break scroll */
.auth-overlay,
.limit-overlay,
.language-overlay {
    /* Use transform instead of changing body overflow when possible */
    transform: translateZ(0); /* Force hardware acceleration */
    contain: layout style paint; /* Ensure proper stacking context */
}

/* Side menu shouldn't affect main page scroll */
.side-menu.open ~ .container {
    /* Don't change overflow, just prevent interaction */
    pointer-events: none;
}

.side-menu-overlay.show {
    /* Only block interaction, not scroll */
    pointer-events: auto;
    touch-action: none; /* Prevent touch scrolling on overlay */
}

/* Emergency scroll fix animation */
@keyframes scroll-fix-flash {
    0% { background-color: rgba(39, 174, 96, 0.2); }
    50% { background-color: rgba(39, 174, 96, 0.5); }
    100% { background-color: transparent; }
}

.scroll-fix-applied {
    animation: scroll-fix-flash 0.5s ease-in-out;
}

/* Additional safety for scroll restoration */
.scroll-restored {
    scroll-behavior: auto !important;
}

/* Debug helpers that can be toggled via JS */
.debug-overflow * {
    outline: 1px solid rgba(255, 0, 0, 0.5) !important;
}

.debug-overflow *:hover {
    outline: 2px solid red !important;
    background: rgba(255, 0, 0, 0.1) !important;
}

/* Mobile scroll fixes */
@media (max-width: 768px) {
    /* Prevent iOS Safari scroll issues */
    .language-overlay.show {
        -webkit-overflow-scrolling: touch;
    }
    
    .language-content {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Additional mobile scroll safety */
    body.modal-open {
        position: fixed;
        width: 100%;
        top: 0;
        left: 0;
    }
}

/* Accessibility: Ensure keyboard navigation works */
.language-overlay.show .language-option:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* =====================================
   SPA CSS INTEGRATION - ALPINE.JS SUPPORT
   ===================================== */

/* Fix Alpine.js integration with existing CSS */
[x-cloak] { display: none !important; }

/* MAIN CONTENT STRUCTURE */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-top: 24px;
    min-height: 600px;
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 24px;
    }
}

/* INPUT/OUTPUT SECTIONS */
.input-section,
.output-section {
    background: var(--background-card);
    border-radius: 12px;
    padding: 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary-color);
}

/* MODE TABS STYLING */
.mode-tabs {
    display: flex;
    background: var(--border-color);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 24px;
    gap: 4px;
}

.mode-tab {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.mode-tab:hover {
    color: var(--text-primary);
    background: rgba(230, 126, 34, 0.1);
}

.mode-tab.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(230, 126, 34, 0.3);
}

/* PRESETS STYLING */
.presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
}

.preset-btn {
    padding: 8px 16px;
    background: var(--background-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.preset-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.preset-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(230, 126, 34, 0.3);
}

/* INPUT/OUTPUT STYLING */
.code-input,
.code-output {
    width: 100%;
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
    font-size: 14px;
    line-height: 1.5;
    background: var(--background);
    color: var(--text-primary);
    resize: vertical;
    transition: all 0.2s ease;
}

/* Specifik stil för input-rutan */
.code-input {
    min-height: 300px; /* Sätt höjden för input-rutan här */
}

/* Specifik stil för output-rutan */
.code-output {
    min-height: 550px; /* Justera höjden för output-rutan här */
    background: var(--border-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.code-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.1);
}

.code-output {
    background: var(--border-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

/* ACTION BUTTON STYLING */
.action-btn {
    width: 100%;
    padding: 16px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 16px;
    box-shadow: 0 2px 8px rgba(230, 126, 34, 0.3);
}

.action-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(230, 126, 34, 0.4);
}

.action-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* TOP BAR INTEGRATION */
.requests-counter {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    background: rgba(230, 126, 34, 0.1) !important;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    border: 1px solid rgba(230, 126, 34, 0.2) !important;
    min-width: 120px !important;
}

.requests-count {
    font-weight: bold !important;
    color: var(--primary-color) !important;
    font-size: 16px !important;
}

.requests-counter span:last-child {
    color: var(--text-secondary) !important;
    font-size: 14px !important;
    white-space: nowrap !important;
}

.auth-btn {
    padding: 10px 20px !important;
    background: var(--primary-color) !important;
    color: white !important;
    border: none !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    text-decoration: none !important;
}

.auth-btn:hover {
    background: var(--primary-dark) !important;
    transform: translateY(-1px) !important;
}

/* LOADING STATES */
.action-btn[disabled] {
    background: #ccc !important;
    cursor: not-allowed !important;
}

/* NOTIFICATION SYSTEM STYLING */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
}

.notification {
    padding: 16px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    background: #27ae60;
}

.notification.error {
    background: #e74c3c;
}

.notification.warning {
    background: #f39c12;
}

.notification.info {
    background: #3498db;
}

.notification-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* COPY/CLEAR BUTTONS */
.input-actions,
.output-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.secondary-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(230, 126, 34, 0.05);
}

/* HAMBURGER MENU STYLING */
.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
}

.hamburger:hover {
    background: var(--border-color);
}

.hamburger-line {
    width: 18px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all 0.3s ease;
}

/* ALPINE.JS SPECIFIC FIXES */
[x-show] {
    transition: opacity 0.2s ease;
}

[x-show="false"] {
    opacity: 0;
    pointer-events: none;
}

[x-show="true"] {
    opacity: 1;
    pointer-events: auto;
}

/* PROCESSING STATE */
.processing .action-btn {
    position: relative;
    overflow: hidden;
}

.processing .action-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    animation: processing-shimmer 1.5s infinite;
}

@keyframes processing-shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* LOADING ANIMATION */
@keyframes processing {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.action-btn[disabled] {
    animation: processing 1.5s ease-in-out infinite;
}

/* MODERN SCROLL BAR FOR CODE AREAS */
.code-input::-webkit-scrollbar,
.code-output::-webkit-scrollbar {
    width: 8px;
}

.code-input::-webkit-scrollbar-track,
.code-output::-webkit-scrollbar-track {
    background: var(--border-color);
    border-radius: 4px;
}

.code-input::-webkit-scrollbar-thumb,
.code-output::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.code-input::-webkit-scrollbar-thumb:hover,
.code-output::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* DARK MODE ADJUSTMENTS */
body.dark .input-section,
body.dark .output-section {
    background: var(--background-card);
    border-color: var(--border-color);
}

body.dark .section-title {
    color: var(--text-primary);
}

body.dark .mode-tabs {
    background: #333;
}

body.dark .mode-tab {
    color: var(--text-secondary);
}

body.dark .mode-tab:hover {
    color: var(--text-primary);
    background: rgba(230, 126, 34, 0.2);
}

body.dark .preset-btn {
    background: #333;
    border-color: var(--border-color);
    color: var(--text-secondary);
}

body.dark .preset-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

body.dark .code-input,
body.dark .code-output {
    background: #2a2a2a;
    border-color: var(--border-color);
    color: var(--text-primary);
}

body.dark .code-input:focus {
    border-color: var(--primary-color);
}

body.dark .requests-counter {
    background: rgba(230, 126, 34, 0.2) !important;
    border: 1px solid rgba(230, 126, 34, 0.3) !important;
}

body.dark .requests-count {
    color: var(--primary-color) !important;
}

body.dark .requests-counter span:last-child {
    color: #ccc !important;
}

body.dark .secondary-btn {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

body.dark .secondary-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(230, 126, 34, 0.1);
}

body.dark .hamburger:hover {
    background: #3a3a3a;
}

body.dark .hamburger-line {
    background: var(--text-secondary);
}

body.dark .code-input::-webkit-scrollbar-track,
body.dark .code-output::-webkit-scrollbar-track {
    background: #333;
}

body.dark .code-input::-webkit-scrollbar-thumb,
body.dark .code-output::-webkit-scrollbar-thumb {
    background: #555;
}

body.dark .code-input::-webkit-scrollbar-thumb:hover,
body.dark .code-output::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* RESPONSIVE ADJUSTMENTS */
@media (max-width: 768px) {
    .input-section,
    .output-section {
        padding: 24px 20px;
    }
    
    .section-title {
        font-size: 18px;
        margin-bottom: 20px;
    }
    
    .mode-tab {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .preset-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .code-input,
    .code-output {
        min-height: 250px;
        padding: 16px;
        font-size: 13px;
    }
    
    .action-btn {
        padding: 14px 20px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .presets {
        gap: 6px;
    }
    
    .preset-btn {
        font-size: 11px;
        padding: 5px 10px;
    }
    
    .code-input,
    .code-output {
        min-height: 200px;
        padding: 12px;
        font-size: 12px;
    }
}

/* Print Styles */
@media print {
    /* Hide interactive elements */
    .side-menu,
    .side-menu-overlay,
    .auth-overlay,
    .limit-overlay,
    .language-overlay,
    .hamburger,
    .top-actions,
    .input-actions,
    .action-section,
    .results-header .copy-btn {
        display: none !important;
    }
    
    /* Optimize for printing */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .container {
        max-width: none;
        padding: 0;
        margin: 0;
    }
    
    .main-panel {
        box-shadow: none;
        border: 1px solid #000;
        page-break-inside: avoid;
    }
    
    .mode-tabs {
        border-bottom: 2px solid #000;
    }
    
    .mode-tab.active {
        font-weight: bold;
    }
    
    .code-input,
    .code-output {
        border: 1px solid #000;
        background: white !important;
        color: black !important;
        font-family: 'Courier New', monospace;
        font-size: 10pt;
        page-break-inside: avoid;
    }
    
    .results-section {
        page-break-before: auto;
    }
    
    /* Ensure good contrast for printing */
    .suggestion-label,
    .input-label,
    .results-title {
        color: #333 !important;
        font-weight: bold;
    }
    
    .suggestion-text {
        color: #666 !important;
    }
}