/* ═══════════════════════════════════════════════════════════════════ */
/* RESPONSIVE DESIGN - MOBILE, TABLET, DESKTOP                        */
/* ═══════════════════════════════════════════════════════════════════ */

/* ─── DESKTOP: 769px and above ─── */
@media (min-width: 769px) {
    .hamburger-btn {
        display: none !important;
    }

    .mobile-sidebar {
        display: none !important;
    }

    .mobile-overlay {
        display: none !important;
    }

    #desktopSidebar {
        display: flex !important;
    }
}

/* ─── TABLET: 1024px and below ─── */
@media (max-width: 1024px) {
    .sidebar {
        width: 180px;
    }

    .docs-panel {
        width: 300px;
    }

    .topbar {
        padding: 0 16px;
    }

    .logo span.sub {
        display: none;
    }

    .topbar-center {
        font-size: 12px;
    }

    .panel-header {
        padding: 12px 16px 10px;
    }

    .asset-card-side {
        margin: 0 10px 10px;
    }

    .asset-name-side {
        color: var(--text);
    }
}

/* ─── MOBILE: 768px and below ─── */
@media (max-width: 768px) {
    * {
        box-sizing: border-box;
    }

    html, body {
        height: auto;
        min-height: 100vh;
        overflow-x: hidden !important;
    }

    body {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }

    .main-layout {
        display: flex !important;
        flex-direction: column !important;
        flex: 1;
        width: 100% !important;
        min-height: calc(100vh - 50px);
        overflow: visible !important;
    }

    /* Sidebar transforms to horizontal */
    .sidebar {
        display: none !important;
    }

    #desktopSidebar {
        display: none !important;
    }

    /* Hamburger Menu Button */
    .hamburger-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: transparent;
        border: none;
        color: var(--text);
        font-size: 18px;
        cursor: pointer;
        transition: color 0.2s;
        margin-right: 8px;
    }

    .hamburger-btn:hover {
        color: var(--accent);
    }

    /* Mobile Overlay */
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
    }

    .mobile-overlay.active {
        display: block;
    }

    /* Mobile Drawer Sidebar */
    .mobile-sidebar {
        display: none;
        position: fixed;
        top: 50px;
        left: 0;
        width: 80%;
        max-width: 320px;
        height: calc(100vh - 50px);
        background: var(--navy-light);
        border-right: 1px solid var(--border);
        z-index: 999;
        flex-direction: column;
        overflow-y: auto;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.3);
        animation: slideInLeft 0.3s ease-out;
    }

    .mobile-sidebar.active {
        display: flex;
    }

    @keyframes slideInLeft {
        from {
            transform: translateX(-100%);
        }
        to {
            transform: translateX(0);
        }
    }

    .mobile-sidebar-header {
        padding: 16px 14px;
        border-bottom: 1px solid var(--border);
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
    }

    .mobile-sidebar-header h3 {
        margin: 0;
        font-size: 14px;
        font-weight: 600;
        color: var(--text);
    }

    .close-btn {
        background: none;
        border: none;
        color: var(--text-muted);
        font-size: 18px;
        cursor: pointer;
        padding: 4px;
        transition: color 0.2s;
    }

    .close-btn:hover {
        color: var(--text);
    }

    .mobile-sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding: 12px 0;
    }

    .asset-card-mobile {
        margin: 0 12px 12px;
        padding: 12px;
        background: var(--navy-mid);
        border: 1px solid var(--accent-dim);
        border-radius: 6px;
        display: flex;
        gap: 10px;
        align-items: flex-start;
    }

    .asset-card-mobile .asset-img {
        width: 50px !important;
        height: 50px !important;
        flex-shrink: 0;
    }

    /* Hide desktop sidebar sections, but show mobile drawer sections */
    #desktopSidebar .sidebar-section {
        display: none !important;
    }
    
    .mobile-sidebar .sidebar-section {
        display: block !important;
        margin: 0;
        padding: 0 12px;
    }
    
    /* Hide mobile assets list - show only selected asset card */
    #mobileAssetsList {
        display: none !important;
    }
    
    /* Make conversation list scrollable in mobile drawer */
    .mobile-sidebar .conversation-list {
        max-height: 200px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    .asset-card-side {
        display: flex !important;
        margin: 0 !important;
        padding: 6px 10px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid var(--accent-dim) !important;
        border-radius: 6px !important;
        overflow: visible !important;
        height: 50px !important;
        flex-shrink: 0 !important;
        align-items: center !important;
        gap: 8px !important;
        flex-direction: row !important;
        white-space: nowrap !important;
        margin-right: 10px !important;
        position: relative;
        min-width: fit-content;
    }

    .asset-img {
        width: 38px !important;
        height: 38px !important;
        background: linear-gradient(160deg, #1e3a52 0%, #0a2035 100%) !important;
        border-radius: 4px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 16px !important;
        flex-shrink: 0 !important;
        border: 1px solid var(--border-soft) !important;
    }

    .asset-side-info {
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 1px !important;
        flex: 1 !important;
        min-width: 80px !important;
        max-width: 180px !important;
        justify-content: center;
    }

    .asset-name-side {
        font-size: 12px !important;
        font-weight: 600 !important;
        color: var(--accent-light) !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        line-height: 1.2;
    }

    .asset-meta-side {
        font-size: 9px !important;
        color: var(--text-muted) !important;
        line-height: 1.1 !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .doc-count-side {
        display: none !important;
    }

    .conversationsSection {
        display: none !important;
    }

    .sidebar-section:first-child {
        display: flex !important;
        padding: 0 !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 0 !important;
        margin: 0 !important;
        border-bottom: none !important;
        width: 100% !important;
        height: 50px !important;
        min-height: 50px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
        flex-basis: 100% !important;
        flex: 0 0 100% !important;
    }

    .sidebar-label {
        margin: 0 !important;
        padding: 0 10px !important;
        border-right: 1px solid var(--border-soft);
        margin-right: 0 !important;
        flex-shrink: 0;
        white-space: nowrap;
        font-size: 11px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .assets-list {
        display: flex !important;
        gap: 8px;
        overflow-x: auto !important;
        overflow-y: hidden;
        padding: 0 10px !important;
        flex: 1;
        align-items: center;
        height: 50px;
    }

    .nav-item {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 6px 10px;
    }

    .new-asset-btn {
        flex-shrink: 0 !important;
        white-space: nowrap;
    }

    /* Content Area */
    .content-area {
        flex: 1 !important;
        width: 100% !important;
        height: auto !important;
        min-height: calc(100vh - 100px) !important;
        overflow: visible !important;
        display: flex;
        flex-direction: column;
    }

    .asset-tabs {
        display: none !important;
    }

    /* Two Panels Stack Vertically */
    .panels {
        flex-direction: column !important;
        height: auto !important;
        width: 100% !important;
        min-height: calc(100vh - 100px) !important;
        overflow: visible !important;
    }

    .docs-panel {
        width: 100% !important;
        height: auto !important;
        max-height: 50vh !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
        flex-shrink: 0 !important;
        overflow: auto !important;
    }

    .chat-panel {
        width: 100% !important;
        height: auto !important;
        min-height: 50vh !important;
        flex: 1 !important;
        overflow: auto !important;
    }

    .doc-list {
        max-height: 25vh !important;
        overflow-y: auto;
    }

    .chat-messages {
        max-height: 30vh !important;
        overflow-y: auto;
    }

    /* Topbar */
    .topbar {
        padding: 0 12px;
        height: 50px;
        width: 100%;
    }

    .logo {
        font-size: 16px;
        gap: 6px;
    }

    .logo svg {
        width: 20px;
        height: 20px;
    }

    .topbar-center {
        font-size: 11px;
        flex: 1;
        justify-content: center;
        margin: 0 8px;
    }

    .topbar-center strong {
        display: none;
    }

    .breadcrumb-sep {
        display: none;
    }

    #currentAssetDisplay {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-right {
        gap: 8px;
    }

    .user-pill {
        padding: 3px 8px 3px 4px;
        font-size: 11px;
    }

    .avatar {
        width: 22px;
        height: 22px;
        font-size: 9px;
    }

    /* Panel Headers */
    .panel-header {
        padding: 10px 12px 8px;
    }

    .panel-title {
        font-size: 13px;
    }

    .panel-subtitle {
        font-size: 11px;
    }

    /* Upload Zone */
    .upload-zone {
        margin: 8px 12px;
        padding: 12px;
    }

    .upload-icon {
        font-size: 20px;
        margin-bottom: 4px;
    }

    .upload-text {
        font-size: 11px;
        line-height: 1.4;
    }

    /* Document Items */
    .doc-item {
        padding: 8px 8px;
        gap: 8px;
    }

    .doc-icon {
        width: 30px;
        height: 34px;
        font-size: 14px;
    }

    .doc-name {
        font-size: 12px;
    }

    .doc-meta {
        font-size: 11px;
    }

    .doc-actions {
        opacity: 1;
    }

    /* Chat Area */
    .chat-header {
        padding: 12px 14px;
    }

    .chat-title {
        font-size: 13px;
    }

    .chat-hint {
        font-size: 11px;
    }

    .chat-messages {
        padding: 10px 12px;
    }

    .chat-input-area {
        padding: 10px 12px 12px;
    }

    .doc-context-bar {
        font-size: 11px;
        gap: 4px;
        margin-bottom: 8px;
        flex-wrap: wrap;
    }

    .ctx-tag {
        font-size: 10px;
        padding: 3px 6px;
    }

    .chat-textarea {
        font-size: 13px;
        padding: 8px 10px;
    }

    .send-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
    }

    /* Modals */
    .tree-modal {
        width: 90%;
        max-height: 80vh;
    }

    .delete-modal {
        width: 85%;
        max-height: 85vh;
    }

    /* Chat Messages */
    .msg {
        max-width: 95%;
        margin-bottom: 8px;
    }

    .msg-text {
        font-size: 13px;
        padding: 8px 10px;
    }

    .msg-citations {
        margin-top: 6px;
    }

    .citation {
        font-size: 10px;
        padding: 4px 6px;
    }

    .welcome-sub {
        font-size: 12px;
        line-height: 1.5;
    }

    /* Mobile Asset Selector Modal */
    .mobile-asset-selector-modal {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        z-index: 1000;
        display: flex;
        align-items: flex-end;
        padding: 16px;
    }

    .mobile-asset-selector-content {
        width: 100%;
        background: var(--navy-light);
        border: 1px solid var(--border);
        border-radius: 12px 12px 0 0;
        max-height: 70vh;
        overflow-y: auto;
        animation: slideUp 0.3s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .mobile-asset-selector-content .modal-header {
        padding: 16px;
        border-bottom: 1px solid var(--border);
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
    }

    .mobile-asset-selector-content .modal-header h3 {
        margin: 0;
        font-size: 14px;
        font-weight: 600;
        color: var(--text);
    }

    .mobile-asset-selector-content .modal-body {
        padding: 12px 0;
    }

    .asset-option {
        padding: 14px 16px;
        border-bottom: 1px solid var(--border-soft);
        cursor: pointer;
        transition: background 0.2s;
    }

    .asset-option:hover {
        background: var(--surface-hover);
    }

    .asset-option.active {
        background: var(--accent-dim);
        border-left: 3px solid var(--accent);
        padding-left: 13px;
    }

    .asset-option-name {
        font-size: 14px;
        font-weight: 500;
        color: var(--text);
        margin-bottom: 4px;
    }

    .asset-option-address {
        font-size: 12px;
        color: var(--text-muted);
    }

    /* Make mobile asset card clickable if multiple assets exist */
    #selectedAssetCardMobile {
        cursor: pointer;
        transition: all 0.2s;
    }

    #selectedAssetCardMobile:active {
        background: var(--surface-hover) !important;
        border-color: var(--accent) !important;
    }
}

/* ─── SMALL MOBILE: 480px and below ─── */
@media (max-width: 480px) {
    .hamburger-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
        margin-right: 6px;
    }

    .mobile-sidebar {
        max-width: 85%;
        width: 85% !important;
    }

    .mobile-sidebar-header {
        padding: 12px 10px;
    }

    .mobile-sidebar-header h3 {
        font-size: 13px;
    }

    .mobile-sidebar-content {
        padding: 8px 0;
    }

    .asset-card-mobile {
        margin: 10px;
        padding: 10px;
    }

    .sidebar {
        width: 100% !important;
        height: auto !important;
        max-height: 50px !important;
    }

    .sidebar-section:first-child {
        width: 100% !important;
        height: 50px !important;
        min-height: 50px !important;
    }

    .asset-card-side {
        width: auto !important;
        height: 40px !important;
        padding: 4px 8px !important;
        margin: 0 6px 0 0 !important;
        border-radius: 4px !important;
        gap: 6px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid var(--accent-dim) !important;
    }

    .asset-img {
        width: 32px !important;
        height: 32px !important;
        font-size: 14px !important;
        flex-shrink: 0 !important;
    }

    .asset-side-info {
        display: flex !important;
        min-width: 80px !important;
        max-width: 120px !important;
    }

    .sidebar-label {
        font-size: 10px;
        padding: 0 8px !important;
    }

    .assets-list {
        padding: 0 8px !important;
    }

    .topbar {
        height: 48px;
        padding: 0 8px;
    }

    .logo {
        font-size: 14px;
        gap: 4px;
    }

    .logo svg {
        width: 18px;
        height: 18px;
    }

    .topbar-center {
        font-size: 10px;
    }

    .user-pill {
        padding: 2px 6px 2px 3px;
        font-size: 10px;
    }

    .avatar {
        width: 20px;
        height: 20px;
        font-size: 8px;
    }

    .badge-demo {
        font-size: 8px;
        padding: 2px 6px;
    }

    .docs-panel {
        max-height: 45vh !important;
    }

    .chat-panel {
        min-height: 55vh !important;
    }

    .doc-list {
        max-height: 20vh !important;
    }

    .chat-messages {
        max-height: 28vh !important;
    }

    .panel-title {
        font-size: 12px;
    }

    .panel-subtitle {
        display: none;
    }

    .upload-zone {
        margin: 6px 10px;
        padding: 10px;
    }

    .upload-icon {
        font-size: 18px;
        margin-bottom: 3px;
    }

    .upload-text {
        font-size: 10px;
        line-height: 1.3;
    }

    .doc-item {
        padding: 6px 6px;
        gap: 6px;
    }

    .doc-icon {
        width: 28px;
        height: 32px;
        font-size: 12px;
    }

    .doc-name {
        font-size: 11px;
    }

    .doc-meta {
        font-size: 10px;
    }

    .chat-header {
        padding: 10px 10px;
    }

    .chat-title {
        font-size: 12px;
    }

    .chat-hint {
        display: none;
    }

    .chat-messages {
        padding: 8px 10px;
    }

    .chat-input-area {
        padding: 8px 10px 10px;
    }

    .doc-context-bar {
        font-size: 10px;
        gap: 3px;
        margin-bottom: 6px;
    }

    .ctx-tag {
        font-size: 9px;
        padding: 2px 5px;
    }

    .input-row {
        gap: 6px;
    }

    .chat-textarea {
        font-size: 12px;
        padding: 6px 8px;
        max-height: 80px;
    }

    .send-btn {
        width: 30px;
        height: 30px;
        min-width: 30px;
    }

    .send-btn svg {
        width: 14px;
        height: 14px;
    }

    .msg-text {
        font-size: 12px;
        padding: 6px 8px;
    }

    .msg-citations {
        margin-top: 4px;
    }

    .citation {
        font-size: 9px;
        padding: 3px 5px;
    }

    .tree-modal,
    .delete-modal {
        width: 92% !important;
        max-height: 90vh;
    }

    .tree-modal-header h2 {
        font-size: 14px;
    }

    .delete-modal-header h3 {
        font-size: 14px;
    }

    .delete-modal-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    .welcome-icon {
        font-size: 32px;
    }

    .welcome-title {
        font-size: 14px;
    }

    .welcome-sub {
        font-size: 11px;
        line-height: 1.4;
    }
}

/* ─── LANDSCAPE MODE ─── */
@media (max-height: 500px) {
    .topbar {
        height: 44px;
        padding: 0 8px;
    }

    .logo svg {
        width: 16px;
        height: 16px;
    }

    .docs-panel {
        max-height: 40vh;
    }

    .chat-panel {
        min-height: 60vh;
    }

    .doc-list {
        max-height: 15vh;
    }

    .chat-messages {
        max-height: 25vh;
    }
}

/* ─── TOUCH DEVICE OPTIMIZATIONS ─── */
@media (hover: none) {
    .doc-item:hover {
        background: var(--surface);
    }

    .doc-actions {
        opacity: 1;
    }

    .doc-delete-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .send-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
}
