/*
 * AI文案智能体 - 前端样式
 * Design System: Ollama-inspired minimal
 *
 * Palette:
 *   ink:        #000   all headlines, primary CTA, active text
 *   charcoal:   #525   list text, disabled-state copy
 *   body:       #737   default body, secondary text
 *   mute:       #a3a   captions, lowest emphasis
 *   canvas:     #fff   page background
 *   surface:    #fafa  soft pill backgrounds
 *   hairline:   #e5e5  1px card borders, dividers
 *   dark:       #1717  inverted surface (featured card)
 *
 * Shapes: pills (9999px) for everything interactive, 12px for cards
 * Typography: system-ui sans for body, rounded headings fallback to system-ui
 */

/* ========== RESET & BASE ========== */

.ai-app {
    width: 100%;
    min-height: 100vh;
    padding: 88px 5vw 88px;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #000;
    background: #fff;
    -webkit-font-smoothing: antialiased;
    box-sizing: border-box;
}

/* ========== HERO ========== */

.ai-hero {
    text-align: center;
    width: 100%;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 88px;
}

.ai-hero-title {
    font-family: "SF Pro Rounded", ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-size: clamp(28px, 4vw, 48px);
    font-weight: 500;
    line-height: 1.11;
    letter-spacing: -0.02em;
    color: #000;
    margin: 0 0 16px;
}

.ai-hero-desc {
    font-size: clamp(15px, 1.4vw, 18px);
    line-height: 1.5;
    color: #737373;
    margin: 0 0 20px;
}

.ai-balance-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-radius: 9999px;
    background: #fafafa;
    font-size: 14px;
}

.ai-balance-label {
    color: #737373;
}

.ai-balance-value {
    font-weight: 600;
    color: #000;
}

.ai-no-room-warn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 40px 24px;
    margin-top: 20px;
    border-radius: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
}

.ai-no-room-img {
    width: 100%;
    max-width: 480px;
    border-radius: 8px;
    border: 1px solid #e5e5e5;
}

.ai-no-room-text {
    color: #dc2626;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

/* ===== 生成历史 ===== */

.ai-history {
    margin: 0 auto clamp(24px, 3vw, 40px);
    max-width: 1400px;
    padding: 0 5vw;
}

.ai-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: #fafafa;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    cursor: pointer;
    user-select: none;
}

.ai-history-head:hover {
    background: #f5f5f5;
}

.ai-history-title {
    font-size: 16px;
    font-weight: 600;
    color: #000;
    margin: 0;
}

.ai-history-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: 1px solid #d4d4d4;
    border-radius: 9999px;
    background: #fff;
    font-size: 13px;
    color: #525252;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-history-toggle:hover {
    background: #f5f5f5;
}

.ai-history-list {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 420px;
    overflow-y: auto;
}

.ai-history-item {
    padding: 14px 18px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-history-item:hover {
    background: #fafafa;
}

.ai-history-item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.ai-history-method {
    font-size: 14px;
    font-weight: 600;
    color: #000;
}

.ai-history-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-history-tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 500;
    background: #f5f5f5;
    color: #737373;
    border: 1px solid #e5e5e5;
}

.ai-history-tag.ai-tag-enhanced {
    background: #171717;
    color: #fff;
    border-color: #171717;
}

.ai-history-preview {
    font-size: 13px;
    color: #737373;
    line-height: 1.5;
    margin: 0;
}

.ai-history-time {
    font-size: 11px;
    color: #a3a3a3;
    margin-top: 6px;
}

.ai-history-empty {
    text-align: center;
    padding: 32px 16px;
    color: #a3a3a3;
    font-size: 14px;
}

.ai-history-loading {
    text-align: center;
    padding: 24px;
    color: #a3a3a3;
    font-size: 14px;
}

/* 历史详情弹窗 */
.ai-history-detail {
    max-height: 50vh;
    overflow-y: auto;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.7;
    color: #262626;
    padding: 16px 0;
}

/* ========== METHODS GRID ========== */

.ai-methods {
    margin-bottom: 88px;
}

.ai-empty {
    text-align: center;
    padding: 64px 0;
    color: #a3a3a3;
    font-size: clamp(14px, 1.2vw, 16px);
}

.ai-methods-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
}

/* ========== CARD ========== */

.ai-card {
    position: relative;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    padding: clamp(20px, 2.5vw, 32px);
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s;
    min-height: 280px;
}

.ai-card:hover {
    border-color: #d4d4d4;
}

/* Featured card: dark inverted surface */
.ai-card-featured {
    background: #171717;
    border-color: #171717;
    color: #fff;
}

.ai-card-featured:hover {
    border-color: #333;
}

.ai-card-badge {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #a3a3a3;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.ai-card-featured .ai-card-badge {
    color: rgba(255,255,255,0.5);
}

.ai-card-title {
    font-family: "SF Pro Rounded", ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.33;
    color: #000;
    margin: 0 0 8px;
}

.ai-card-featured .ai-card-title {
    color: #fff;
}

.ai-card-structure {
    font-size: 13px;
    font-weight: 500;
    color: #525252;
    margin: 0 0 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    word-break: break-all;
}

.ai-card-featured .ai-card-structure {
    color: rgba(255,255,255,0.6);
}

.ai-card-case {
    font-size: 14px;
    line-height: 1.5;
    color: #737373;
    margin: 0 0 20px;
    flex: 1;
}

.ai-card-featured .ai-card-case {
    color: rgba(255,255,255,0.6);
}

/* Card CTA pill */
.ai-card .ai-pill {
    align-self: flex-start;
}

.ai-card-featured .ai-pill {
    background: #fff;
    color: #000;
}

.ai-card-featured .ai-pill:hover {
    background: #e5e5e5;
}

/* ========== PILL BUTTONS ========== */

.ai-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    border-radius: 9999px;
    border: none;
    padding: 8px 20px;
    height: 36px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, opacity 0.15s;
    text-decoration: none;
}

.ai-pill-primary {
    background: #000;
    color: #fff;
}

.ai-pill-primary:hover {
    background: #1a1a1a;
}

.ai-pill-primary:active {
    background: #090909;
}

.ai-pill-primary:disabled {
    background: #fafafa;
    color: #a3a3a3;
    cursor: not-allowed;
}

.ai-pill-primary.ai-pill-danger {
    background: #dc2626;
}

.ai-pill-lg {
    padding: 12px 28px;
    height: 44px;
    font-size: 15px;
    width: 100%;
}

.ai-pill-secondary {
    background: #fff;
    color: #000;
    border: 1px solid #d4d4d4;
}

.ai-pill-secondary:hover {
    background: #fafafa;
}

/* ========== OVERLAY & MODAL ========== */

.ai-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-overlay-bg {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 0;
}

.ai-modal {
    position: relative;
    background: #fff;
    border-radius: 12px;
    width: 480px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    z-index: 1;
    border: 1px solid #e5e5e5;
}

.ai-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e5e5;
}

.ai-modal-head h2 {
    margin: 0;
    font-family: "SF Pro Rounded", ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-size: 20px;
    font-weight: 600;
    color: #000;
}

.ai-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    border: none;
    background: transparent;
    color: #a3a3a3;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}

.ai-modal-close:hover {
    background: #fafafa;
    color: #000;
}

.ai-modal-body {
    padding: 24px;
}

/* ========== FORM FIELDS ========== */

.ai-field {
    margin-bottom: 20px;
}

.ai-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #525252;
    margin-bottom: 8px;
}

/* Select pill */
.ai-select-wrap {
    position: relative;
}

.ai-select {
    appearance: none;
    width: 100%;
    padding: 10px 36px 10px 16px;
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-size: 15px;
    color: #000;
    background: #fafafa;
    border: 1px solid #e5e5e5;
    border-radius: 9999px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.ai-select:hover {
    border-color: #d4d4d4;
}

.ai-select:focus {
    outline: none;
    border-color: #000;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

.ai-select-wrap::after {
    content: "";
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 6px;
    background: currentColor;
    pointer-events: none;
    clip-path: polygon(0 0, 50% 100%, 100% 0);
    color: #a3a3a3;
}

/* Segmented control */
.ai-segmented {
    display: inline-flex;
    background: #fafafa;
    border-radius: 9999px;
    padding: 3px;
    border: 1px solid #e5e5e5;
}

.ai-seg {
    position: relative;
    font-size: 14px;
    font-weight: 500;
    color: #737373;
    cursor: pointer;
    border-radius: 9999px;
    transition: color 0.15s, background 0.15s;
}

.ai-seg input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ai-seg span {
    display: block;
    padding: 6px 20px;
    min-width: 44px;
    text-align: center;
}

.ai-seg:has(input:checked) {
    background: #fff;
    color: #000;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.ai-seg:hover:not(:has(input:checked)) {
    color: #525252;
}

/* ========== TOGGLE SWITCH ========== */

.ai-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.ai-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ai-toggle-track {
    position: relative;
    width: 40px;
    height: 24px;
    border-radius: 9999px;
    background: #d4d4d4;
    transition: background 0.15s;
    flex-shrink: 0;
}

.ai-toggle input:checked + .ai-toggle-track {
    background: #000;
}

.ai-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: #fff;
    transition: transform 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.ai-toggle input:checked + .ai-toggle-track .ai-toggle-knob {
    transform: translateX(16px);
}

.ai-toggle-label {
    font-size: 14px;
    font-weight: 500;
    color: #525252;
}

/* ========== COST CARD ========== */

.ai-cost-card {
    background: #fafafa;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 20px;
}

.ai-cost-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.ai-cost-row-sub {
    border-top: 1px solid #e5e5e5;
    padding-top: 10px;
    margin-top: 8px;
}

.ai-cost-meta {
    font-size: 14px;
    color: #737373;
}

.ai-cost-num {
    font-size: 20px;
    font-weight: 600;
    color: #000;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.ai-cost-bal {
    font-size: 16px;
    font-weight: 600;
    color: #000;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* ========== MODAL ACTIONS ========== */

.ai-modal-actions {
    margin-bottom: 20px;
}

/* ========== GENERATING HINT ========== */

.ai-generating {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    margin-bottom: 20px;
    background: #fafafa;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    gap: 16px;
}

.ai-generating-icon {
    color: #737373;
    animation: spin 2s linear infinite;
}

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

.ai-generating-text {
    font-size: 15px;
    font-weight: 500;
    color: #262626;
    margin: 0;
    text-align: center;
}

/* ========== RESULT ========== */

.ai-result {
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 24px;
}

.ai-result-head {
    padding: 14px 20px;
    background: #fafafa;
    border-bottom: 1px solid #e5e5e5;
}

.ai-result-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #000;
}

.ai-result-body {
    padding: 20px;
    font-size: 15px;
    line-height: 1.7;
    color: #000;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 360px;
    overflow-y: auto;
}

/* ========== RESPONSIVE ========== */

@media (max-width: 768px) {
    .ai-app {
        padding: 48px 16px 48px;
    }

    .ai-hero {
        margin-bottom: 48px;
    }

    .ai-methods {
        margin-bottom: 48px;
    }

    .ai-methods-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .ai-card {
        padding: 20px;
        min-height: auto;
    }

    .ai-modal {
        width: calc(100vw - 32px);
        max-width: none;
        margin: 16px;
        max-height: 90vh;
    }

    .ai-modal-body {
        padding: 16px;
    }
}

@media (min-width: 1400px) {
    .ai-methods-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
