:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #e4e4e4;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --node-gray: #666;
    --node-green: #4caf50;
    --node-yellow: #ffc107;
    --border: #2a2a4a;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.hidden { display: none !important; }

/* 登录页 */
.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, var(--bg-primary), var(--bg-tertiary));
}

.auth-card {
    background: var(--bg-secondary);
    padding: 40px;
    border-radius: 16px;
    width: 360px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.auth-card h1 {
    font-size: 32px;
    color: var(--accent);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}

.tab-btn.active {
    background: var(--accent);
    color: white;
}

.auth-form input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

.auth-form button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: 0.2s;
}

.auth-form button:hover {
    opacity: 0.9;
}

/* 主应用 */
.main-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: 48px;
    flex-shrink: 0;
}

.direction-name {
    font-size: 18px;
    font-weight: bold;
    color: var(--accent);
}

.top-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: 0.2s;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
}

.three-column {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* AI面板 */
.ai-panel {
    width: 25%;
    min-width: 200px;
    max-width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s;
}

.ai-panel.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.collapse-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.ai-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.ai-message {
    margin-bottom: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
}

.ai-message.system {
    background: var(--bg-tertiary);
}

.ai-message.user {
    background: var(--accent);
    margin-left: 20%;
}

.ai-input-area {
    display: flex;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.ai-input {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.ai-input:focus {
    border-color: var(--accent);
}

.ai-send-btn {
    padding: 8px 14px;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: 0.2s;
}

.ai-send-btn:hover {
    opacity: 0.9;
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 拆解结果卡片 */
.parse-result {
    padding: 12px !important;
}
.parse-direction { font-size: 14px; margin-bottom: 6px; }
.parse-count { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.parse-warning {
    background: rgba(255, 193, 7, 0.15);
    color: var(--node-yellow);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    margin-bottom: 10px;
}
.parse-nodes {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
    max-height: 240px;
    overflow-y: auto;
}
.parse-node {
    background: var(--bg-primary);
    padding: 8px 10px;
    border-radius: 6px;
}
.parse-node-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.parse-level {
    font-size: 10px;
    background: var(--accent);
    color: white;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}
.parse-title { font-size: 13px; font-weight: bold; }
.parse-summary {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.parse-actions { display: flex; gap: 8px; }
.parse-import-btn {
    flex: 1;
    padding: 8px;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: 0.2s;
}
.parse-import-btn:hover { opacity: 0.9; }
.parse-import-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.parse-cancel-btn {
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: 0.2s;
}
.parse-cancel-btn:hover { background: var(--bg-tertiary); }

/* 加载闪烁点 */
.loading-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: blink 1.2s infinite;
    margin-right: 4px;
    vertical-align: middle;
}
@keyframes blink {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.ai-float {
    position: fixed;
    left: 16px;
    top: 60px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    font-size: 20px;
    cursor: pointer;
    z-index: 100;
}

/* 树容器 */
.tree-container {
    flex: 1;
    position: relative;
    overflow: auto;
    background: var(--bg-primary);
}

.tree-svg {
    width: 100%;
    height: 100%;
}

.empty-tree {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
}

.empty-tree p:first-child {
    font-size: 48px;
    margin-bottom: 12px;
    animation: treeBounce 2s ease-in-out infinite;
}

.empty-tree .hint {
    font-size: 14px;
    margin-top: 8px;
}

.empty-tree .guide-arrow {
    position: absolute;
    bottom: -80px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 24px;
    animation: arrowBounce 1.5s ease-in-out infinite;
}

@keyframes treeBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes arrowBounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(8px); }
}

/* 详情弹窗 */
.detail-modal-content {
    width: 480px;
    max-width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.detail-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.detail-value {
    font-size: 14px;
    line-height: 1.6;
}

.detail-summary {
    white-space: pre-wrap;
    word-break: break-word;
}

.verified-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.verified-true { background: var(--node-green); color: white; }
.verified-false { background: var(--accent); color: white; }
.verified-uncertain, .verified-unverified { background: var(--node-yellow); color: black; }

.read-timer {
    text-align: center;
    padding: 16px;
    margin: 16px 0;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.timer-display {
    font-size: 32px;
    font-weight: bold;
    color: var(--accent);
}

.master-btn {
    width: 100%;
    padding: 12px;
    background: var(--node-gray);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: 0.2s;
}

.master-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.master-btn.active {
    background: var(--node-green);
}

.master-btn.ready {
    background: var(--accent);
    animation: pulse 1.5s infinite;
}

.master-btn.active:hover {
    opacity: 0.9;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* 底部输入栏 */
.input-bar {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 8px 16px;
    flex-shrink: 0;
}

.input-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.input-tab {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: 0.2s;
}

.input-tab.active {
    background: var(--accent);
    color: white;
}

.input-area {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-field {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    resize: vertical;
    min-height: 40px;
    max-height: 120px;
}

.file-drop {
    flex: 1;
    padding: 16px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    text-align: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: 0.2s;
}

.file-drop:hover, .file-drop.dragover {
    border-color: var(--accent);
    color: var(--accent);
}

.file-link {
    color: var(--accent);
    text-decoration: underline;
}

.submit-btn {
    padding: 10px 20px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: 0.2s;
}

.submit-btn:hover {
    opacity: 0.9;
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 600px;
    max-width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.pit-list {
    padding: 16px;
    overflow-y: auto;
}

.pit-item {
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.pit-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 8px;
}

.pit-item-title {
    font-weight: bold;
    flex: 1;
}

.pit-category {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.pit-cat-hard {
    background: rgba(220, 53, 69, 0.2);
    color: #dc3545;
}

.pit-cat-time {
    background: rgba(255, 193, 7, 0.2);
    color: var(--node-yellow);
}

.pit-item-reason {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.pit-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.pit-source {
    color: var(--accent);
    text-decoration: none;
}

/* D3 树节点样式 */
.node circle {
    stroke-width: 2px;
    cursor: pointer;
    transition: r 0.2s;
}

.node circle.mastered { fill: var(--node-green); stroke: var(--node-green); }
.node circle.unverified { fill: var(--node-yellow); stroke: var(--node-yellow); }
.node circle.pending { fill: var(--node-gray); stroke: var(--node-gray); }
.node circle.false { fill: var(--accent); stroke: var(--accent); }

/* 新节点闪烁 */
.new-node-pulse {
    animation: nodePulse 1.5s ease-out 3;
    transform-origin: center;
}

@keyframes nodePulse {
    0% { r: 8; opacity: 1; }
    100% { r: 20; opacity: 0; }
}

.node text {
    font-size: 12px;
    fill: var(--text-primary);
}

.link {
    fill: none;
    stroke: var(--border);
    stroke-width: 1.5px;
}

/* 响应式 */
@media (max-width: 768px) {
    .ai-panel { display: none; }
    .detail-modal-content { width: 95%; }
}

/* 额度弹窗 */
.usage-modal-content {
    width: 400px;
    max-width: 90%;
}

.usage-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.usage-item-header {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 6px;
}

.usage-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.usage-bar-fill {
    height: 100%;
    transition: width 0.3s;
}

/* 消息红点 */
.msg-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: white;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

.icon-btn {
    position: relative;
}

/* 消息弹窗 */
.message-modal-content {
    width: 420px;
    max-width: 90%;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.message-item {
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}

.message-item.unread {
    border-left: 3px solid var(--accent);
}

.message-item.read {
    opacity: 0.6;
}

.message-title {
    font-weight: bold;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.unread-dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.message-content {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.7;
}

.small-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-right: 8px;
}

.small-btn:hover {
    background: var(--bg-primary);
}
