/* ════════════════════════════════════════════════════════════════════════
   RESPONSIVE DESIGN - Mobile & Tablet Optimization
   ════════════════════════════════════════════════════════════════════════ */

/* ─ Tablet (768px - 1024px) ─ */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 240px;
    }
    
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        position: fixed;
        left: -240px;
        height: 100dvh;
        z-index: 999;
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    
    .sidebar.open {
        transform: translateX(240px);
    }
    
    .chat-main {
        width: 100%;
        margin-left: 0;
    }
    
    .provider-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }
}

/* ─ Mobile (480px - 767px) ─ */
@media (max-width: 767px) {
    :root {
        --sidebar-width: 100%;
        --header-height: 56px;
    }
    
    * {
        font-size: 14px;
    }
    
    body {
        height: 100dvh;
    }
    
    .app-container {
        height: 100%;
    }
    
    .sidebar {
        width: 100%;
        left: -100%;
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        padding-right: 16px;
        transform: translateX(0); /* Using transform for performance */
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .brand {
        flex-direction: column;
        text-align: center;
        margin-bottom: 12px;
    }
    
    .brand h2 {
        font-size: 1.1rem;
    }
    
    .new-chat-btn {
        width: 100%;
        margin: 12px 0;
    }
    
    .conversations-list {
        max-height: 180px; /* More room for conversations */
    }
    
    .templates-grid {
        max-height: 180px; /* More room for templates */
        grid-template-columns: 1fr;
    }
    
    .tips-list {
        max-height: 150px;
    }

    .features-list ul {
        gap: 10px; /* Better spacing for capabilities */
    }
    
    .chat-header {
        padding: 8px 12px;
        height: var(--header-height);
    }
    
    .header-info h1 {
        font-size: 1rem;
    }
    
    .chat-container {
        height: calc(100dvh - var(--header-height) - 140px);
        gap: 8px;
    }
    
    .message {
        margin: 6px 0;
        padding: 8px;
    }
    
    .message-content {
        max-width: 85vw;
        font-size: 0.9rem;
        padding: 10px;
    }
    
    .avatar {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .input-toolbar {
        flex-direction: row; /* Keep it in a row if possible */
        justify-content: space-between;
        padding: 5px 10px 8px;
    }
    
    .input-toolbar-left {
        gap: 8px;
    }
    
    .toolbar-model-badge {
        font-size: 0.65rem;
        padding: 2px 8px;
    }
    
    .toolbar-hint {
        display: none;
    }
    
    .code-block-wrapper {
        margin: 8px 0;
    }
    
    .code-block-header {
        padding: 6px 8px;
        font-size: 0.75rem;
    }
    
    .copy-code-btn {
        padding: 4px 6px;
        font-size: 0.7rem;
    }
    
    pre {
        max-width: 100%;
        font-size: 0.75rem;
        border-radius: 4px;
    }
    
    .user-msg-img {
        max-width: 120px;
        max-height: 200px;
    }
    
    .file-preview-item {
        font-size: 0.8rem;
        padding: 6px;
    }
    
    .generated-image-card {
        max-width: 95%;
    }
    
    .generated-image-card img {
        max-height: 300px;
    }
    
    .card-footer {
        padding: 6px;
    }
    
    .prompt-text {
        font-size: 0.7rem;
    }
    
    .download-btn {
        padding: 4px 6px;
        font-size: 0.7rem;
    }
    
    .provider-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }
    
    .provider-btn {
        padding: 10px 4px;
        font-size: 0.8rem;
    }
    
    .provider-icon {
        font-size: 1.2rem;
    }
    
    .provider-name {
        font-size: 0.7rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 80px;
    }
    
    .provider-free-tag {
        font-size: 0.55rem;
        padding: 1px 3px;
        top: 2px;
        right: 2px;
    }
    
    .config-select,
    .config-input-row input {
        font-size: 0.85rem;
        padding: 6px 8px;
    }
    
    .conversation-item {
        padding: 8px 10px;
        font-size: 0.8rem;
    }
    
    .conversation-item-title {
        font-size: 0.75rem;
    }
    
    .template-btn {
        padding: 6px 8px;
        font-size: 0.75rem;
    }
    
    .features-list ul {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    
    .features-list li {
        width: 100%;
        margin-bottom: 0px;
    }
    
    .tip-item {
        padding: 6px;
    }
    
    .tip-item strong {
        font-size: 0.7rem;
    }
    
    .tip-item small {
        font-size: 0.65rem;
    }
    
    .hamburger-btn {
        padding: 4px;
        min-width: auto;
    }
    
    .clear-chat-btn {
        padding: 4px;
        min-width: auto;
    }
    
    .welcome-screen {
        padding: 16px;
        gap: 12px;
    }
    
    .welcome-icon {
        width: 80px;
        height: 80px;
    }
    
    .welcome-screen h2 {
        font-size: 1.2rem;
    }
    
    .provider-pills {
        gap: 6px;
        flex-wrap: wrap;
    }
    
    .provider-pill {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    .suggestion-chips {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .chip {
        padding: 10px;
        font-size: 0.85rem;
    }
    
    .export-modal {
        max-width: 90vw;
        padding: 16px;
    }
    
    .export-modal h3 {
        font-size: 1rem;
    }
    
    .export-option-btn {
        padding: 10px;
        font-size: 0.85rem;
    }
    
    #pwa-install-prompt {
        right: 10px !important;
        left: 10px !important;
        bottom: 70px;
        top: auto;
        max-width: none;
    }
    
    #offline-indicator {
        font-size: 0.85rem;
        padding: 8px;
    }
}

/* ─ Small Mobile (320px - 479px) ─ */
@media (max-width: 479px) {
    :root {
        --radius-xl: 12px;
        --radius-lg: 8px;
    }
    
    * {
        font-size: 13px;
    }
    
    .brand-text h2 {
        font-size: 1rem;
    }
    
    .header-info h1 {
        font-size: 0.95rem;
    }
    
    .status-badge {
        font-size: 0.75rem;
    }
    
    .message-content {
        max-width: 90vw;
        font-size: 0.85rem;
    }
    
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }
    
    pre {
        font-size: 0.7rem;
        padding: 8px;
        border-radius: 4px;
    }
    
    code {
        font-size: 0.7rem;
    }
    
    #user-input {
        font-size: 13px !important;
        padding: 8px !important;
    }
    
    .send-btn,
    .attachment-btn {
        min-width: 36px;
        height: 36px;
    }
    
    .user-msg-img {
        max-width: 100px;
        max-height: 180px;
    }
    
    .chip {
        padding: 8px;
        font-size: 0.8rem;
    }
    
    .welcome-icon {
        width: 64px;
        height: 64px;
    }
    
    .welcome-screen h2 {
        font-size: 1.1rem;
    }
    
    .welcome-screen p {
        font-size: 0.85rem;
    }
    
    .export-modal {
        padding: 12px;
    }
    
    #pwa-install-prompt {
        font-size: 0.85rem;
    }
    
    #pwa-install-prompt > div:first-child {
        font-size: 0.9rem;
        font-weight: 600;
    }
    
    #pwa-install-prompt > div:nth-child(2) {
        font-size: 0.75rem;
    }
}

/* ─ Landscape Orientation ─ */
@media (max-height: 500px) {
    .chat-container {
        height: calc(100vh - 120px);
    }
    
    .message-content {
        max-width: 70vw;
    }
    
    .welcome-screen {
        padding: 8px;
        gap: 8px;
    }
    
    .welcome-icon {
        width: 60px;
        height: 60px;
    }
    
    .suggestion-chips {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ─ Touch Device Optimizations ─ */
@media (hover: none) and (pointer: coarse) {
    button {
        min-height: 44px;
        min-width: 44px;
    }
    
    .send-btn,
    .attachment-btn,
    .clear-chat-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    input,
    textarea,
    select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on focus */
        padding: 8px !important;
    }
    
    #user-input {
        min-height: 44px;
        font-size: 16px !important;
    }
    
    /* Remove hover effects */
    .button:hover,
    button:hover {
        opacity: 1;
    }
    
    /* Add active/tap feedback */
    button:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
}

/* ─ Print Styles ─ */
@media print {
    .sidebar,
    .input-area,
    .chat-header,
    .sidebar-overlay,
    #pwa-install-prompt,
    #offline-indicator {
        display: none;
    }
    
    .chat-container {
        width: 100%;
        background: white;
        color: black;
    }
    
    .message {
        page-break-inside: avoid;
    }
}

/* ─ Reduced Motion ─ */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
