/*
 * Prashn Shastra - Mobile Responsive Styles
 * Ensures proper scaling without zoom and touch-friendly elements
 */

/* ==================== MOBILE-FIRST FIXES ==================== */

/* Viewport meta tag must be in HTML:
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
*/

/* Prevent horizontal scroll and zoom */
html,
body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: manipulation;
    /* Better touch handling */
}

/* ==================== HEADER MOBILE ==================== */
@media screen and (max-width: 600px) {
    .app-header {
        padding: 0.4rem 0.5rem;
        position: fixed;
    }

    .header-top-row {
        flex-direction: row;
        flex-wrap: nowrap !important;
        gap: 0.2rem;
        justify-content: space-between !important;
        align-items: center;
    }

    .user-actions-left {
        order: 1;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 0.4rem;
        padding: 0.2rem 0.6rem;
        justify-content: flex-start;
        align-items: center;
        background: var(--card-bg) !important;
        border: 1px solid var(--card-border);
        border-radius: 50px;
        flex: 1 1 auto;
        overflow: hidden;
    }

    .user-actions-left .icon-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.6rem;
        min-height: 32px;
        min-width: 32px;
        /* Touch-friendly */
    }

    .dashboard-header-btn {
        padding: 0.3rem 0.5rem !important;
        font-size: 0.55rem !important;
    }

    #userName {
        color: var(--text-primary) !important;
        font-size: 0.7rem;
        display: inline-block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0;
        flex: 1 1 auto;
    }

    .header-lang-controls {
        order: 2;
        padding: 0.3rem 0.5rem;
        gap: 0.4rem;
    }

    .lang-group label {
        font-size: 0.6rem;
    }

    .small-select {
        font-size: 0.7rem;
        padding: 0.25rem 0.4rem;
        min-height: 32px;
        /* Touch-friendly */
    }
}

/* ==================== MAIN CONTENT MOBILE ==================== */
@media screen and (max-width: 600px) {
    .main-content-center {
        padding-top: 60px;
        /* Aligned with desktop for tight feel */
        padding-bottom: 2rem;
        min-height: auto;
    }

    .om-header {
        width: 70px;
        height: 70px;
        margin-bottom: 0.8rem;
    }

    .logo-container {
        margin-bottom: 1rem;
    }

    .logo {
        font-size: 1.5rem;
        letter-spacing: 1px;
    }

    .orbital-section {
        width: 100%;
        padding: 0 0.5rem;
    }

    /* Input Area - Stack on Mobile */
    .input-area {
        display: flex !important;
        flex-direction: row;
        align-items: center;
        padding: 0.4rem 0.6rem;
        border-radius: 50px;
        gap: 0.4rem;
        width: 100%;
        background: var(--input-bg) !important;
        border: 2px solid var(--card-border) !important;
    }

    .input-wrapper {
        width: 100%;
    }

    #questionInput {
        flex: 1;
        width: auto;
        min-width: 0;
        /* Allows shrinking in flex context */
        font-size: 16px !important;
        padding: 0.6rem;
        text-align: left;
        border-radius: 8px;
        background: transparent !important;
        border: none !important;
        color: var(--text-primary) !important;
    }

    .input-actions {
        width: auto;
        display: flex;
        gap: 0.3rem;
        flex-shrink: 0;
        align-items: center;
    }

    .ask-btn,
    .primary-btn {
        width: auto;
        padding: 0.4rem 0.8rem !important;
        font-size: 0.8rem;
        min-height: 38px;
        max-width: 80px;
        flex-shrink: 0;
        background: var(--primary-gradient) !important;
        color: white !important;
        box-shadow: 0 4px 10px var(--shadow-soft) !important;
    }

    .info-btn-outer {
        width: 36px;
        height: 36px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
    }

    .info-btn {
        position: relative;
        right: auto;
        transform: none;
        margin-top: 0.5rem;
    }
}

/* ==================== ANSWER CARDS MOBILE ==================== */
@media screen and (max-width: 600px) {
    .chat-item {
        padding: 1rem;
        margin: 0.8rem 0;
        border-radius: 14px;
    }

    .chat-item .label {
        font-size: 0.9rem;
    }

    .chat-item .timestamp {
        font-size: 0.7rem;
        color: var(--text-medium);
    }

    .short-answer {
        font-size: 0.95rem;
        line-height: 1.7;
    }

    .chart-data {
        font-size: 0.75rem;
        padding: 0.8rem;
    }

    .duration-meta {
        font-size: 0.7rem;
        color: var(--text-medium);
    }

    .charts-container {
        display: none !important;
    }
}

/* ==================== AUTH FORMS MOBILE ==================== */
@media screen and (max-width: 600px) {
    .auth-overlay {
        padding: 0.5rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    .auth-box {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 1.2rem;
        border-radius: 16px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .auth-box.signup-mode {
        padding: 1rem;
    }

    .signup-row {
        gap: 0.5rem;
        margin-bottom: 0.3rem;
    }

    .auth-logo {
        font-size: 1.4rem;
        margin-bottom: 0.3rem;
    }

    .auth-box>p {
        font-size: 0.8rem;
        margin-bottom: 1rem;
    }

    .auth-tabs {
        margin-bottom: 1rem;
    }

    .tab-btn,
    .auth-tab {
        padding: 0.6rem;
        font-size: 0.9rem;
        min-height: 44px;
        /* Touch-friendly */
    }

    .auth-form-content input,
    .auth-form-content select {
        padding: 0.7rem;
        font-size: 16px !important;
        /* Prevents iOS zoom */
        margin-bottom: 0.6rem;
        min-height: 48px;
        /* Touch-friendly */
    }

    .name-row,
    .birth-row,
    .time-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .input-label {
        font-size: 0.7rem;
        margin-top: 0.5rem;
    }

    .date-dropdowns {
        flex-direction: row;
        gap: 0.3rem;
    }

    .date-select {
        flex: 1;
        font-size: 14px !important;
        padding: 0.5rem 0.2rem;
        min-height: 44px;
        min-width: 60px;
        text-align: center;
        font-weight: 600;
    }

    .birth-row-stacked {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.8rem;
    }

    .primary-btn {
        width: 100%;
        padding: 0.9rem;
        font-size: 0.95rem;
        min-height: 50px;
        margin-top: 0.5rem;
        background: var(--saffron-gradient);
        color: white !important;
        font-weight: bold;
        border: none;
        border-radius: 50px;
    }

    .auth-link {
        font-size: 0.8rem;
    }

    /* Birth City Search */
    .form-group {
        margin-bottom: 0.5rem;
    }

    #birth_city_results,
    #edit_birth_city_results {
        max-height: 150px;
    }

    .city-result {
        padding: 0.6rem;
        font-size: 0.85rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        color: var(--text-primary);
        /* Ensure text is visible in list */
    }
}

/* ==================== MODALS MOBILE ==================== */
@media screen and (max-width: 600px) {
    .modal {
        padding: 0.5rem;
        align-items: flex-start;
        padding-top: 1rem;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        padding: 1rem;
        border-radius: 16px;
        max-height: 95vh;
        overflow-y: auto;
    }

    .history-content {
        max-height: 80vh;
    }

    .close {
        top: 10px;
        right: 15px;
        font-size: 1.3rem;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .modal h2 {
        font-size: 1.2rem;
        margin-bottom: 0.8rem;
    }

    /* History Items */
    .history-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }

    .clear-history-btn {
        width: 100%;
        min-height: 44px;
    }

    .history-item {
        padding: 0.8rem;
        margin-bottom: 0.8rem;
    }

    .history-item .h-q {
        font-size: 0.9rem;
    }

    .history-item .h-a {
        font-size: 0.85rem;
    }

    .history-feedback button {
        min-height: 36px;
        min-width: 50px;
    }

    /* Location Modal */
    .location-search-box input {
        font-size: 16px !important;
        min-height: 48px;
    }

    .search-result-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Profile Edit Modal */
    .profile-edit-form input,
    .profile-edit-form select {
        font-size: 16px !important;
        min-height: 48px;
    }
}

/* ==================== GUIDANCE BOX MOBILE ==================== */
@media screen and (max-width: 600px) {
    .guidance-box {
        padding: 1rem;
        font-size: 0.85rem;
        border-radius: 12px;
    }

    .guidance-box h4 {
        font-size: 1rem;
    }

    .guidance-box ul {
        padding-left: 1.2rem;
    }

    .guidance-box li {
        margin-bottom: 0.4rem;
    }
}

/* ==================== UTILITY MOBILE FIXES ==================== */

/* Touch-friendly minimum sizes */
@media screen and (max-width: 600px) {

    button,
    .icon-btn,
    [role="button"],
    a.btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Prevent text selection on buttons */
    button {
        -webkit-user-select: none;
        user-select: none;
    }

    /* Smooth scrolling */
    .search-results,
    .history-content,
    .modal-content {
        -webkit-overflow-scrolling: touch;
    }

    /* Loading State */
    .loading-oracle {
        font-size: 1rem;
        padding: 1.5rem;
    }

    /* Rate Limit */
    .rate-limit-error {
        padding: 1.5rem 1rem;
    }

    .rate-limit-error h3 {
        font-size: 1.1rem;
    }

    .upgrade-btn {
        padding: 0.8rem 1.5rem;
        font-size: 0.9rem;
        width: 100%;
        text-align: center;
    }

    /* Tier Badge */
    .tier-badge {
        font-size: 0.65rem;
        padding: 0.15rem 0.5rem;
    }

    /* Query Remaining */
    .query-remaining {
        font-size: 0.75rem;
    }
}

/* ==================== LANDSCAPE MOBILE ==================== */
@media screen and (max-width: 900px) and (orientation: landscape) {
    .main-content-center {
        padding-top: 70px;
    }

    .auth-overlay {
        padding: 0.5rem;
    }

    .auth-box {
        max-height: 80vh;
        overflow-y: auto;
    }

    .om-header {
        width: 50px;
        height: 50px;
    }

    .logo {
        font-size: 1.3rem;
    }
}

/* ==================== SMALL MOBILE (< 360px) ==================== */
@media screen and (max-width: 360px) {
    html {
        font-size: 13px;
    }

    .user-actions-left .icon-btn {
        padding: 0.25rem 0.4rem;
        font-size: 0.55rem;
    }

    .logo {
        font-size: 1.3rem;
    }

    .om-header {
        width: 50px;
        height: 50px;
    }

    .date-dropdowns {
        flex-direction: column;
    }
}

/* ==================== ACCESSIBILITY ==================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --card-bg: white;
        --card-border: #000;
    }

    .input-area,
    .chat-item,
    .modal-content {
        border-width: 3px;
    }
}