/* ===== 基础变量 ===== */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-body: #f1f5f9;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f8fafc;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== 布局 ===== */
.app-container {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    overflow: hidden;
}

.sidebar {
    width: 380px;
    min-width: 380px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    height: 100vh;
    overflow-y: auto;
    padding: 24px 24px 0 24px;
    position: sticky;
    top: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.main-content {
    flex: 1;
    padding: 24px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    height: 100%;
}

/* ===== 侧边栏头部 ===== */
.sidebar-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ===== 面板区块 ===== */
.panel-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.panel-section:last-of-type {
    margin-bottom: 8px;
    border-bottom: none;
}

.panel-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== 拖拽上传区 ===== */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 12px;
    background: var(--bg-hover);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone-content {
    pointer-events: none;
}

.drop-icon {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
}

.drop-zone p {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.drop-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== 输入区操作栏 ===== */
.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: var(--transition);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-text:hover {
    background: var(--primary-light);
    color: var(--primary-hover);
}

.shortcut-hint {
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* ===== 输入框 ===== */
textarea,
input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 14px;
    font-size: 14px;
    font-family: inherit;
    background: #f8fafc;
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

textarea:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
    background: #ffffff;
}

input[type="password"] {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* API Key 输入框专属美化 */
#api-key {
    font-size: 14px;
    padding: 10px 14px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid #d1d5db;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    margin-bottom: 10px;
}

#api-key:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
    background: #ffffff;
    outline: none;
}

/* AI 分析区块优化 */
.panel-section:has(#api-key) .control-row {
    gap: 8px;
}

.panel-section:has(#api-key) .btn-primary,
.panel-section:has(#api-key) .btn-secondary {
    padding: 8px 14px;
    font-size: 13px;
    height: 38px;
}

textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

input[type="number"] {
    width: 100%;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ===== 控制行 ===== */
.control-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.control-row:last-child {
    margin-bottom: 0;
}

.input-group {
    flex: 1;
    min-width: 0;
}

.input-group.full {
    flex: 2;
}

.input-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-group .hint {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 11px;
}

/* ===== 滑块 ===== */
input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    margin-top: 8px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow);
}

/* ===== 预设尺寸芯片 ===== */
.preset-sizes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.chip {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== 配色卡片 ===== */
.color-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.color-card {
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.color-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.color-card.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.color-strip {
    height: 24px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.color-card span {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== 背景选项 ===== */
.bg-options {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.analysis-summary {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 10px 12px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 12px;
}

.analysis-item {
    margin-top: 12px;
}

.analysis-item strong {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip-list .chip {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 16px;
    background: var(--bg-hover);
    border-color: var(--border);
    color: var(--text-primary);
}

.analysis-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.bg-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    color: var(--text-secondary);
}

.bg-btn:hover {
    border-color: var(--primary);
}

.bg-btn.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

input[type="color"] {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
    background: var(--bg-card);
}

/* ===== 折叠面板 ===== */
.foldable .foldable-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
}

.foldable .toggle-icon {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.foldable.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.foldable .foldable-content {
    margin-top: 12px;
    animation: fadeIn 0.2s ease;
}

.foldable.collapsed .foldable-content {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== 复选框 ===== */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.checkbox-label input:checked+.checkmark {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox-label input:checked+.checkmark::after {
    content: "✓";
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* ===== 毛玻璃操作栏 ===== */
.action-bar {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    padding: 16px 0;
    position: sticky;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border-top: 1px solid rgba(226, 232, 240, 0.8);
    z-index: 50;
}

/* ===== 按钮样式 ===== */
.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    height: 44px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.39);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px 0 rgba(79, 70, 229, 0.23);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.btn-icon {
    font-size: 16px;
}

/* ===== 主内容区 ===== */
.canvas-area {
    flex: 1;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    position: relative;
    overflow: hidden;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h2 {
    font-size: 20px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
}

.canvas-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    overflow: auto;
    padding: 20px;
}

.canvas-wrapper canvas {
    display: block;
    max-width: 100%;
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
}

.canvas-overlay {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.canvas-wrapper:hover .canvas-overlay {
    opacity: 1;
}

.btn-float {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: var(--transition);
    color: var(--text-secondary);
}

.btn-float:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

/* ===== 加载遮罩 ===== */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 10;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 14px;
}

.loading-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.72);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 20000;
}

.modal-content {
    position: relative;
    z-index: 20001;
}

.modal-content {
    width: min(100%, 760px);
    max-height: 90vh;
    overflow: auto;
    background: var(--bg-card);
    border-radius: 18px;
    box-shadow: 0 32px 80px rgba(15, 23, 42, 0.28);
    padding: 24px;
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.modal-close {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 26px;
    cursor: pointer;
    line-height: 1;
}

.review-section {
    margin-bottom: 20px;
}

.review-section strong {
    display: block;
    margin-bottom: 10px;
    color: var(--text);
}

.checkbox-list {
    display: grid;
    gap: 10px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: var(--bg-surface);
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.checkbox-item input {
    accent-color: var(--primary);
    transform: scale(1.05);
}

.checkbox-item:hover {
    background: rgba(59, 130, 246, 0.08);
}

.empty-tip {
    color: var(--text-muted);
    font-size: 14px;
    padding: 12px 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
}

/* ===== Tooltip ===== */
.wc-tooltip {
    position: fixed;
    background: rgba(15, 23, 42, 0.92);
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    pointer-events: none;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    transform: translateY(4px);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.wc-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ===== 结果面板 ===== */
.results-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
}

.stats-bar {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.word-ranking h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 600;
}

.word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 8px;
}

.word-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    animation: popIn 0.3s ease backwards;
}

.word-tag:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.word-tag .freq {
    font-size: 11px;
    opacity: 0.8;
    background: rgba(0, 0, 0, 0.1);
    padding: 1px 6px;
    border-radius: 10px;
}

.word-tag:hover .freq {
    background: rgba(255, 255, 255, 0.2);
}

.word-tag .rank {
    font-size: 11px;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    margin-right: 2px;
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.results-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-light);
    flex-wrap: wrap;
}

/* ===== 文本统计 ===== */
.text-stats {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: right;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary);
    font-size: 14px;
    color: var(--text-primary);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
    max-width: 320px;
    word-break: break-word;
    display: flex;
    align-items: center;
    gap: 6px;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ===== 页脚 ===== */
.app-footer {
    text-align: center;
    padding: 16px;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-body);
}

/* ===== 响应式 ===== */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: auto;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: none;
        overflow-y: visible;
    }

    .main-content {
        padding: 16px;
        overflow-y: visible;
        height: auto;
    }

    .stats-bar {
        flex-wrap: wrap;
        gap: 16px;
    }

    .action-bar {
        position: relative;
        bottom: auto;
        background: var(--bg-sidebar);
        border-top: 1px solid var(--border);
    }
}

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

    .control-row {
        flex-direction: column;
        gap: 8px;
    }

    .stats-bar {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }

    .shortcut-hint {
        display: none;
    }
}

.word-tag .rank-num {
    font-size: 11px;
    opacity: 0.5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-width: 16px;
    text-align: center;
    display: inline-block;
}