/* ========================================
   RESPONSIVE/MOBILE-FRIENDLY STYLES
   ======================================== */

/* ----------------
   1. CSS CUSTOM PROPERTIES FOR BREAKPOINTS
   ---------------- */
:root {
    --breakpoint-xs: 320px;
    --breakpoint-sm: 480px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;
}

/* ----------------
   2. BASE RESPONSIVE UTILITIES
   ---------------- */

/* Fluid typography */
html {
    font-size: 16px;
}

@media (max-width: 768px) {
    html {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
}

/* Container responsive padding */
.container,
.dashboard-container,
.docs-container {
    width: 100%;
    padding-left: 20px;
    padding-right: 20px;
}

@media (max-width: 480px) {
    .container,
    .dashboard-container,
    .docs-container {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ----------------
   3. HOME PAGE MOBILE STYLES
   ---------------- */

/* HUD Panel responsive */
@media (max-width: 1024px) {
    .hud-panel.right-panel {
        width: 280px;
        right: 20px;
        padding: 20px;
    }
    
    .info-title {
        font-size: 20px;
    }
    
    .status-grid {
        gap: 8px;
    }
}

@media (max-width: 768px) {
    .hud-panel.right-panel {
        position: fixed;
        top: auto;
        bottom: 100px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: 100%;
        transform: none;
        max-height: 50vh;
        overflow-y: auto;
        padding: 16px;
        border-radius: 16px;
    }
    
    .navbar-home {
        padding: 16px 20px;
    }
    
    .logo-home {
        font-size: 20px;
    }
    
    .home-main {
        bottom: 20px;
    }
    
    .scan-button {
        padding: 14px 24px;
    }
    
    .button-text {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .hud-panel.right-panel {
        bottom: 80px;
        max-height: 40vh;
    }
    
    .status-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .feature-list {
        font-size: 13px;
    }
    
    .feature-item {
        padding: 6px 0;
    }
}

/* Content sections responsive */
@media (max-width: 768px) {
    .content-section {
        padding: 60px 16px;
        min-height: auto;
    }
    
    .glass-panel {
        padding: 30px 20px;
        border-radius: 16px;
    }
    
    .section-content h2 {
        font-size: 28px;
        margin-bottom: 16px;
    }
    
    .section-content p {
        font-size: 16px;
        margin-bottom: 24px;
    }
    
    .stat-num {
        font-size: 28px;
    }
    
    .stat-label {
        font-size: 12px;
    }
}

/* ----------------
   4. AUTH PAGES (LOGIN/REGISTER) MOBILE
   ---------------- */

@media (max-width: 768px) {
    .navbar {
        padding: 16px 20px;
    }
    
    .navbar .container {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .nav-brand h1 a {
        font-size: 18px;
    }
    
    .auth-container {
        padding: 80px 16px 40px;
        align-items: flex-start;
    }
    
    .auth-card {
        padding: 30px 24px;
        border-radius: 16px;
        max-width: 100%;
    }
    
    .auth-card h2 {
        font-size: 24px;
        margin-bottom: 24px;
    }
    
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-group input,
    .form-group select,
    .form-control {
        padding: 14px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .btn {
        padding: 14px 24px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .auth-container {
        padding-top: 70px;
    }
    
    .auth-card {
        padding: 24px 20px;
    }
}

/* ----------------
   5. DASHBOARD LAYOUT MOBILE
   ---------------- */

@media (max-width: 1024px) {
    .main-content {
        padding: 30px;
    }
    
    .dashboard-card {
        padding: 24px;
    }
}

@media (max-width: 768px) {
    /* Sidebar becomes overlay */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        width: 280px;
    }
    
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    }
    
    /* Backdrop when sidebar is open */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    .sidebar-backdrop.show {
        display: block;
    }
    
    .close-sidebar-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        margin-left: auto;
    }
    
    .main-content {
        margin-left: 0;
        padding: 20px;
    }
    
    .mobile-header {
        display: flex;
        margin: -20px -20px 20px -20px;
        padding: 16px 20px;
    }
    
    .mobile-header h2 {
        font-size: 18px;
        margin: 0;
    }
    
    .dashboard-container h1 {
        display: none;
    }
    
    .dashboard-card {
        padding: 20px;
        margin-bottom: 20px;
        border-radius: 16px;
    }
    
    .dashboard-card h2 {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 16px;
    }
    
    .mobile-header {
        margin: -16px -16px 16px -16px;
        padding: 14px 16px;
    }
    
    .dashboard-card {
        padding: 16px;
        border-radius: 12px;
    }
}

/* ----------------
   6. FEATURE GRID RESPONSIVE
   ---------------- */

@media (max-width: 1200px) {
    .feature-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .feature-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .feature-card {
        padding: 20px;
    }
}

/* Dashboard feature grid */
@media (max-width: 900px) {
    [style*="grid-template-columns: repeat(auto-fit, minmax(300px, 1fr))"] {
        grid-template-columns: 1fr !important;
    }
}

/* Status grid responsive */
@media (max-width: 600px) {
    [style*="grid-template-columns: repeat(auto-fit, minmax(150px, 1fr))"] {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }
}

/* ----------------
   7. TABLES RESPONSIVE
   ---------------- */

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .data-table,
    .user-table {
        min-width: 600px;
    }
    
    .data-table th,
    .data-table td,
    .user-table th,
    .user-table td {
        padding: 10px 8px;
        font-size: 0.9rem;
    }
}

/* Card-style tables for very small screens */
@media (max-width: 480px) {
    .table-responsive.table-cards table,
    .table-responsive.table-cards thead,
    .table-responsive.table-cards tbody,
    .table-responsive.table-cards th,
    .table-responsive.table-cards td,
    .table-responsive.table-cards tr {
        display: block;
    }
    
    .table-responsive.table-cards thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    .table-responsive.table-cards tr {
        margin-bottom: 16px;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 8px;
        padding: 12px;
    }
    
    .table-responsive.table-cards td {
        border: none;
        position: relative;
        padding: 8px 8px 8px 45%;
        text-align: right;
    }
    
    .table-responsive.table-cards td::before {
        content: attr(data-label);
        position: absolute;
        left: 12px;
        width: 40%;
        font-weight: 600;
        text-align: left;
        color: var(--text-secondary);
    }
}

/* ----------------
   8. QUICK LINKS RESPONSIVE
   ---------------- */

@media (max-width: 768px) {
    .quick-links {
        flex-direction: column;
        gap: 10px;
    }
    
    .quick-links li a {
        display: block;
        width: 100%;
        text-align: center;
    }
}

/* ----------------
   9. CHAT INTERFACE MOBILE
   ---------------- */

@media (max-width: 900px) {
    .chat-layout {
        grid-template-columns: 1fr;
        height: calc(100vh - 120px);
    }
    
    .conversations-sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        border-radius: 0;
        margin: 0;
    }
    
    .conversations-sidebar.mobile-open {
        display: flex;
    }
    
    .close-mobile-sidebar {
        display: block;
    }
    
    .mobile-conv-toggle {
        display: flex;
    }
}

@media (max-width: 480px) {
    .chat-layout {
        height: calc(100vh - 100px);
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .message {
        max-width: 90%;
        padding: 10px 14px;
    }
    
    .chat-input-area {
        padding: 12px 16px;
        gap: 8px;
    }
    
    .chat-input {
        padding: 10px 12px;
        font-size: 16px; /* Prevent zoom */
    }
    
    .send-btn,
    .voice-btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }
    
    .voice-settings {
        flex-wrap: wrap;
        padding: 8px 16px;
        font-size: 0.8rem;
    }
}

/* ----------------
   10. ADMIN PANEL MOBILE
   ---------------- */

@media (max-width: 1100px) {
    .vision-main-area {
        grid-template-columns: 1fr;
    }
    
    .vision-data-sidebar {
        max-height: 200px;
    }
    
    .llm-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .tabs {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .tab-btn {
        padding: 8px 16px;
        font-size: 0.9rem;
        flex: 1 1 auto;
        text-align: center;
    }
    
    .vision-settings-grid {
        grid-template-columns: 1fr;
    }
    
    .vision-toggles-panel {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .vision-enhancements-bar {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .vision-feed-container {
        aspect-ratio: 16/9;
    }
    
    /* Speech panel grid */
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .vision-toggles-panel {
        grid-template-columns: 1fr;
    }
    
    .api-tester-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .api-tester-grid select,
    .api-tester-grid button {
        width: 100%;
    }
}

/* ----------------
   11. API DOCS MOBILE
   ---------------- */

@media (max-width: 900px) {
    .layout-wrapper {
        flex-direction: column;
    }
    
    .docs-sidebar {
        display: none;
    }
    
    .docs-main {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .docs-section {
        padding: 20px 16px;
    }
    
    .endpoint {
        padding: 12px;
    }
    
    .endpoint-header {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .endpoint-path {
        font-size: 0.9em;
        word-break: break-all;
    }
    
    .auth-badge {
        margin-left: 0;
    }
    
    .sdk-grid {
        grid-template-columns: 1fr;
    }
    
    .tab-buttons {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
    }
    
    .tab-button {
        flex-shrink: 0;
    }
    
    pre {
        font-size: 0.8em;
        padding: 12px;
    }
}

/* ----------------
   12. ACCOUNT PAGE MOBILE
   ---------------- */

@media (max-width: 768px) {
    .vision-grid,
    .video-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
    }
    
    /* API keys section */
    .form-group > div[style*="display: flex"] {
        flex-direction: column;
        gap: 8px !important;
    }
    
    .form-group > div[style*="display: flex"] input {
        width: 100% !important;
    }
    
    .form-group > div[style*="display: flex"] button {
        width: 100% !important;
    }
}

/* ----------------
   13. BUTTONS MOBILE
   ---------------- */

@media (max-width: 480px) {
    .btn {
        padding: 12px 20px;
        width: 100%;
    }
    
    .btn-block {
        display: block;
    }
    
    /* Button groups stack vertically */
    .btn-group,
    [style*="display: flex"][style*="gap"] {
        flex-direction: column;
    }
}

/* ----------------
   14. FORMS MOBILE
   ---------------- */

@media (max-width: 480px) {
    .form-group label {
        font-size: 14px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea,
    .form-control {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 14px;
    }
    
    .form-group small {
        font-size: 12px;
    }
}

/* ----------------
   15. MODALS MOBILE
   ---------------- */

@media (max-width: 768px) {
    [role="dialog"],
    .modal {
        width: calc(100% - 32px) !important;
        max-width: 100% !important;
        margin: 16px;
        max-height: calc(100vh - 32px);
        overflow-y: auto;
    }
}

/* ----------------
   16. PRINT STYLES
   ---------------- */

@media print {
    .sidebar,
    .mobile-header,
    .hud-container,
    .scan-overlay,
    .cyberpunk-filter,
    nav,
    button:not(.print-visible),
    .btn:not(.print-visible) {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 20px !important;
    }
    
    body {
        background: #fff !important;
        color: #000 !important;
    }
    
    .glass-panel,
    .dashboard-card,
    .auth-card {
        background: #fff !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
    }
}

/* ----------------
   17. LANDSCAPE MOBILE
   ---------------- */

@media (max-height: 500px) and (orientation: landscape) {
    .auth-container {
        padding-top: 60px;
        padding-bottom: 20px;
    }
    
    .hud-panel.right-panel {
        max-height: 70vh;
    }
    
    .chat-layout {
        height: calc(100vh - 80px);
    }
}

/* ----------------
   18. SAFE AREA INSETS (Notch devices)
   ---------------- */

@supports (padding: env(safe-area-inset-top)) {
    .navbar,
    .navbar-home,
    .mobile-header {
        padding-top: max(16px, env(safe-area-inset-top));
    }
    
    .sidebar {
        padding-left: env(safe-area-inset-left);
    }
    
    .main-content {
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .chat-input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* ----------------
   19. TOUCH IMPROVEMENTS
   ---------------- */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .nav-item {
        padding: 14px 18px;
    }
    
    .feature-item {
        padding: 12px 0;
    }
    
    .toggle-chip {
        padding: 10px 12px;
    }
    
    /* Remove hover effects that don't work on touch */
    .hud-panel:hover,
    .feature-card:hover,
    .btn:hover {
        transform: none;
    }
}

/* ----------------
   20. DARK MODE ADJUSTMENTS
   ---------------- */

@media (prefers-color-scheme: light) {
    /* If user prefers light mode, these overrides can apply */
    /* Currently the site is dark-themed, so no changes needed */
}
