/**
 * Liora Responsive Styles
 * Extracted from templates/index.html (lines 6166-6253)
 */

/* ============================================
   响应式布局
   ============================================ */

/* 平板及以上 */
@media (max-width: 1024px) {
    .sidebar {
        width: 320px;
        min-width: 280px;
    }

    .search-box {
        max-width: 400px;
    }
}

/* 小平板 */
@media (max-width: 900px) {
    .memory-network-controls {
        display: none;
    }

    .time-travel-btn {
        display: none;
    }

    .graph-legend,
    .graph-legend.collapsed,
    #graphLegend {
        display: none !important;
    }

    .pi-trigger-btn {
        display: none !important;
    }

    .luoyi-header {
        display: none;
    }

    /* 显示移动端菜单按钮 */
    .mobile-menu-btn {
        display: inline-flex !important;
    }

    .search-box {
        max-width: none;
        flex: 1;
    }
}

/* 手机 */
@media (max-width: 768px) {
    .header {
        padding: 10px 12px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .logo-img {
        height: 28px;
        width: auto;
    }

    .search-box {
        order: 3;
        width: 100%;
        max-width: none;
        margin-top: 8px;
    }

    .search-input {
        padding: 8px 10px;
        font-size: 14px;
    }

    .search-button {
        padding: 8px 12px;
        font-size: 11px;
    }

    .time-travel-btn {
        display: none;
    }

    .main-content {
        flex-direction: column;
    }

    .graph-section {
        flex: 1;
        min-height: 50vh;
    }

    /* 移动端侧边栏默认隐藏，以抽屉形式呈现 */
    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        max-height: 100vh;
        min-height: auto;
        border-left: none;
        border-top: none;
        z-index: 200;
        background: var(--color-bg);
        flex: none;
    }

    .sidebar.mobile-open {
        display: flex;
    }

    /* 移动端侧边栏头部 */
    .sidebar-mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        border-bottom: 1px solid var(--color-border);
        background: var(--color-bg-secondary);
        flex-shrink: 0;
    }

    .sidebar-mobile-title {
        font-size: 14px;
        font-weight: 600;
        font-family: var(--font-mono);
        letter-spacing: 0.5px;
    }

    .sidebar-mobile-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: 1px solid var(--color-border-light);
        background: var(--color-bg);
        cursor: pointer;
        border-radius: 4px;
        padding: 0;
        color: #000;
    }

    .sidebar-mobile-close:hover {
        border-color: var(--color-memory);
        background: var(--color-memory-light);
    }

    .panel-content {
        flex: 1;
        width: 100%;
        padding: 12px;
    }

    .graph-legend {
        display: none;
    }

    .edge-labels-toggle {
        display: none;
    }

    /* 移动端边标签开关按钮 */
    .mobile-edge-label-btn {
        display: inline-block !important;
    }

    .mobile-edge-label-btn.active {
        background-color: var(--color-memory) !important;
        color: #fff !important;
        border-color: var(--color-memory) !important;
    }

    /* ========== 移动端底部抽屉（Bottom Sheet）========== */
    .detail-panel {
        position: fixed;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: 100% !important;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
        font-size: 12px;
        z-index: 55;
        /* 通过 transform 控制显隐，覆盖桌面端的 display:none */
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
        display: flex;
        /* iOS 底部安全区适配 + 橡皮筋效果抑制 */
        padding-bottom: env(safe-area-inset-bottom, 0);
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    .detail-panel.show {
        transform: translateY(0);
    }

    /* 拖拽手柄 */
    .drag-handle {
        display: block;
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: #ddd;
        border-radius: 2px;
        pointer-events: none;
    }

    .detail-panel-header {
        position: relative;
        padding: 20px 12px 10px;
        gap: 6px;
    }

    /* Tab 栏 */
    .detail-tabs {
        display: flex;
        border-bottom: 1px solid var(--color-border);
        background: #fafafa;
        flex-shrink: 0;
    }

    .detail-tab {
        flex: 1;
        padding: 10px;
        border: none;
        background: none;
        font-size: 13px;
        color: #888;
        cursor: pointer;
        position: relative;
        font-family: var(--font-mono);
        transition: color 0.2s;
    }

    .detail-tab.active {
        color: var(--color-memory);
        font-weight: 600;
    }

    .detail-tab.active::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 25%;
        right: 25%;
        height: 2px;
        background: var(--color-memory);
        border-radius: 1px;
    }

    /* 遮罩层：毛玻璃效果 */
    .detail-panel-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.2);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        z-index: 50;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .detail-panel-overlay.show {
        display: block;
        opacity: 1;
    }

    /* 内容区滚动 */
    .detail-content {
        padding: 12px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
    }

    /* 探索区块在移动端由 Tab 控制，去掉顶部边框和固定高度限制 */
    .detail-explore-section {
        border-top: none !important;
        padding: 12px;
        max-height: none !important;
        overflow-y: auto;
        flex: 1;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
    }

    .form-group {
        margin-bottom: 12px;
    }

    .form-textarea {
        min-height: 80px;
    }

    .recall-panel {
        width: calc(100% - 32px);
        right: 16px;
        left: 16px;
        top: 60px;
        max-height: 50vh;
    }

    .graph-io-buttons {
        bottom: 8px;
        right: 8px;
        left: auto;
    }

    .graph-io-buttons .control-btn {
        padding: 4px 8px;
        font-size: 10px;
    }

    /* .detail-panel-header padding 已在上方定义为 20px 12px 10px，此处不再覆盖 */

    .detail-header-left {
        flex: 1;
        min-width: 0;
    }

    .detail-title {
        font-size: 13px;
    }

    .btn-header-edit,
    .btn-header-delete {
        width: 32px;
        height: 32px;
    }

    .detail-content {
        padding: 12px;
    }

    .detail-row {
        margin-bottom: 10px;
        font-size: 12px;
    }

    .detail-label {
        font-size: 11px;
        min-width: 60px;
    }

    .detail-section {
        margin-top: 12px;
        padding-top: 10px;
    }

    .section-title {
        font-size: 11px;
        margin-bottom: 8px;
    }

    /* 预测按钮 - 只显示图标，与编辑/删除按钮等比例 */
    .btn-predict {
        width: 32px;
        height: 32px;
        padding: 0;
        justify-content: center;
        background: var(--color-bg);
        border-radius: 4px;
        border-color: var(--color-border-light);
    }

    .btn-predict .predict-text {
        display: none;
    }

    .prediction-section {
        padding: 12px;
        margin-bottom: 12px;
    }

    .prediction-label {
        font-size: 14px;
    }

    .prediction-item {
        padding: 10px;
    }

    .prediction-name {
        font-size: 13px;
    }

    .prediction-reason {
        font-size: 11px;
    }

    /* 关系详情面板 */
    .edge-relation-header {
        font-size: 12px;
        padding: 10px;
    }

    /* 热力图移动端适配 */
    .heatmap-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 2px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .heatmap-row {
        display: flex;
        gap: 2px;
        min-width: max-content;
    }

    .heatmap-cell {
        width: 10px;
        height: 10px;
        border-radius: 2px;
        flex-shrink: 0;
    }

    /* 洛忆面板边距修复 */
    #panel-luoyi {
        margin: 0;
    }
}

/* 小屏手机 */
@media (max-width: 480px) {
    .header {
        padding: 8px 10px;
    }

    .logo-img {
        order: 1;
        height: 24px;
    }

    .search-box {
        order: 3;
        margin-top: 6px;
    }

    .graph-header {
        padding: 8px 10px;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .graph-title {
        font-size: 11px;
    }

    .graph-controls {
        flex-wrap: wrap;
        gap: 4px;
    }

    .graph-controls .control-btn {
        padding: 3px 6px;
        font-size: 10px;
    }

    .tabs {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }

    .tab {
        flex: 1;
        white-space: normal;
        padding: 8px 2px;
        font-size: 11px;
        text-align: center;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-number {
        font-size: 18px;
    }

    .stat-label {
        font-size: 11px;
    }

    .graph-legend {
        width: 150px;
        font-size: 9px;
    }

    /* 小屏详情面板进一步优化 */
    .detail-panel {
        max-height: 80vh;
        border-radius: 12px 12px 0 0;
    }

    .detail-panel-header {
        flex-wrap: nowrap;
        padding: 18px 10px 8px;
    }

    .detail-header-actions {
        order: 0;
        width: auto;
        margin-top: 0;
    }

    .btn-header-edit,
    .btn-header-delete {
        width: 36px;
        height: 36px;
    }

    .btn-predict {
        width: 36px;
        height: 36px;
    }

    .prediction-item {
        flex-direction: column;
        gap: 8px;
    }

    .prediction-marker {
        display: none;
    }

    .btn-adopt {
        width: 100%;
        margin-top: 4px;
    }
}

/* 横屏手机 */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 6px 12px;
    }

    .sidebar {
        height: 45vh;
        min-height: 200px;
    }

    .form-textarea {
        min-height: 60px;
    }

    /* 横屏时底部抽屉缩小，避免遮挡整个图谱 */
    .detail-panel {
        max-height: 55vh;
        border-radius: 12px 12px 0 0;
    }
}

/* 触控优化 */
@media (hover: none) and (pointer: coarse) {
    .control-btn,
    .tab,
    .btn {
        min-height: 44px;
    }

    .memory-delete-btn {
        opacity: 1;
        width: 32px;
        height: 32px;
    }

    .detail-close {
        width: 44px;
        height: 44px;
    }
}

/* ========== 节点长按快捷菜单 ========== */
.node-context-menu {
    display: none;
    position: fixed;
    z-index: 100;
    background: #fff;
    border: 1px solid var(--color-border-light);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.15);
    padding: 6px 0;
    min-width: 160px;
    font-size: 13px;
    overflow: hidden;
    animation: menuPop 0.15s ease-out;
}

@keyframes menuPop {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.node-menu-item {
    padding: 11px 16px;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.node-menu-item:active {
    background: var(--color-memory-light);
    color: var(--color-memory);
}

.node-menu-item.danger {
    color: #e74c3c;
}

.node-menu-item.danger:active {
    background: #fdf2f0;
}
