/* ============================================
   Text Optimizer Pro - Responsive Stylesheet
   Mobile-First Responsive Design
   ============================================ */

/* ============================================
   Large Devices (Desktops, 1200px and up)
   ============================================ */
@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
    
    .tool-container {
        max-width: 1000px;
    }
}

/* ============================================
   Medium Devices (Tablets, 768px to 1199px)
   ============================================ */
@media (max-width: 1199px) {
    .container {
        max-width: 960px;
    }
    
    .footer-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--spacing-xl);
    }
    
    .footer-column:last-child {
        grid-column: span 3;
    }
    
    .sidebar-ad {
        display: none;
    }
}

/* ============================================
   Small Devices (Landscape phones, 576px to 767px)
   ============================================ */
@media (max-width: 767px) {
    .container {
        max-width: 100%;
        padding: 0 var(--spacing-md);
    }
    
    /* Header Adjustments */
    .header-inner {
        flex-wrap: wrap;
    }
    
    .logo {
        flex: 1;
    }
    
    .mobile-menu-toggle {
        display: flex;
    }
    
    .main-nav {
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        background: var(--bg-primary);
        box-shadow: var(--shadow-lg);
        padding: var(--spacing-lg);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 999;
        max-height: calc(100vh - 70px);
        overflow-y: auto;
    }
    
    .main-nav.active {
        transform: translateX(0);
    }
    
    .nav-list {
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .nav-link {
        display: block;
        padding: var(--spacing-md);
    }
    
    .has-dropdown {
        position: relative;
    }
    
    .dropdown {
        position: static;
        box-shadow: none;
        border: none;
        padding-left: var(--spacing-lg);
        max-height: none;
        display: none;
        background: var(--bg-secondary);
        border-radius: var(--border-radius);
        margin-top: var(--spacing-sm);
    }
    
    .has-dropdown.active .dropdown {
        display: block;
    }
    
    .dropdown-toggle {
        display: inline-block;
    }
    
    /* Hide header actions on mobile */
    .header-actions {
        display: none;
    }

    /* Hide top bar on mobile */
    .top-bar {
        display: none;
    }
    
    /* Footer Adjustments */
    .footer-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-xl);
    }
    
    .footer-column {
        text-align: center;
    }
    
    .footer-column h3::after {
        left: 50%;
        transform: translateX(-50%);
    }
    
    .social-icons-footer {
        justify-content: center;
    }
    
    .donation-buttons {
        max-width: 300px;
        margin: var(--spacing-md) auto 0;
    }
    
    /* Advertisement Adjustments */
    .sidebar-ad {
        display: none !important;
    }
    
    .ad-top {
        max-width: 100%;
    }
    
    .ad-box {
        width: 100%;
        height: auto;
        min-height: 100px;
    }
    
    /* Cookie Notice */
    .cookie-content {
        flex-direction: column;
        text-align: center;
        gap: var(--spacing-md);
    }
    
    .cookie-buttons {
        flex-direction: column;
        width: 100%;
    }
    
    .cookie-buttons .btn {
        width: 100%;
    }
    
    /* Back to Top Button */
    .back-to-top {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
    }
}

/* ============================================
   Extra Small Devices (Portrait phones, less than 576px)
   ============================================ */
@media (max-width: 575px) {
    .container {
        padding: 0 var(--spacing-sm);
    }
    
    /* Typography */
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    /* Tool Pages */
    .tool-icon {
        font-size: 3rem;
    }
    
    .tool-title {
        font-size: 1.75rem;
    }
    
    .tool-description {
        font-size: var(--font-size-base);
    }
    
    .tool-box {
        padding: var(--spacing-md);
    }
    
    .tool-input,
    .tool-output {
        min-height: 200px;
        font-size: var(--font-size-sm);
    }
    
    .tool-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Cards */
    .card {
        padding: var(--spacing-md);
    }
    
    /* Forms */
    .form-control {
        font-size: var(--font-size-sm);
    }
    
    /* Results */
    .result-item {
        flex-direction: column;
        gap: var(--spacing-xs);
    }
    
    .result-value {
        font-size: var(--font-size-lg);
    }
    
    /* Footer */
    .footer {
        padding: var(--spacing-xl) 0 var(--spacing-md);
    }
    
    .footer-bottom {
        font-size: var(--font-size-sm);
    }
    
    /* Advertisement */
    .ad-placeholder {
        padding: var(--spacing-md);
        font-size: var(--font-size-sm);
    }
    
    /* Tips Box */
    .tips-box {
        padding: var(--spacing-md);
    }
    
    .tips-box h4 {
        font-size: var(--font-size-base);
    }
    
    .tips-box p {
        font-size: var(--font-size-sm);
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .header,
    .footer,
    .sidebar-ad,
    .ad-container,
    .back-to-top,
    .cookie-notice,
    .mobile-menu-toggle,
    .social-icons,
    .auth-buttons,
    .language-switcher {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }
    
    .main-content {
        padding: 0;
        margin: 0;
    }
    
    .tool-container {
        max-width: 100%;
    }
    
    .tool-input,
    .tool-output {
        border: 1px solid #ccc;
        background: #fff;
    }
    
    a {
        text-decoration: underline;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.9em;
    }
}

/* ============================================
   High Contrast Mode Support
   ============================================ */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --text-secondary: #000;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
    
    .form-control {
        border: 2px solid #000;
    }
}

/* ============================================
   Reduced Motion Support
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    html {
        scroll-behavior: auto;
    }
}

/* ============================================
   Dark Mode Support
   ============================================ */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #E9ECEF;
        --text-secondary: #ADB5BD;
        --text-light: #6C757D;
        
        --bg-primary: #1A1A1A;
        --bg-secondary: #212529;
        --bg-tertiary: #2C3034;
        --bg-dark: #000000;
        
        --border-color: #343A40;
        --border-light: #2C3034;
    }
    
    body {
        background: var(--bg-primary);
        color: var(--text-primary);
    }
}

/* ============================================
   Landscape Mode for Mobile
   ============================================ */
@media (max-width: 767px) and (orientation: landscape) {
    .main-nav {
        max-height: calc(100vh - 60px);
    }
    
    .cookie-notice {
        padding: var(--spacing-sm) 0;
    }
    
    .cookie-content {
        flex-direction: row;
        align-items: center;
    }
}

/* ============================================
   Touch Device Optimizations
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .nav-link,
    .social-icon,
    .dropdown li a {
        min-height: 44px;
        min-width: 44px;
    }
    
    .tool-input,
    .tool-output {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* ============================================
   RTL (Right-to-Left) Support for Arabic
   ============================================ */
html[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

html[dir="rtl"] .logo a {
    flex-direction: row-reverse;
}

html[dir="rtl"] .nav-list {
    flex-direction: row-reverse;
}

html[dir="rtl"] .dropdown {
    left: auto;
    right: 0;
}

html[dir="rtl"] .dropdown li a:hover {
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-xl);
}

html[dir="rtl"] .header-actions {
    flex-direction: row-reverse;
}

html[dir="rtl"] .social-icons {
    flex-direction: row-reverse;
}

html[dir="rtl"] .auth-buttons {
    flex-direction: row-reverse;
}

html[dir="rtl"] .footer-links a:hover {
    transform: translateX(-5px);
}

html[dir="rtl"] .sidebar-ad-top {
    left: auto;
    right: 20px;
}

html[dir="rtl"] .sidebar-ad-bottom {
    right: auto;
    left: 20px;
}

html[dir="rtl"] .back-to-top {
    left: 30px;
    right: auto;
}

html[dir="rtl"] .cookie-buttons {
    flex-direction: row-reverse;
}

html[dir="rtl"] .tips-box {
    border-left: none;
    border-right: 4px solid var(--warning-color);
}

/* ============================================
   Very Large Screens (4K and above)
   ============================================ */
@media (min-width: 1920px) {
    .container {
        max-width: 1400px;
    }
    
    .tool-container {
        max-width: 1200px;
    }
    
    html {
        font-size: 18px;
    }
}

/* ============================================
   Ultra Wide Screens
   ============================================ */
@media (min-width: 2560px) {
    .container {
        max-width: 1600px;
    }
    
    .tool-container {
        max-width: 1400px;
    }
}

/* ============================================
   Accessibility: Focus Visible
   ============================================ */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ============================================
   Selection Styling
   ============================================ */
::selection {
    background: var(--primary-color);
    color: var(--text-white);
}

::-moz-selection {
    background: var(--primary-color);
    color: var(--text-white);
}

/* ============================================
   Scrollbar Styling (Webkit browsers)
   ============================================ */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* ============================================
   Firefox Scrollbar Styling
   ============================================ */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-secondary);
}

/* ============================================
   Loading States
   ============================================ */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============================================
   Skeleton Loading
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border-light) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--border-radius);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ============================================
   Print Optimization for Tools
   ============================================ */
@media print {
    .tool-header {
        page-break-after: avoid;
    }
    
    .tool-box {
        page-break-inside: avoid;
    }
    
    .tool-input,
    .tool-output {
        page-break-inside: avoid;
    }
    
    .tool-actions {
        display: none;
    }
    
    .tips-box {
        page-break-inside: avoid;
    }
}