/* ===== 全局变量 - 移动应用风格 ===== */
:root {
    --primary: #5b7cfa;
    --primary-light: #eef1ff;
    --primary-dark: #4a6ae0;
    --bg: #f2f4f8;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --border: rgba(0,0,0,0.05);
    --radius: 16px;
    --shadow: 0 8px 24px rgba(0,0,0,0.04), 0 2px 6px rgba(0,0,0,0.02);
    --shadow-hover: 0 12px 32px rgba(0,0,0,0.06);
}
* { margin:0; padding:0; box-sizing:border-box; }

/* ===== 全局防溢出 ===== */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
}
#app {
    max-width: 1200px;
    width:100%;
    background:var(--bg);
    min-height:100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

/* ===== 所有容器防溢出 ===== */
.app-layout,
.main-content,
#mainContent,
.view,
.detail-actions,
.share-section,
.editor-wrapper,
.file-list,
.file-card,
.navbar,
.sidebar,
.modal-content {
    max-width: 100%;
    overflow-x: hidden;
}

/* ===== 按钮 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    background: var(--border);
    color: var(--text);
    transition: all 0.15s ease;
    white-space: nowrap;
    min-height: 44px;
    min-width: 44px;
    flex-shrink: 0;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); background: var(--primary-light); }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; min-width: 32px; }
.btn-block { width: 100%; justify-content: center; }

/* ===== 顶部导航 ===== */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 32px;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    max-width: 100%;
    overflow: hidden;
}
.navbar-brand {
    font-weight: 700;
    font-size: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.hamburger {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    padding: 4px;
    color: var(--text);
    flex-shrink: 0;
}
#userBadge {
    font-size: 13px;
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 12px;
    border-radius: 20px;
    font-weight: 500;
    display: none;
    flex-shrink: 0;
}
#userBadge.show { display: inline-block; }
.vip-badge {
    font-size: 11px;
    background: #fbbf24;
    color: #78350f;
    padding: 2px 12px;
    border-radius: 20px;
    font-weight: 600;
    display: none;
    flex-shrink: 0;
}

/* ===== 侧边栏 ===== */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 999;
    display: none;
}
.sidebar-backdrop.active { display: block; }
.sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    background: #fff;
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar.open { transform: translateY(0); }
.sidebar-header {
    padding: 16px 20px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-header .brand { font-weight: 600; font-size: 18px; }
.sidebar-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}
.sidebar-user {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}
.sidebar-user .avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: var(--primary);
    flex-shrink: 0;
}
.sidebar-user .user-info { flex:1; min-width:0; }
.sidebar-user .user-name { font-weight:600; font-size:16px; }
.sidebar-user .user-status { font-size:13px; color:var(--text-secondary); }
.sidebar-nav {
    flex:1;
    overflow-y:auto;
    padding: 8px 0 16px;
}
.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    color: var(--text);
    cursor: pointer;
    transition: 0.1s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 16px;
    font-family: inherit;
    border-radius: 0;
}
.sidebar-nav .nav-item:hover { background: var(--primary-light); }
.sidebar-nav .nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}
.sidebar-nav .nav-item .icon { font-size: 22px; width: 28px; text-align: center; flex-shrink:0; }
.sidebar-nav .nav-divider { height:1px; background:var(--border); margin:8px 16px; }

/* 桌面端侧边栏常驻 */
@media (min-width: 769px) {
    .sidebar {
        position: sticky;
        top: 0;
        transform: translateY(0);
        border-radius: 0;
        max-height: 100vh;
        width: 280px;
        flex-shrink: 0;
        box-shadow: none;
        border-right: 1px solid var(--border);
        background: #fff;
        z-index: 1;
        bottom: auto;
        left: auto;
        right: auto;
    }
    .sidebar-backdrop { display: none !important; }
    .hamburger { display: none; }
    .app-layout { display: flex; flex-direction: row; }
    .main-content { flex:1; overflow-y:auto; height:100vh; }
    .sidebar-close-mobile { display: none; }
}

/* ===== 主内容 ===== */
.main-content {
    display: flex;
    flex-direction: column;
    flex:1;
    min-height: 100vh;
    max-width: 100%;
    overflow-x: hidden;
}
#mainContent {
    flex:1;
    display:flex;
    flex-direction:column;
    padding: 16px;
    max-width: 100%;
    overflow-x: hidden;
}
.view { display:none; flex-direction:column; flex:1; gap: 16px; max-width:100%; overflow-x:hidden; }
.view.active { display:flex; }

/* ===== 列表视图 ===== */
.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
    max-width: 100%;
    flex-wrap: wrap;
}
.list-title { font-size: 20px; font-weight: 700; flex-shrink:0; }
.file-count { font-size: 14px; color: var(--text-secondary); flex-shrink:0; }
.file-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex:1;
    max-width:100%;
}
.file-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    transition: 0.15s;
    border: 1px solid var(--border);
    max-width:100%;
    overflow:hidden;
}
.file-card:active {
    background: var(--primary-light);
    transform: scale(0.99);
}
.file-card .card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    max-width:100%;
}
.file-card .file-name {
    font-weight: 600;
    font-size: 17px;
    word-break: break-word;
    flex: 1;
    margin-right: 10px;
    min-width:0;
}
.file-card .file-type-badge {
    font-size: 11px;
    background: var(--border);
    padding: 2px 12px;
    border-radius: 20px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
}
.file-card .file-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}
.file-card .file-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.file-card .file-actions .btn {
    font-size: 13px;
    padding: 4px 12px;
    background: transparent;
    color: var(--text-secondary);
}
.file-card .file-actions .btn:hover { color: var(--primary); }
.file-card .file-actions .btn.danger:hover { color: #ef4444; }
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex:1;
    padding: 40px 20px;
    color: var(--text-secondary);
    text-align: center;
}
.empty-icon { font-size: 64px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 17px; }
.empty-hint { font-size: 14px; margin-top: 6px; opacity: 0.7; }

/* ===== 详情视图（编辑器） ===== */
.detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    max-width:100%;
    flex-wrap: wrap;
}
.detail-filename {
    font-weight: 600;
    font-size: 18px;
    flex:1;
    min-width:0;
    word-break: break-word;
}
.detail-type {
    font-size: 12px;
    background: var(--border);
    padding: 2px 14px;
    border-radius: 20px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink:0;
}
.editor-wrapper {
    display: flex;
    flex-direction: column;
    flex:1;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
    max-width:100%;
}
.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    color: var(--text-secondary);
    flex-shrink:0;
    flex-wrap: wrap;
    gap: 8px;
}
.editor-toolbar .file-info { display: flex; gap: 10px; flex-wrap: wrap; }
.editor-container {
    flex:1;
    padding: 8px 12px;
    position: relative;
}
.editor-container textarea {
    width: 100%;
    height: 100%;
    min-height: 120px;
    border: none;
    outline: none;
    resize: vertical;
    font-family: 'SF Mono', 'Courier New', monospace;
    font-size: 15px;
    line-height: 1.7;
    background: transparent;
    color: var(--text);
}
.json-format-btn {
    position: absolute;
    bottom: 14px;
    right: 14px;
    z-index: 2;
}

/* ===== 底部详情操作栏（强制防溢出） ===== */
.detail-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 0 0;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    max-width: 100%;
    overflow: hidden;
}
.detail-actions .share-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    flex-wrap: nowrap;
}
.detail-actions .share-url {
    flex: 1;
    min-width: 20px;
    max-width: 100%;
    background: var(--bg);
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 13px;
    color: var(--primary);
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid var(--border);
    box-sizing: border-box;
    word-break: break-all;
    display: inline-block;
}
.detail-actions .share-url.placeholder {
    color: var(--text-secondary);
    font-weight: 400;
}
.detail-actions .share-section .btn {
    flex-shrink: 0;
}
.detail-actions .action-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.detail-actions .action-buttons .btn {
    padding: 12px 24px;
    font-size: 15px;
    border-radius: 12px;
    min-height: 48px;
}

/* ===== 移动端极限压缩 + 提高编辑框高度 ===== */
@media (max-width: 640px) {
    .navbar { padding: 10px 20px; }
    .navbar-brand { font-size: 18px; }
    #userBadge { font-size: 12px; padding: 0 10px; }

    .main-content { padding: 0; }
    #mainContent {
        padding: 4px 12px;
    }
    .view {
        gap: 8px;
    }

    .file-card { padding: 14px 16px; }
    .file-card .file-name { font-size: 16px; }

    /* ===== 提高编辑框高度 ===== */
    .editor-wrapper {
        flex: 0 0 auto;          /* 不拉伸 */
        max-height: 640px;       /* 更高，但不超过屏幕 */
    }
    .editor-container {
        padding: 2px 8px;
        flex: 1;
        overflow: hidden;
    }
    .editor-container textarea {
        min-height: 200px;       /* 基础高度提高 */
        max-height: 620px;       /* 滚动上限提高 */
        height: auto;
        resize: vertical;
        overflow-y: auto;
        font-size: 14px;
        line-height: 1.6;
    }

    .detail-actions {
        padding: 4px 0 0;
        margin-top: 4px;
        gap: 8px;
    }
    .detail-actions .action-buttons .btn {
        padding: 8px 14px;
        font-size: 14px;
        min-height: 36px;
    }
    .detail-header {
        padding-bottom: 6px;
        gap: 8px;
    }
    .detail-filename { font-size: 16px; }

    .modal-content { margin: 10px; max-width: 95%; }
    .btn { font-size: 14px; min-height: 40px; }
    .btn-sm { font-size: 12px; min-height: 28px; }
    .sidebar { border-radius: var(--radius) var(--radius) 0 0; }
    .sidebar-header .brand { font-size: 17px; }
    .sidebar-nav .nav-item { padding: 16px 20px; font-size: 16px; }
    .sidebar-nav .nav-item .icon { font-size: 20px; }
    .captcha-row img { height: 38px; }

    .detail-actions .share-url {
        font-size: 12px;
        padding: 4px 8px;
        min-width: 20px;
    }
    .detail-actions .share-section {
        gap: 6px;
    }
}

/* ===== 模态框 ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.modal.active { display: flex; }
.modal-content {
    background: #fff;
    border-radius: var(--radius);
    max-width: 400px;
    width:100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    animation: modalIn 0.3s ease;
}
@keyframes modalIn {
    from { opacity:0; transform: scale(0.92); }
    to { opacity:1; transform: scale(1); }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 20px; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
}
.modal-body { padding: 20px; }
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 15px;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    background: #fafcff;
    transition: 0.15s;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.captcha-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.captcha-row input { flex:1; }
.captcha-row img {
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
}
.auth-switch { text-align: center; margin-top: 16px; font-size: 15px; }
.auth-switch .btn-link { font-size: 15px; }
.auth-message { margin-top: 12px; font-size: 14px; color: #dc2626; text-align: center; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 400px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    background: #1e293b;
    color: #fff;
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideUp 0.3s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }
.toast.info { background: #2563eb; }
.toast .toast-close { background:none; border:none; color:inherit; font-size:22px; cursor:pointer; }
@keyframes slideUp {
    from { opacity:0; transform: translateY(20px); }
    to { opacity:1; transform: translateY(0); }
}

/* ===== 加载遮罩 ===== */
.loading-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 20;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
}
.loading-overlay.active { display: flex; }
.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 额外细节 ===== */
.file-card .card-top {
    cursor: pointer;
}
.sidebar-close-mobile {
    display: none;
}
@media (max-width: 768px) {
    .sidebar-close-mobile {
        display: block;
    }
}
@media (min-width: 769px) {
    .sidebar {
        border-radius: 0;
    }
}