/* Custom styles for AI Evaluation Form */

/* Critical: Prevent horizontal scroll on mobile */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-text-size-adjust: 100%;
}

/* Ensure all elements use Cairo font and proper box sizing */
*, *::before, *::after {
    font-family: inherit;
    box-sizing: border-box;
}

/* Ensure container doesn't overflow */
.container {
    max-width: 100%;
    overflow-x: hidden;
}

/* Form input focus states */
input:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

input.error {
    border-color: #ef4444 !important;
    background-color: #fef2f2;
}

/* Option cards */
.option-card {
    cursor: pointer;
    transition: all 0.2s ease;
}

.option-card:hover {
    border-color: #93c5fd;
    background-color: #f9fafb;
}

.option-card.selected {
    border-color: #1d4ed8;
    background-color: #eff6ff;
}

.option-card input[type="radio"] {
    accent-color: #1d4ed8;
}

/* Question navigation dots */
.question-dot {
    cursor: pointer;
    transition: all 0.2s ease;
}

.question-dot:hover {
    transform: scale(1.2);
}

.question-dot.current {
    width: 2rem;
    background-color: #1d4ed8;
}

.question-dot.answered {
    background-color: #16a34a;
}

.question-dot.unanswered {
    background-color: #d1d5db;
}

/* Loading animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Print styles */
@media print {
    body {
        background: white !important;
    }
    
    header,
    #step-userinfo,
    #step-questions,
    #questionListSidebar,
    #sidebarOverlay,
    #saveIndicator,
    #resumeDialog,
    .flex.justify-center.gap-4 {
        display: none !important;
    }
    
    #step-results {
        display: block !important;
    }
    
    .shadow-xl,
    .shadow-lg,
    .shadow-md {
        box-shadow: none !important;
        border: 1px solid #e5e7eb !important;
    }
    
    .bg-gradient-to-l,
    .bg-gradient-to-br {
        background: #1d4ed8 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* Smooth transitions */
.transition-all {
    transition-property: all;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 300ms;
}

/* RTL specific adjustments */
[dir="rtl"] input[type="email"] {
    text-align: left;
}

/* Chart container */
#categoryChart,
#radarChart {
    max-width: 100%;
}

/* Button disabled state */
button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Question list sidebar */
.question-list-item {
    cursor: pointer;
    transition: all 0.15s ease;
}

.question-list-item:hover {
    background-color: #eff6ff;
}

.question-list-item.bg-blue-50 {
    background-color: #dbeafe;
    border-right: 3px solid #2563eb;
}

.question-list-item.bg-green-50 {
    background-color: #dcfce7;
}

/* Save indicator animation */
#saveIndicator {
    z-index: 9999;
}

/* Mobile sidebar transitions */
#questionListSidebar {
    direction: ltr;
}

#questionListSidebar > * {
    direction: rtl;
}

/* Prevent any element from causing horizontal overflow */
img, video, iframe, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* Ensure all cards and containers respect viewport */
[class*="rounded-"],
[class*="shadow-"],
.bg-white {
    max-width: 100%;
}

/* Fix for long text breaking layout */
h1, h2, h3, h4, h5, h6, p, span, label {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Scrollbar styling for question list */
#questionListItems::-webkit-scrollbar,
#questionListItemsMobile::-webkit-scrollbar {
    width: 6px;
}

#questionListItems::-webkit-scrollbar-track,
#questionListItemsMobile::-webkit-scrollbar-track {
    background: #f1f5f9;
}

#questionListItems::-webkit-scrollbar-thumb,
#questionListItemsMobile::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

#questionListItems::-webkit-scrollbar-thumb:hover,
#questionListItemsMobile::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Error message animation */
.error-msg {
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Card hover effect */
.hover\:shadow-xl:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Progress bar animation */
#progressBar {
    transition: width 0.5s ease-in-out;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Extra small devices (phones, 320px and up) */
@media (max-width: 480px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Header */
    #mainHeader {
        padding: 1rem;
    }
    
    #mainHeader h1 {
        font-size: 1.25rem;
    }
    
    #mainHeader p {
        font-size: 0.875rem;
    }
    
    #userInfoHeader {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    #userInfoHeader span {
        font-size: 0.75rem;
    }
    
    /* Intro page */
    #step-intro .text-4xl,
    #step-intro h1 {
        font-size: 1.5rem !important;
    }
    
    #step-intro .text-xl,
    #step-intro .text-2xl {
        font-size: 0.875rem !important;
    }
    
    #step-intro .p-8 {
        padding: 1rem !important;
    }
    
    #step-intro .grid {
        gap: 0.75rem;
    }
    
    #step-intro .rounded-xl {
        padding: 1rem;
    }
    
    #step-intro button.px-12 {
        padding-left: 2rem;
        padding-right: 2rem;
        font-size: 1rem;
    }
    
    /* User info form */
    #step-userinfo .p-8 {
        padding: 1rem !important;
    }
    
    #step-userinfo h2 {
        font-size: 1.25rem;
    }
    
    #step-userinfo input {
        padding: 0.625rem 0.75rem;
        font-size: 0.875rem;
    }
    
    /* Questions */
    #step-questions .p-8 {
        padding: 1rem !important;
    }
    
    #step-questions .p-6 {
        padding: 0.75rem !important;
    }
    
    #questionText {
        font-size: 1rem !important;
        line-height: 1.5;
    }
    
    #questionNumber,
    #subAxis {
        font-size: 0.625rem;
        padding: 0.25rem 0.5rem;
    }
    
    .option-card {
        padding: 0.75rem !important;
    }
    
    .option-card span {
        font-size: 0.875rem;
    }
    
    /* Navigation buttons */
    .nav-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .nav-buttons button {
        width: 100%;
        justify-content: center;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Question dots - hide text, smaller dots */
    .question-dot {
        width: 8px !important;
        height: 8px !important;
    }
    
    .question-dot.current {
        width: 20px !important;
    }
    
    /* Results page */
    #step-results .p-8 {
        padding: 1rem !important;
    }
    
    #step-results .text-3xl {
        font-size: 1.25rem;
    }
    
    #step-results .text-7xl {
        font-size: 3rem;
    }
    
    #step-results .grid {
        gap: 0.75rem;
    }
    
    /* Charts */
    #categoryChart,
    #radarChart {
        height: 250px !important;
    }
}

/* Small devices (phones landscape, 481px - 640px) */
@media (min-width: 481px) and (max-width: 640px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    #mainHeader h1 {
        font-size: 1.5rem;
    }
    
    #step-intro h1 {
        font-size: 1.75rem !important;
    }
    
    #questionText {
        font-size: 1.125rem !important;
    }
    
    .option-card {
        padding: 0.875rem !important;
    }
    
    /* Navigation buttons */
    .nav-buttons button {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }
    
    #step-results .text-7xl {
        font-size: 3.5rem;
    }
}

/* Medium devices (tablets, 641px - 768px) */
@media (min-width: 641px) and (max-width: 768px) {
    #step-intro h1 {
        font-size: 2rem !important;
    }
    
    #questionText {
        font-size: 1.25rem !important;
    }
    
    /* Show sidebar toggle button */
    #step-questions .lg\\:hidden {
        display: block;
    }
}

/* Medium-large devices (tablets landscape, 769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    #step-intro h1 {
        font-size: 2.25rem !important;
    }
    
    /* Sidebar adjustments */
    .desktop-sidebar {
        width: 280px;
    }
}

/* Large devices (desktops, 1025px and up) */
@media (min-width: 1025px) {
    .desktop-sidebar {
        width: 320px;
    }
    
    #step-questions .question-main {
        max-width: calc(100% - 340px);
    }
}

/* Extra large devices (large desktops, 1280px and up) */
@media (min-width: 1280px) {
    .desktop-sidebar {
        width: 360px;
    }
    
    #step-questions .question-main {
        max-width: 800px;
    }
}

/* ========================================
   MOBILE-SPECIFIC STYLES
   ======================================== */

/* Mobile navigation buttons */
@media (max-width: 768px) {
    #step-questions > div > div:first-child > div:nth-child(3) {
        flex-wrap: wrap;
    }
    
    /* Stack buttons on very small screens */
    .btn-group-left,
    .btn-group-right {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .btn-group-left button,
    .btn-group-right button {
        flex: 1 1 auto;
        min-width: 120px;
    }
    
    /* Save for later button - full width on mobile */
    button[onclick="saveForLater()"] {
        order: 3;
        flex-basis: 100%;
    }
    
    /* Progress bar text */
    #step-questions .p-6 .text-sm {
        font-size: 0.75rem;
    }
    
    /* Question metadata */
    #step-questions .text-sm.text-gray-600 {
        font-size: 0.75rem;
    }
}

/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
    button,
    .option-card,
    .question-list-item,
    .question-dot {
        min-height: 44px;
    }
    
    .option-card {
        padding: 1rem !important;
    }
    
    .question-list-item {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
}

/* ========================================
   MOBILE SIDEBAR IMPROVEMENTS
   ======================================== */

#questionListSidebar {
    max-width: 85vw;
}

@media (max-width: 480px) {
    #questionListSidebar {
        width: 100%;
        max-width: 100%;
    }
}

/* ========================================
   HEADER RESPONSIVE
   ======================================== */

@media (max-width: 640px) {
    #mainHeader {
        margin-bottom: 1rem;
        border-radius: 1rem;
    }
    
    #mainHeader img {
        height: 2.5rem;
    }
}

/* ========================================
   FORM RESPONSIVE
   ======================================== */

@media (max-width: 640px) {
    #step-userinfo {
        margin-top: 0;
    }
    
    #step-userinfo form {
        gap: 1rem;
    }
    
    #step-userinfo label {
        font-size: 0.875rem;
    }
}

/* ========================================
   RESULTS PAGE RESPONSIVE
   ======================================== */

@media (max-width: 640px) {
    #step-results > div:first-child {
        padding: 1.5rem 1rem;
        border-radius: 1rem;
    }
    
    #step-results .w-20 {
        width: 4rem;
        height: 4rem;
    }
    
    #step-results .w-10 {
        width: 2rem;
        height: 2rem;
    }
    
    /* Charts container */
    #step-results > div:nth-child(4),
    #step-results > div:nth-child(5) {
        padding: 1rem;
    }
    
    #step-results > div:nth-child(4) > div,
    #step-results > div:nth-child(5) > div {
        height: 280px !important;
    }
    
    /* Action buttons */
    #step-results > div:last-child {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    #step-results > div:last-child button {
        width: 100%;
    }
}

/* ========================================
   DIALOGS RESPONSIVE
   ======================================== */

@media (max-width: 480px) {
    #resumeDialog > div,
    #loadingOverlay > div {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    #resumeDialog h3 {
        font-size: 1.125rem;
    }
    
    #resumeDialog p {
        font-size: 0.875rem;
    }
}

/* ========================================
   LANDSCAPE ORIENTATION
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
    #mainHeader {
        padding: 0.5rem 1rem;
        margin-bottom: 0.5rem;
    }
    
    #mainHeader img {
        height: 2rem;
    }
    
    #mainHeader h1 {
        font-size: 1.25rem;
        margin-bottom: 0;
    }
    
    #mainHeader p {
        display: none;
    }
    
    #step-questions .p-6 {
        padding: 0.5rem 1rem !important;
    }
    
    #step-questions .p-8 {
        padding: 1rem !important;
    }
    
    #questionText {
        font-size: 1rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .option-card {
        padding: 0.5rem 0.75rem !important;
    }
}

/* ========================================
   SAFE AREA INSETS (for notched phones)
   ======================================== */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    #questionListSidebar {
        padding-left: max(0px, env(safe-area-inset-left));
    }
    
    #saveIndicator {
        bottom: max(1rem, calc(env(safe-area-inset-bottom) + 1rem));
        left: max(1rem, calc(env(safe-area-inset-left) + 1rem));
    }
}

/* ========================================
   DARK MODE MEDIA QUERY (optional)
   ======================================== */

@media (prefers-color-scheme: dark) {
    /* Users can enable if they want dark mode support */
}

/* ========================================
   REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    #progressBar {
        transition: none;
    }
}

/* ========================================
   HIGH CONTRAST MODE
   ======================================== */

@media (prefers-contrast: high) {
    .option-card {
        border-width: 3px;
    }
    
    .option-card.selected {
        border-color: #000;
        background-color: #fff;
    }
    
    button {
        border: 2px solid currentColor;
    }
}
