@import "../../theme.css";

*, *::before, *::after { box-sizing: border-box; }
input, textarea, button, select { font-family: inherit; }

body {
    margin: 0; padding: 16px; background-color: var(--bg-main);
    -webkit-font-smoothing: antialiased; color: var(--text-primary);
    height: 100vh; height: 100dvh; box-sizing: border-box; overflow: hidden; letter-spacing: -0.01em;
    width: 100%; max-width: 100%; overflow-x: hidden;
}

*:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }
input:focus, button:focus, textarea:focus, select:focus { outline: none !important; }

.tool-wrapper { display: flex; flex-direction: column; height: 100%; gap: 12px; animation: fadeIn 0.3s ease; width: 100%; max-width: 100%; }
@keyframes fadeIn { from { opacity: 0; transform: translate3d(0, 4px, 0); } to { opacity: 1; transform: translate3d(0, 0, 0); } }

.tool-header { display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.header-main h2 { font-size: 16px; font-weight: 600; margin: 0 0 4px 0; display: flex; align-items: center; gap: 8px;}
.header-main p { margin: 0; font-size: 12px; color: var(--text-secondary); }
.header-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

.badge { font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 4px; letter-spacing: 0.05em; display: inline-block; }
.badge-indigo { background-color: var(--accent-tint); color: var(--accent-color); }
.badge-slate { background-color: var(--bg-active); color: var(--text-secondary); }

.toggle-switch-label { font-size: 11px; font-weight: 600; cursor: pointer; color: var(--text-primary); display: flex; align-items: center; gap: 6px; transition: opacity 0.2s; white-space: nowrap; }
.toggle-switch-label:hover { opacity: 0.8; }
.toggle-switch-label input { accent-color: var(--accent-color); width: 14px; height: 14px; cursor: pointer; margin: 0; }

.btn { border: 1px solid var(--border-color); border-radius: 6px; cursor: pointer; font-weight: 500; transition: all var(--transition-smooth); background-color: #FFF; color: var(--text-primary); display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; font-family: inherit !important; }
.btn-md { height: 32px; padding: 0 14px; font-size: 12px; }
.btn-sm { height: 26px; padding: 0 10px; font-size: 11px; }
.btn-muted { border-color: var(--border-color); color: var(--text-secondary); }
.btn-muted:hover { background-color: var(--bg-active-hover); color: var(--text-primary); }
.btn-primary { background-color: var(--accent-color); color: #FFF; border-color: var(--accent-color); }
.btn-primary:hover { opacity: 0.95; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2); transform: translate3d(0, -1px, 0); }
.btn-primary:active { transform: scale(0.98); }

/* --- 统一流线型 URL 输入条 --- */
.url-bar-container { 
    display: flex; align-items: center; gap: 10px; 
    background-color: var(--bg-card); padding: 12px; 
    border-radius: 12px; border: 1px solid var(--border-color); 
    box-shadow: 0 2px 6px rgba(15,23,42,0.02); flex-shrink: 0; 
    width: 100%; box-sizing: border-box;
}
.url-input-group { 
    display: flex; flex: 1; align-items: center; 
    background-color: #F8FAFC; border: 1px solid var(--border-color); 
    border-radius: 8px; height: 38px; transition: all var(--transition-smooth); 
    overflow: hidden; width: 100%; box-sizing: border-box;
}
.url-input-group:focus-within { border-color: var(--accent-color); background-color: #FFF; box-shadow: 0 0 0 3px var(--accent-tint); }

/* 💡 修复：将 method-select 下拉图标的坐标系修正为标准的 0 0 24 24 容器内以防变形 */
.method-select { 
    border: none; background-color: transparent; height: 100%; padding: 0 26px 0 16px; 
    font-weight: 700; font-size: 12px; color: var(--text-primary); 
    cursor: pointer; outline: none; 
    -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='14' height='14' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); 
    background-repeat: no-repeat; background-position: right 10px center; 
    padding-right: 32px !important;
}
.method-divider { width: 1px; height: 20px; background-color: var(--border-color); margin: 0 4px; }
.url-input { flex: 1; border: none; background: transparent; height: 100%; padding: 0 12px; font-size: 13px; font-family: ui-monospace, monospace; color: var(--text-primary); outline: none; min-width: 0; }
.url-input::placeholder { color: #94A3B8; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

.code-btn-action { height: 38px !important; padding: 0 16px; font-size: 12px !important; border-radius: 8px !important; }
.btn-generate-action { height: 38px !important; padding: 0 20px; font-size: 13px !important; font-weight: 600 !important; border-radius: 8px !important; flex-shrink: 0; }
.btn-generate-action.loading { background-color: #4338CA; cursor: wait; opacity: 0.9; }

/* 经典四宫格网格 */
.workspace-layout { display: flex; gap: 14px; flex: 1; min-height: 0; width: 100%; }
.layout-column { display: flex; flex-direction: column; gap: 14px; flex: 1; min-height: 0; width: 50%; }

.pane { background-color: var(--bg-card); border: 1px solid var(--border-color); border-radius: 12px; display: flex; flex-direction: column; position: relative; min-height: 0; overflow: hidden; box-shadow: 0 2px 6px rgba(15,23,42,0.02); transition: border-color var(--transition-smooth), box-shadow var(--transition-smooth); width: 100%; }
.pane:focus-within { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--accent-tint); }
.req-pane-top, .resp-pane-top { flex: 4; }
.req-pane-bottom, .resp-pane-bottom { flex: 6; }

.pane-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border-color); background-color: #FFF; flex-shrink: 0; min-height: 40px; }
.pane-toolbar.bg-muted { background-color: #F8FAFC; }
.toolbar-title { font-size: 13px; font-weight: 600; color: var(--text-primary); flex-shrink: 0; }

.toolbar-tabs { display: flex; background: rgba(15,23,42,0.04); padding: 2px; border-radius: 6px; border: 1px solid var(--border-color); }
.tab-pill { background: transparent; border: none; padding: 4px 10px; font-size: 11px; font-weight: 600; color: var(--text-secondary); border-radius: 4px; cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.tab-pill:hover { color: var(--text-primary); }
.tab-pill.active { background: #FFF; color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }

.toolbar-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.action-divider { width: 1px; height: 14px; background-color: var(--border-color); margin: 0 4px; }

.crypto-toolbar { gap: 6px; }
.mini-select, .mini-input { border: 1px solid var(--border-color); border-radius: 4px; height: 26px; padding: 0 8px; font-size: 11px; background-color: #F8FAFC; color: var(--text-primary); outline: none; transition: border-color 0.2s; font-family: inherit; }
.mini-select:focus, .mini-input:focus { border-color: var(--accent-color); background-color: #FFF; }
.mini-input { width: 75px; font-family: ui-monospace, monospace; }

/* 💡 修复：同样为工具栏小下拉框加入 24x24 的 viewBox 防止截断 */
.arrow-select { 
    -webkit-appearance: none; appearance: none; 
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='12' height='12' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); 
    background-repeat: no-repeat; background-position: right 6px center; 
    padding-right: 22px !important; cursor: pointer; 
}

.action-btn { background: none; border: 1px solid var(--border-color); color: var(--text-secondary); height: 26px; padding: 0 10px; border-radius: 4px; cursor: pointer; font-size: 11px; font-weight: 500; transition: all var(--transition-smooth); display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.action-btn:hover { background-color: var(--bg-active-hover); color: var(--text-primary); border-color: var(--text-secondary); }
.text-accent { color: var(--accent-color); }
.font-bold { font-weight: 600; }

.raw-editor { flex: 1; border: none; padding: 12px 14px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; line-height: 1.55; color: var(--text-primary); background-color: transparent; resize: none; outline: none; word-break: break-all; white-space: pre-wrap; width: 100%; box-sizing: border-box; }
.raw-editor::-webkit-scrollbar { width: 6px; height: 6px; }
.raw-editor::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.1); border-radius: 3px; }
.raw-editor::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.2); }
.raw-editor::placeholder { color: #94A3B8; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.readonly-editor { background-color: #FAFAFA; color: #334155; }

/* 响应高亮展示与网页沙盒 */
.code-viewer-container { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; background-color: #FAFAFA; width: 100%; }
.code-viewer { margin: 0; position: absolute; inset: 0; overflow: auto; padding: 12px 14px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; line-height: 1.5; color: #334155; white-space: pre-wrap; word-wrap: break-word; -webkit-overflow-scrolling: touch; }
.code-viewer::-webkit-scrollbar { width: 8px; height: 8px; }
.code-viewer::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.15); border-radius: 4px; }
.preview-iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; background: #FFF; }

.json-key { color: #4338CA; font-weight: 600; }
.json-string { color: #059669; }
.json-number { color: #D97706; }
.json-boolean { color: #2563EB; font-weight: 600; }
.json-null { color: #94A3B8; font-style: italic; }

.resp-stats { display: flex; gap: 8px; font-size: 11px; flex-wrap: wrap; }
.stat-badge { font-weight: 600; font-family: ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: rgba(15,23,42,0.04); color: var(--text-secondary); white-space: nowrap; }
.stat-badge .val.status-green { color: #10B981; }
.stat-badge .val.status-yellow { color: #F59E0B; }
.stat-badge .val.status-red { color: #EF4444; }

/* 抽屉 */
.drawer-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.3); backdrop-filter: blur(2px); z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: opacity; }
.drawer-overlay.show { opacity: 1; pointer-events: auto; }

.side-drawer { position: fixed; top: 0; bottom: 0; width: 480px; max-width: 90vw; background: var(--bg-main); box-shadow: 0 0 40px rgba(0,0,0,0.15); z-index: 1001; display: flex; flex-direction: column; will-change: transform; transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
.side-drawer.right-drawer { right: 0; transform: translate3d(100%, 0, 0); }
.side-drawer.right-drawer.show { transform: translate3d(0, 0, 0); }
.side-drawer.left-drawer { left: 0; width: 340px; transform: translate3d(-100%, 0, 0); border-right: 1px solid var(--border-color); }
.side-drawer.left-drawer.show { transform: translate3d(0, 0, 0); }

.drawer-content { display: flex; flex-direction: column; height: 100%; width: 100%; box-sizing: border-box; }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; background: #FFF; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.code-lang-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.lang-tab { background: none; border: none; font-size: 12px; font-weight: 600; color: var(--text-secondary); cursor: pointer; padding: 6px 12px; border-radius: 6px; transition: background 0.2s, color 0.2s; }
.lang-tab:hover { background-color: var(--bg-active-hover); }
.lang-tab.active { background-color: var(--accent-tint); color: var(--accent-color); }

.btn-drawer-close { background: #F1F5F9; border: none; font-size: 16px; color: var(--text-secondary); cursor: pointer; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.btn-drawer-close:hover { background: #FEE2E2; color: #EF4444; }

.drawer-body { padding: 20px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; width: 100%; box-sizing: border-box; }
.drawer-desc { font-size: 11px; color: var(--text-secondary); margin: 0 0 16px 0; line-height: 1.6; }
.drawer-textarea { border: 1px solid var(--border-color); border-radius: 8px; background: #FFF; flex: 1; padding: 16px; font-size: 12.5px; transition: border-color 0.2s, box-shadow 0.2s; width: 100%; box-sizing: border-box; }
.drawer-textarea:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--accent-tint); }
.custom-input { border: 1px solid var(--border-color); border-radius: 8px; padding: 0 12px; font-size: 12px; height: 34px; outline: none; background: #FFF; transition: border-color 0.2s, box-shadow 0.2s; width: 100%; box-sizing: border-box; }
.custom-input:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--accent-tint); }

.history-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.history-item { background: #FFF; border: 1px solid var(--border-color); border-radius: 8px; padding: 12px; cursor: pointer; transition: all 0.2s; display: flex; flex-direction: column; gap: 6px; width: 100%; box-sizing: border-box; }
.history-item:hover { border-color: var(--accent-color); box-shadow: 0 2px 10px var(--accent-tint); transform: translate3d(0, -1px, 0); }
.hist-top { display: flex; justify-content: space-between; align-items: center; }
.hist-method { font-size: 11px; font-weight: 700; color: var(--accent-color); padding: 2px 6px; background: var(--accent-tint); border-radius: 4px; }
.hist-time { font-size: 10px; color: var(--text-muted); }
.hist-url { font-size: 12px; color: var(--text-primary); word-break: break-all; font-family: ui-monospace, monospace; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.toast-pill {
    position: fixed; top: 24px; left: 50%; transform: translate3d(-50%, -20px, 0);
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(15,23,42,0.06); border-radius: 40px;
    color: var(--text-primary); font-size: 13px; font-weight: 600;
    padding: 8px 20px 8px 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    display: flex; align-items: center; gap: 10px; z-index: 9999;
    opacity: 0; pointer-events: none; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    will-change: transform, opacity;
    max-width: 85vw; white-space: normal; word-break: break-all; line-height: 1.4;
}
.toast-pill.show { transform: translate3d(-50%, 0, 0); opacity: 1; }
.toast-icon { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: #FFF; box-shadow: 0 2px 6px rgba(0,0,0,0.1); flex-shrink: 0; }
.toast-icon.success { background: linear-gradient(135deg, #34D399, #059669); }
.toast-icon.error { background: linear-gradient(135deg, #F87171, #DC2626); }
.toast-icon.info { background: linear-gradient(135deg, #60A5FA, #2563EB); }
.toast-msg { letter-spacing: 0.2px; }

.loading-pulse { animation: pulse 1.4s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

/* 💡 移动端重排：严防纵向压缩，增加控件高度与内边距 */
@media (max-width: 850px) {
    body { padding: 8px; height: auto; overflow-y: auto; overflow-x: hidden; }
    input, textarea, select { font-size: 16px !important; }
    
    .workspace-layout { flex-direction: column; }
    .layout-column { width: 100%; }
    
    .url-bar-container { flex-direction: column; height: auto; gap: 12px; align-items: stretch; padding: 14px; border-radius: 12px; }
    .url-input-group { width: 100%; flex-direction: column; border: none; height: auto; box-shadow: 0 2px 8px rgba(15,23,42,0.04); border-radius: 10px; overflow: hidden; background: transparent; }
    
    /* 强行剥夺 flex:1 的弹性缩放权利，给予固定的高度和安全的盒子模型 */
    .method-select { width: 100%; border: 1px solid var(--border-color); border-bottom: none; border-radius: 10px 10px 0 0; height: 44px !important; background-color: #F1F5F9; padding-right: 36px !important; background-position: right 14px center; font-size: 15px !important; box-sizing: border-box; flex: none; }
    .method-divider { display: none; }
    .url-input { width: 100%; border: 1px solid var(--border-color); border-radius: 0 0 10px 10px; height: 48px !important; min-height: 48px !important; padding: 0 16px; background-color: #FFF; font-size: 15px !important; box-sizing: border-box; flex: none; }
    
    .btn-generate-action, .code-btn-action { width: 100%; height: 44px !important; font-size: 14px !important; }
    
    .pane { min-height: 280px; }
    .pane-toolbar { flex-direction: column; align-items: flex-start; gap: 10px; height: auto; padding: 12px; }
    .toolbar-actions { width: 100%; flex-wrap: wrap; justify-content: flex-start; }
    .toolbar-actions .action-btn, .toolbar-actions .mini-select, .toolbar-actions .mini-input { flex: 1; min-width: calc(33.33% - 6px); height: 36px; font-size: 12px; }
    .arrow-select { padding-right: 28px !important; background-position: right 10px center; }

    .side-drawer { width: 100%; max-width: 100%; }
}