/* =========================
   MEET RIVEN RESPONSIVE CSS
   Tablet + Mobile
========================= */


/* =========================
   TABLET / SMALL DESKTOP
   641px - 980px
========================= */

@media (max-width: 980px) {
    .nav-links {
        display: none;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .landing-header {
        position: relative;
        z-index: 1000;
    }

    .nav-actions {
        position: relative;
        z-index: 1001;
    }

    .mobile-menu {
        position: absolute;
        top: calc(100% + 12px);
        right: 0;

        width: min(260px, calc(100vw - 48px));
        padding: 14px;

        display: flex;
        flex-direction: column;
        gap: 10px;

        z-index: 3000;

        border-radius: 22px;
        background: rgba(15, 23, 42, 0.94);
        border: 1px solid rgba(255, 255, 255, 0.12);
        backdrop-filter: blur(20px);
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    }

    .mobile-menu.hidden {
        display: none;
    }

    .mobile-menu a {
        display: block;
        padding: 14px 16px;
        border-radius: 16px;

        color: white;
        text-decoration: none;
        font-size: 15px;

        background: rgba(255, 255, 255, 0.08);
    }
}


/* =========================
   MOBILE GENERAL
   max 640px
========================= */

@media (max-width: 640px) {
    html,
    body {
        width: 100%;
        min-height: 100%;
        margin: 0;
        overflow-x: hidden;

        background:
            radial-gradient(circle at top left, rgba(168, 85, 247, 0.35), transparent 20%),
            radial-gradient(circle at top right, rgba(249, 115, 22, 0.30), transparent 20%),
            linear-gradient(135deg, #1e1b4b, #0f172a 55%, #3b0764);
    }

    .landing-page {
        padding-top: calc(env(safe-area-inset-top) + 26px) !important;
    }

    .landing-header {
        padding: 0 16px 22px !important;

        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    .landing-header .brand {
        max-width: none;
        transform: none;
        font-size: 18px;
        line-height: 1;
    }

    .landing-header .nav-actions {
        transform: none;

        display: flex;
        align-items: center;
        gap: 10px;
    }

    .how-page,
    .pricing-page {
        padding-top: calc(env(safe-area-inset-top) + 26px) !important;
    }

    .how-header,
    .pricing-header {
        padding: 0 16px 28px !important;

        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
    }

    .how-header .brand,
    .pricing-header .brand {
        max-width: 48%;
        transform: none;
        font-size: 18px;
        line-height: 1.2;
    }

    .how-header .back-btn,
    .pricing-header .back-btn {
        min-width: 110px;
        height: 48px;
        padding: 0 22px !important;

        border-radius: 18px;
        font-size: 15px;

        margin: 0;
    }
}


/* =========================
   MOBILE CHAT APP
   WhatsApp-style layout
========================= */

@media (max-width: 640px) {
    #chatScreen {
        position: fixed;
        inset: 0;

        width: 100%;
        height: 100dvh;
        min-height: 100dvh;

        padding: 0 !important;
        overflow: hidden;
        overscroll-behavior: none;

        align-items: stretch;
        justify-content: stretch;

        background:
            radial-gradient(circle at top left, rgba(168, 85, 247, 0.28), transparent 35%),
            radial-gradient(circle at top right, rgba(249, 115, 22, 0.22), transparent 35%),
            linear-gradient(135deg, #1e1b4b, #0f172a 55%, #3b0764);
    }

    #chatScreen .chat-container {
        width: 100%;
        height: 100dvh;
        max-width: none;

        border: none;
        border-radius: 0;

        overflow: hidden;

        display: grid;
        grid-template-rows: auto 1fr auto;

        background: rgba(15, 23, 42, 0.92);
    }

    #chatScreen .chat-header {
        position: relative;
        z-index: 100;

        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 12px;

        min-height: 74px;

        padding:
            calc(env(safe-area-inset-top) + 10px)
            24px
            10px;

        background: rgba(15, 23, 42, 0.98);
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        backdrop-filter: blur(18px);
    }

    #chatScreen .chat-header h1 {
        margin: 0 0 3px;
        font-size: 24px;
        line-height: 1.1;
    }

    #chatScreen .chat-header p {
        font-size: 13px;
        color: rgba(255, 255, 255, 0.55);
    }

    #chatScreen .header-right {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    #chatScreen .user-info,
    #chatScreen #logoutBtn {
        display: none;
    }

    #chatScreen #backFromChatBtn,
    #chatScreen #settingsBtn {
        width: 42px;
        height: 42px;
        padding: 0;

        display: flex;
        align-items: center;
        justify-content: center;

        border-radius: 999px;
        font-size: 0;
    }

    #chatScreen #backFromChatBtn::before {
        content: "←";
        font-size: 24px;
        color: white;
    }

    #chatScreen #settingsBtn::before {
        content: "⚙";
        font-size: 20px;
        line-height: 1;
    }

    #chatScreen .chat-feed {
        min-height: 0;

        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        overscroll-behavior: contain;

        display: flex;
        flex-direction: column;
        gap: 14px;

        padding: 16px 14px 12px;
    }

    #chatScreen .message-row {
        max-width: 86%;
    }

    #chatScreen .bot-row {
        align-self: flex-start;
    }

    #chatScreen .user-row {
        align-self: flex-end;
    }

    #chatScreen .message-meta {
        margin-bottom: 5px;
        font-size: 12px;
        color: rgba(255, 255, 255, 0.46);
    }

    #chatScreen .message {
        padding: 12px 14px;
        border-radius: 18px;

        font-size: 15px;
        line-height: 1.45;
    }

    #chatScreen .bot-message {
        border-bottom-left-radius: 6px;
    }

    #chatScreen .user-message {
        border-bottom-right-radius: 6px;
    }

    #chatScreen .message-time {
        margin-top: 5px;
        font-size: 10px;
        opacity: 0.45;
    }

    #chatScreen .chat-composer {
        position: relative;
        z-index: 100;

        width: 100%;
        box-sizing: border-box;

        display: grid !important;
        grid-template-columns: 1fr 46px;
        align-items: center;
        gap: 10px;

        padding:
            7px
            22px
            max(4px, calc(env(safe-area-inset-bottom) - 10px));

        background: rgba(15, 23, 42, 0.98);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        backdrop-filter: blur(18px);
    }

    #chatScreen .chat-composer input {
        min-width: 0;
        width: 100%;
        height: 42px;

        padding: 0 16px;

        border-radius: 999px;

        font-size: 16px;
        line-height: 42px;

        background: rgba(255, 255, 255, 0.09);
        border: 1px solid rgba(255, 255, 255, 0.10);

        color: white;
    }

    #chatScreen .chat-composer input::placeholder {
        color: rgba(255, 255, 255, 0.40);
    }

    #chatScreen .chat-composer button {
        width: 46px;
        height: 46px;
        min-width: 46px;
        padding: 0;

        display: flex;
        align-items: center;
        justify-content: center;

        border-radius: 999px;

        font-size: 0;

        background: linear-gradient(135deg, #ec4899, #f97316);
        box-shadow: 0 10px 24px rgba(249, 115, 22, 0.22);
    }

    #chatScreen .chat-composer button::before {
        content: "➤";
        font-size: 20px;
        transform: translateX(1px);
        color: white;
    }
}


/* =========================
   iPHONE PWA / SAFARI FIX
========================= */

@supports (-webkit-touch-callout: none) {
    @media (max-width: 640px) {
        html,
        body,
        #chatScreen,
        #chatScreen .chat-container {
            height: -webkit-fill-available;
            min-height: -webkit-fill-available;
            background: #0f172a;
        }
    }
}

/* =========================
   MOBILE SETTINGS PAGE
========================= */

@media (max-width: 640px) {
    #settingsScreen {
        padding: calc(env(safe-area-inset-top) + 16px) 10px 70px !important;
        min-height: 100dvh;
        align-items: flex-start;
        overflow-y: auto;
    }

    #settingsScreen .auth-wrapper {
        width: 100%;
        align-items: flex-start;
    }

    #settingsScreen .auth-card {
        width: 100%;
        max-width: 100%;
        padding: 24px 14px;
        border-radius: 26px;
    }

    #settingsScreen .logo {
        display: none;
    }

    #settingsScreen h1 {
        font-size: 42px;
        line-height: 1;
        margin-bottom: 10px;
    }

    #settingsScreen h2 {
        font-size: 24px;
        line-height: 1.15;
    }

    #settingsScreen .subtitle {
        font-size: 16px;
        line-height: 1.5;
        margin-bottom: 22px;
    }

    #settingsScreen .auth-form {
        gap: 18px;
    }

    #settingsScreen .settings-panel,
    #settingsScreen .plan-card,
    #settingsScreen .memory-card {
        width: 100%;
        box-sizing: border-box;
        padding: 22px 16px;
        border-radius: 26px;
        background: rgba(255, 255, 255, 0.055);
        border: 1px solid rgba(255, 255, 255, 0.09);
        overflow: hidden;
    }

    #settingsScreen input,
    #settingsScreen select,
    #settingsScreen button {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    #settingsScreen .choice-label {
        font-size: 12px;
        letter-spacing: 0.13em;
        text-transform: uppercase;
        color: #fbcfe8;
        margin-bottom: 14px;
    }

    #settingsScreen label {
        font-size: 15px;
        letter-spacing: normal;
        text-transform: none;
        color: rgba(255,255,255,0.78);
    }

    #settingsScreen label:has(input[type="checkbox"]) {
        display: grid;
        grid-template-columns: 28px 1fr;
        align-items: center;
        gap: 12px;
        line-height: 1.4;
    }

    #settingsScreen input[type="checkbox"] {
        width: 22px;
        height: 22px;
    }

    #settingsScreen p {
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    #memorySummaryBox {
        max-height: 320px;
        overflow-y: auto;
        padding: 16px;
        border-radius: 20px;
        background: rgba(255, 255, 255, 0.055);
        line-height: 1.65;
    }
    
@media (max-width: 640px) {
    #settingsScreen #dailyTime {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;

        box-sizing: border-box;
        display: block;

        -webkit-appearance: none;
        appearance: none;
    }

    #settingsScreen .settings-panel {
        box-sizing: border-box;
        overflow: hidden;
    }
}

@media (max-width: 640px) {
    .site-footer {
        padding: 34px 20px 46px;
        flex-direction: column;
        gap: 22px;
    }

    .footer-links {
        flex-direction: column;
        gap: 14px;
    }

    .footer-copy {
        white-space: normal;
    }
}

/*Legal pages*/
@media (max-width: 640px) {
    .legal-page {
        padding: calc(env(safe-area-inset-top) + 26px) 14px 60px;
    }

    .legal-header {
        margin-bottom: 28px;
    }

    .legal-card {
        padding: 28px 20px;
        border-radius: 28px;
    }

    .legal-card h1 {
        font-size: 42px;
    }

    .legal-content h2 {
        font-size: 24px;
    }
}

@media (max-width:640px){

    .legal-table{
        display:block;
        overflow-x:auto;
    }

    .legal-highlight{
        padding:18px;
    }

}

@media (max-width: 768px) {

    .auth-page {
        padding: 24px;
        align-items: center;
    }

    .auth-card {
        max-width: 100%;
    }

    .auth-card h1 {
        font-size: 48px;
        line-height: 1;
    }
}

}
