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

:root {
    --yl-primary: #1e3a8a;
    --yl-primary-light: #2563eb;
    --yl-primary-bg: #eff6ff;
    --yl-bg: #eef2f7;
    --yl-surface: #ffffff;
    --yl-text: #1e293b;
    --yl-text-muted: #64748b;
    --yl-border: #e2e8f0;
    --yl-radius: 14px;
    --yl-radius-lg: 18px;
    --yl-header-h: 56px;
    --yl-avatar: 38px;
    --yl-content-max: 720px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 15px;
    color: var(--yl-text);
    background: var(--yl-bg);
    -webkit-font-smoothing: antialiased;
}

/* ===== 整体布局 ===== */
.yl-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 960px;
    margin: 0 auto;
    background: var(--yl-surface);
    box-shadow: 0 0 40px rgba(30, 58, 138, 0.06);
}

/* ===== 顶栏 ===== */
.yl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--yl-header-h);
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
    flex-shrink: 0;
}

.yl-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.yl-logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    object-fit: cover;
    flex-shrink: 0;
}

.yl-brand-text {
    min-width: 0;
}

.yl-brand-text h1 {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.yl-brand-text p {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.72);
    margin-top: 1px;
}

.yl-btn-outline {
    padding: 6px 14px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.yl-btn-outline:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* ===== 对话区 ===== */
.yl-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    scroll-behavior: smooth;
    background: linear-gradient(180deg, #f8fafc 0%, #fff 120px);
}

.yl-main::-webkit-scrollbar { width: 5px; }
.yl-main::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* 欢迎页 */
.yl-welcome {
    display: flex;
    justify-content: center;
    padding: 24px 0 16px;
}

.yl-welcome.hidden { display: none; }

.yl-welcome-card {
    width: 100%;
    max-width: var(--yl-content-max);
    text-align: center;
    padding: 28px 20px;
    background: #fff;
    border: 1px solid var(--yl-border);
    border-radius: var(--yl-radius-lg);
    box-shadow: 0 2px 12px rgba(30, 58, 138, 0.04);
}

.yl-welcome-icon {
    font-size: 42px;
    line-height: 1;
    margin-bottom: 12px;
}

.yl-welcome-card h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--yl-primary);
    margin-bottom: 8px;
}

.yl-welcome-card p {
    font-size: 14px;
    color: var(--yl-text-muted);
    line-height: 1.6;
    margin-bottom: 20px;
}

.yl-chips {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    text-align: left;
}

.yl-chip {
    padding: 10px 12px;
    border: 1px solid var(--yl-border);
    border-radius: 10px;
    background: var(--yl-primary-bg);
    color: var(--yl-primary);
    font-size: 13px;
    line-height: 1.45;
    cursor: pointer;
    transition: all 0.2s;
}

.yl-chip:hover {
    border-color: #93c5fd;
    background: #dbeafe;
    transform: translateY(-1px);
}

/* 消息列表 */
.yl-chat-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: var(--yl-content-max);
    margin: 0 auto;
    width: 100%;
}

.yl-msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.yl-msg-user {
    flex-direction: row-reverse;
}

.yl-avatar {
    width: var(--yl-avatar);
    height: var(--yl-avatar);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    overflow: hidden;
}

.yl-avatar-ai {
    background: var(--yl-primary-bg);
    border: 1px solid #bfdbfe;
}

.yl-avatar-user {
    background: #f1f5f9;
    border: 1px solid var(--yl-border);
}

.yl-msg-content {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - var(--yl-avatar) - 10px);
}

.yl-msg-user .yl-msg-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.yl-bubble {
    padding: 12px 16px;
    border-radius: var(--yl-radius);
    line-height: 1.75;
    font-size: 14px;
    word-break: break-word;
    max-width: 100%;
}

.yl-msg-user .yl-bubble {
    max-width: 88%;
}

.yl-bubble-user {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.yl-bubble-ai {
    background: #fff;
    border: 1px solid var(--yl-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
}

/* AI 回答内容排版 */
.yl-bubble-ai p { margin: 0.55em 0; }
.yl-bubble-ai p:first-child { margin-top: 0; }
.yl-bubble-ai p:last-child { margin-bottom: 0; }
.yl-bubble-ai ul, .yl-bubble-ai ol { padding-left: 1.4em; margin: 0.5em 0; }
.yl-bubble-ai li { margin: 0.25em 0; }
.yl-bubble-ai h1, .yl-bubble-ai h2, .yl-bubble-ai h3 {
    margin: 1em 0 0.45em;
    font-size: 1.05em;
    font-weight: 600;
    color: var(--yl-primary);
}
.yl-bubble-ai h1:first-child, .yl-bubble-ai h2:first-child, .yl-bubble-ai h3:first-child { margin-top: 0; }
.yl-bubble-ai blockquote {
    margin: 0.6em 0;
    padding: 8px 12px;
    border-left: 3px solid #93c5fd;
    background: #f8fafc;
    color: var(--yl-text-muted);
}
.yl-bubble-ai pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.65em 0;
    font-size: 13px;
    line-height: 1.5;
}
.yl-bubble-ai code { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.yl-bubble-ai :not(pre) > code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    color: #334155;
}
.yl-bubble-ai table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.65em 0;
    font-size: 13px;
    display: block;
    overflow-x: auto;
}
.yl-bubble-ai th, .yl-bubble-ai td {
    border: 1px solid var(--yl-border);
    padding: 8px 10px;
    text-align: left;
}
.yl-bubble-ai th { background: var(--yl-primary-bg); font-weight: 600; }

.yl-bubble-ai .lineS { opacity: 0.6; font-size: 13px; }
.yl-bubble-ai .lineA {
    font-weight: 600;
    color: var(--yl-primary);
    margin-top: 14px !important;
    padding-top: 10px;
    border-top: 1px dashed #cbd5e1;
}

.yl-aborted {
    color: #94a3b8;
    font-size: 12px;
    font-style: italic;
    margin-top: 8px !important;
}

.yl-msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.yl-action-btn {
    padding: 5px 12px;
    border: 1px solid var(--yl-border);
    border-radius: 8px;
    background: #fff;
    color: var(--yl-text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.yl-action-btn:hover {
    border-color: var(--yl-primary-light);
    color: var(--yl-primary);
    background: var(--yl-primary-bg);
}

.codebutton {
    float: right;
    padding: 3px 8px;
    border: none;
    border-radius: 4px;
    background: #475569;
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    margin-bottom: 4px;
}

/* ===== 底部输入区 ===== */
.yl-composer {
    flex-shrink: 0;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--yl-border);
    background: #fff;
}

.yl-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}

.yl-toolbar-subject {
    display: flex;
    align-items: center;
    gap: 8px;
}

.yl-toolbar-label {
    font-size: 12px;
    color: var(--yl-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.yl-select {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--yl-border);
    border-radius: 10px;
    font-size: 13px;
    background: #f8fafc;
    color: var(--yl-text);
    outline: none;
    cursor: pointer;
}

.yl-select:focus {
    border-color: var(--yl-primary-light);
    background: #fff;
}

.yl-toolbar-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.yl-pill {
    position: relative;
    cursor: pointer;
    user-select: none;
}

.yl-pill input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.yl-pill span {
    display: inline-block;
    padding: 6px 12px;
    border: 1px solid var(--yl-border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--yl-text-muted);
    background: #f8fafc;
    transition: all 0.15s;
}

.yl-pill input:checked + span {
    background: var(--yl-primary-bg);
    border-color: #93c5fd;
    color: var(--yl-primary);
    font-weight: 500;
}

.yl-pill:hover span {
    border-color: #cbd5e1;
}

.yl-input-box {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding: 4px;
    background: #f8fafc;
    border: 1px solid var(--yl-border);
    border-radius: var(--yl-radius-lg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.yl-input-box:focus-within {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background: #fff;
}

#kw-target {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: none;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 120px;
}

#kw-target:disabled {
    color: var(--yl-text-muted);
}

.yl-btn-send {
    margin: 4px;
    padding: 10px 18px;
    border: none;
    border-radius: 12px;
    background: var(--yl-primary-light);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.yl-btn-send:hover { background: var(--yl-primary); }
.yl-btn-send.stop { background: #ef4444; }
.yl-btn-send.stop:hover { background: #dc2626; }

.yl-disclaimer {
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 10px;
    line-height: 1.5;
}

/* ===== 平板 / 桌面 ===== */
@media (min-width: 640px) {
    .yl-header { padding: 0 24px; }
    .yl-main { padding: 20px 24px; }
    .yl-composer { padding: 14px 24px 18px; }
    .yl-brand-text h1 { font-size: 16px; }
    .yl-chips { grid-template-columns: repeat(3, 1fr); }
    .yl-toolbar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .yl-toolbar-subject { flex: 1; max-width: 280px; }
    .yl-toolbar-options { flex-shrink: 0; }
}

/* ===== 手机 ===== */
@media (max-width: 480px) {
    .yl-brand-text p { display: none; }
    .yl-brand-text h1 { font-size: 14px; }
    .yl-welcome-card { padding: 22px 14px; }
    .yl-chips { grid-template-columns: 1fr; }
    .yl-btn-send { padding: 10px 14px; }
    .yl-msg-user .yl-bubble { max-width: 92%; }
}
