/* 
  AIViva Mobile-First Responsive Styles
  ---
  This file contains overrides and additions to the main 'style.css' 
  to ensure the website is fully responsive and mobile-friendly.

  Breakpoint Philosophy:
  - 1200px (Large Desktops)
  - 992px (Tablets in Landscape)
  - 768px (Tablets in Portrait)
  - 480px (Mobile Phones)
*/

/* --- General Typography & Layout --- */
@media (max-width: 768px) {
    body {
        -webkit-text-size-adjust: 100%; /* Prevents iOS font scaling */
    }

    .container {
        padding: 0 16px;
    }

    h1, .hero h1 {
        font-size: 2.25rem; /* 36px */
        letter-spacing: -0.5px;
    }
    h2, .section-title {
        font-size: 1.75rem; /* 28px */
    }
}


/* --- Header --- */
@media (max-width: 768px) {
    header {
        padding: 8px 0;
    }
    .nav {
        flex-direction: column; /* Stack items vertically */
        justify-content: center; /* Center horizontally */
        align-items: center;
        gap: 12px; /* Add space between logo and buttons */
    }

    .logo-icon {
        height: 40px;
    }
    
    .nav-buttons {
       gap: 8px;
    }

    .nav-link, .cta-button {
        padding: 8px 12px;
        font-size: 0.875rem; /* 14px */
    }
}

@media (max-width: 480px) {
    .nav-buttons {
        gap: 6px;
    }
    .nav-link, .cta-button {
        padding: 6px 10px;
        font-size: 0.8rem; /* ~13px */
    }
}

/* --- Hero Section --- */
@media (max-width: 768px) {
    .hero {
        padding: 40px 0 30px;
    }
    .hero p {
        font-size: 1.125rem; /* 18px */
        margin-bottom: 24px;
    }
    .hero-visual {
        margin-top: 30px;
    }
}


/* --- Features & Advantages Grid --- */
@media (max-width: 992px) {
    .feature-grid {
        grid-template-columns: 1fr 1fr;
    }
    .advantages .feature-grid {
        grid-template-columns: 1fr 1fr;
    }
    .advantages .feature-card:last-child {
        grid-column: auto; /* Reset column span */
    }
}

@media (max-width: 768px) {
    .features, .advantages {
        padding: 40px 0;
    }
    .feature-grid,
    .advantages .feature-grid {
        grid-template-columns: 1fr; /* Stack cards vertically */
        gap: 24px;
    }
    .feature-card {
        padding: 24px;
    }
}

/* --- Final CTA --- */
@media (max-width: 768px) {
    .final-cta {
        padding: 48px 24px;
        margin: 40px 16px; /* Add horizontal margin */
        border-radius: 24px;
    }
    .final-cta h2 {
        font-size: 2rem; /* 32px */
    }
    .final-cta p {
        font-size: 1rem; /* 16px */
    }
    .final-cta .cta-button {
        padding: 14px 28px;
        font-size: 1rem;
    }
}


/* --- Footer --- */
@media (max-width: 768px) {
    .footer-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 16px;
    }
    .footer-left {
        align-items: center;
    }
    .footer-nav {
        flex-direction: column;
        gap: 8px;
    }
}

/* --- GENERAL MOBILE FIXES --- */
@media (max-width: 768px) {
    /* Hide hamburger menu by default on ALL pages */
    .mobile-menu-toggle {
        display: none !important;
    }
}


/* --- Dashboard --- */
@media (max-width: 992px) {
    .dashboard-page {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }
    .main-content {
        padding: 16px;
    }
    .department-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 columns for tablets */
        gap: 16px;
    }
}

@media (max-width: 768px) {
    .dashboard-page {
        flex-direction: column;
    }
    .sidebar {
        position: fixed;
        left: -100%; /* Start off-screen */
        top: 0;
        height: 100%;
        z-index: 9999;
        transition: left 0.3s ease-in-out !important;
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
        overflow-y: auto;
    }
    .sidebar.open {
        left: 0;
    }

    .mobile-menu-toggle {
        display: none; /* Hide hamburger by default */
    }

    .dashboard-page .mobile-menu-toggle {
        display: flex !important;
        position: static !important;
        margin: 0;
        width: 40px;
        height: 40px;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.9);
        border: 1px solid rgba(15, 23, 42, 0.1);
        box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
        flex-shrink: 0;
    }
    .dashboard-page .mobile-menu-toggle span {
        display: block !important;
        width: 20px !important;
        height: 2px !important;
        background-color: #333 !important;
        border-radius: 1px;
        transition: all 0.3s ease;
        opacity: 1 !important;
        visibility: visible !important;
        margin: 0 !important;
    }

    .dashboard-page .dashboard-header .mobile-menu-toggle {
        display: flex !important;
        background: transparent;
        border: none;
    }

    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.4);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease-in-out, visibility 0.3s;
    }

    .dashboard-page .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .main-content {
        width: 100%;
        margin-left: 0;
        padding-top: 70px; /* Space for the header */
    }

    .dashboard-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding: 12px 18px;
        background-color: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(8px);
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
        z-index: 1000;
        display: grid;
        grid-template-columns: auto 1fr;
        align-items: center;
        column-gap: 16px;
        min-height: 56px;
    }

    .dashboard-header h1 {
       display: none; /* Hide title, it's redundant on mobile */
    }
    
    .header-links {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 16px;
        flex-wrap: wrap;
        margin: 0;
    }
    .header-link {
        font-size: 14px;
        white-space: nowrap;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }
    #user-menu {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .department-card, .special-card {
        height: auto; /* Let content define height */
        min-height: unset;
        padding: 16px; /* Уменьшаем padding */
        margin-bottom: 12px; /* Уменьшаем отступы между карточками */
    }

    /* Оптимизация карточек для мобильных устройств */
    .department-card .card-header {
        flex-direction: column;
        text-align: center;
        gap: 8px;
        margin-bottom: 12px;
    }

    .department-card .card-icon {
        width: 40px; /* Уменьшаем размер иконки */
        height: 40px;
        padding: 8px;
    }

    .department-card h3 {
        font-size: 1.2rem; /* Уменьшаем размер заголовка */
        line-height: 1.2;
        margin: 0;
    }

    .department-card p {
        font-size: 0.9rem; /* Уменьшаем размер текста */
        line-height: 1.4;
        margin: 8px 0 12px 0; /* Уменьшаем отступы */
    }

    .department-card .card-metric {
        margin-top: 8px; /* Уменьшаем отступ метрики */
    }

    .department-card .metric-value {
        font-size: 1.1rem; /* Уменьшаем размер метрики */
    }

    .department-card .metric-label {
        font-size: 0.8rem; /* Уменьшаем размер подписи метрики */
    }
}

@media (max-width: 600px) {
    .dashboard-header {
        padding: 10px 16px;
    }

    /* Дополнительная оптимизация для маленьких экранов */
    .department-card {
        padding: 12px; /* Еще меньше padding */
        margin-bottom: 10px;
    }

    .department-card .card-header {
        gap: 6px;
        margin-bottom: 10px;
    }

    .department-card .card-icon {
        width: 36px; /* Еще меньше иконка */
        height: 36px;
        padding: 6px;
    }

    .department-card h3 {
        font-size: 1.1rem; /* Еще меньше заголовок */
    }

    .department-card p {
        font-size: 0.85rem; /* Еще меньше текст */
        margin: 6px 0 10px 0;
    }

    .department-card .card-metric {
        margin-top: 6px;
    }

    .department-card .metric-value {
        font-size: 1rem;
    }

    .department-card .metric-label {
        font-size: 0.75rem;
    }
        column-gap: 12px;
    }
    .header-links {
        gap: 12px;
    }
}

/* Shared tool page tweaks (contract-header, form cards, results) */
@media (max-width: 768px) {
    .contract-header {
        padding: 32px 0;
    }

    .contract-header .header-content,
    .content-main .header-content {
        flex-direction: column;
        text-align: center;
        align-items: center;
        gap: 20px;
        padding: 0 18px;
    }

    .contract-header .header-text h1,
    .content-main .header-text h1 {
        font-size: 2.3rem;
    }

    .contract-header .header-subtitle,
    .content-main .header-subtitle {
        font-size: 1.1rem;
        margin: 12px 0 0 0;
    }

    .contract-header .header-icon,
    .content-main .header-icon {
        justify-content: center;
        padding-top: 0;
    }

    /* Скрываем иконки в header на мобильных устройствах */
    .contract-header .header-icon,
    .resume-header .header-icon,
    .vacancy-header .header-icon,
    .content-main .header-icon,
    .business-growth-header .header-icon,
    .header-content .header-icon,
    .main-content .vacancy-header .header-icon,
    .main-content .contract-header .header-icon,
    .main-content .resume-header .header-icon,
    .main-content .business-growth-header .header-icon,
    header.vacancy-header .header-icon,
    header.contract-header .header-icon,
    header.resume-header .header-icon,
    header .header-content .header-icon {
        display: none !important;
    }

    /* Убеждаемся, что контент не перекрывает сайдбар */
    .main-content,
    .main-content *:not(.sidebar):not(.mobile-overlay):not(.mobile-menu-toggle),
    .dashboard-header,
    .contract-header,
    .resume-header,
    .vacancy-header,
    .content-main,
    .contract-main,
    .content-container,
    .header-content,
    main,
    section,
    .tools-overview,
    .department-grid,
    body > *:not(.sidebar):not(.mobile-overlay) {
        z-index: 1 !important;
    }
    
    /* Гарантируем, что сайдбар и overlay всегда сверху */
    .sidebar {
        z-index: 9999 !important;
    }
    
    .mobile-overlay {
        z-index: 9998 !important;
    }

    .contract-header .header-description-tabs,
    .content-main .header-description-tabs {
        flex-wrap: wrap;
        justify-content: center;
    }

    .contract-main,
    .content-main,
    .content-container {
        padding: 0 16px;
        width: 100%;
    }

    .form-card,
    .upload-card,
    .results-container,
    .facts-container {
        border-radius: 18px;
    }

    .form-header,
    .upload-header {
        padding: 20px 20px;
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .platform-buttons,
    .goals-grid,
    .platforms-grid,
    .actions-grid {
        grid-template-columns: 1fr !important;
    }

    .results-header,
    .facts-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
        padding: 20px 24px;
    }

    .results-actions,
    .results-container .results-actions {
        width: 100%;
        flex-direction: column;
        gap: 12px;
    }

    .results-content,
    .facts-content,
    .loading-container,
    .upload-area,
    .chat-input-form {
        padding: 24px;
    }

    .upload-area,
    .loading-container {
        padding: 32px 24px;
    }
}

@media (max-width: 520px) {
    .contract-header .header-text h1,
    .content-main .header-text h1 {
        font-size: 1.85rem;
    }

    .contract-header .header-subtitle,
    .content-main .header-subtitle {
        font-size: 1rem;
    }

    .results-content,
    .facts-content,
    .loading-container,
    .upload-area,
    .chat-input-form {
        padding: 20px;
    }

    .form-header,
    .upload-header {
        padding: 18px 18px;
    }

    .results-actions button,
    .action-button,
    .copy-button,
    .submit-button,
    .send-button {
        width: 100%;
    }
}

@media (max-width: 576px) {
    .department-grid {
        grid-template-columns: 1fr; /* 1 column for small phones */
    }
}

/* --- Auth Pages (Login, Request Access) --- */
@media (max-width: 768px) {
    .auth-container {
        margin: 20px 16px;
        padding: 24px;
        box-shadow: none;
        border: 1px solid var(--border-color);
        max-width: 100%;
        width: auto;
    }
    
    .auth-container h2 {
        font-size: 1.75rem;
        margin-bottom: 16px;
    }
    
    .auth-container .subtitle {
        font-size: 1rem;
        margin-bottom: 24px;
    }
    
    .form-group {
        margin-bottom: 20px;
    }
    
    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 8px;
        display: block;
    }
    
    .form-group input {
        width: 100%;
        padding: 12px 16px;
        font-size: 1rem;
        border-radius: 8px;
        border: 1px solid #d1d5db;
        box-sizing: border-box;
    }
    
    .form-group input:focus {
        outline: none;
        border-color: #4f46e5;
        box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    }
    
    .cta-button {
        width: 100%;
        padding: 14px 24px;
        font-size: 1rem;
        border-radius: 8px;
        margin-top: 8px;
    }
    
    .auth-switch {
        font-size: 0.9rem;
        margin-top: 20px;
        text-align: center;
    }
    
    .nav-buttons .cta-button {
        padding: 8px 16px;
        font-size: 0.9rem;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 16px;
    }
    
    .footer-nav {
        flex-direction: column;
        gap: 8px;
    }
}

/* --- Content Pages (FAQ, Privacy Policy) --- */
@media (max-width: 768px) {
    .content-section {
        padding: 40px 0;
    }
    .text-container {
        padding: 0 16px;
    }
    .faq-section-title {
        font-size: 1.5rem; /* 24px */
    }
    .faq-question {
        font-size: 1.25rem; /* 20px */
    }
    .faq-answer {
        font-size: 1rem; /* 16px */
    }
}

/* --- Tool Pages (Contract Analysis, etc.) --- */
@media (max-width: 768px) {
    .contract-header .header-content {
        flex-direction: column;
        text-align: center;
        gap: 16px;
    }
    .contract-main {
        padding: 16px;
    }
    .actions-grid {
        grid-template-columns: 1fr;
    }
    .upload-area {
        padding: 24px;
    }
    .quick-questions-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
}

/* Hide redundant header on tool pages on desktop */
@media (min-width: 769px) {
    .main-content:has(> .contract-header) .dashboard-header,
    .main-content:has(> .vacancy-header) .dashboard-header,
    .main-content:has(> .resume-header) .dashboard-header {
        display: none;
    }
}
