/* ===== 设计 token（参照 stock-ios 品牌色） ===== */
:root {
    --brand-red: #E23C2E;
    --brand-red-soft: rgba(226, 60, 46, 0.08);
    --bg-page: #f3f5f8;          /* PC 浏览器外背景 */
    --bg-phone: #ffffff;         /* 手机屏幕内 */
    --bg-tab-bar: #f7f7fa;
    --bg-section: #f5f6f8;
    --ink: #1c1c1e;
    --ink-2: #3a3a3c;
    --muted: #8e8e93;
    --line: rgba(0, 0, 0, 0.08);
    --shadow-phone: 0 20px 60px rgba(0, 0, 0, 0.18);
    --r-md: 10px;
    --r-lg: 16px;
    --r-xl: 22px;
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: var(--bg-page);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button, input, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { outline: none; border: none; background: none; color: inherit; }

/* ===== 手机外壳（PC 上居中浮起、移动端全屏） ===== */
.phone-wrap {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.phone {
    width: 100%;
    max-width: 420px;
    height: 100%;
    max-height: 900px;
    background: var(--bg-phone);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-phone);
    border-radius: 0;
}

@media (min-width: 480px) {
    .phone-wrap { padding: 20px; }
    .phone {
        border-radius: 40px;
        border: 10px solid #1c1c1e;
        max-height: 880px;
    }
    /* 假状态栏 */
    .phone::before {
        content: "9:41   π   100%";
        position: absolute;
        top: 0; left: 0; right: 0;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--ink);
        letter-spacing: 0.15em;
        background: transparent;
        z-index: 200;
        pointer-events: none;
    }
    /* 假底部 home indicator */
    .phone::after {
        content: "";
        position: absolute;
        bottom: 6px; left: 50%;
        width: 134px; height: 5px;
        border-radius: 3px;
        background: rgba(0, 0, 0, 0.25);
        transform: translateX(-50%);
        z-index: 200;
        pointer-events: none;
    }
}

@media (min-width: 480px) {
    .phone .nav-bar { padding-top: calc(env(safe-area-inset-top, 0px) + 36px); }
    .phone .tab-bar { padding-bottom: 24px; }
}

/* ===== 登录页 ===== */
.login {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem 4rem;
}

.login .pi {
    font-size: 5rem;
    font-weight: 300;
    color: var(--brand-red);
    line-height: 1;
    margin-bottom: 0.6rem;
    font-family: 'Times New Roman', serif;
}

.login .sub {
    color: var(--muted);
    letter-spacing: 0.3em;
    font-size: 0.85rem;
    margin-bottom: 3rem;
}

.login .step { width: 100%; max-width: 280px; }

.login label {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.2em;
    margin-bottom: 0.6rem;
}

.login input {
    width: 100%;
    padding: 0.95rem 1rem;
    background: var(--bg-section);
    border-radius: var(--r-md);
    font-size: 1rem;
    margin-bottom: 0.7rem;
    transition: background 0.2s;
}

.login input:focus { background: #ececf0; }

.login .btn-primary {
    width: 100%;
    padding: 0.9rem 1rem;
    background: var(--brand-red);
    color: white;
    border-radius: var(--r-md);
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.15em;
    margin-top: 0.5rem;
    transition: filter 0.2s, transform 0.15s var(--ease);
}

.login .btn-primary:hover { filter: brightness(1.06); }
.login .btn-primary:active { transform: scale(0.985); }

.login .err {
    color: #d32f2f;
    font-size: 0.85rem;
    min-height: 1.4em;
    margin-top: 0.4rem;
    letter-spacing: 0.02em;
}

.login .tip {
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 2.5rem;
    letter-spacing: 0.05em;
    text-align: center;
}

/* ===== 主 App ===== */
.app {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 顶部 NavBar */
.nav-bar {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--line);
    background: var(--bg-phone);
    flex-shrink: 0;
    position: relative;
    font-weight: 600;
    font-size: 1.02rem;
    z-index: 50;
}

.nav-bar .nav-right {
    position: absolute;
    right: 1rem;
    font-size: 0.85rem;
    color: var(--brand-red);
    font-weight: 400;
}

/* 每个 tab —— 只有 .active 才显示、撑满可用空间 */
.tab-pane {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-phone);
}

.tab-pane.active { display: flex; }

/* 每个 tab 内部的滚动内容区（nav-bar 之下） */
.tab-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-phone);
}

/* 分析 tab 的容器也要撑满 tab-pane */
.analysis {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* 占位 tab：未完工提示 */
.placeholder-pane {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--muted);
    height: 100%;
}

.placeholder-pane h2 {
    font-size: 1.1rem;
    color: var(--ink);
    margin-bottom: 0.6rem;
    letter-spacing: 0.1em;
    font-weight: 500;
}

.placeholder-pane p {
    font-size: 0.88rem;
    line-height: 1.7;
    letter-spacing: 0.05em;
    max-width: 260px;
}

.placeholder-pane .badge {
    margin-top: 1.5rem;
    padding: 0.3rem 0.8rem;
    background: var(--brand-red-soft);
    color: var(--brand-red);
    border-radius: 999px;
    font-size: 0.72rem;
    letter-spacing: 0.1em;
}

/* ===== Tab Bar（底部 5 个 tab，照搬 stock-ios） ===== */
.tab-bar {
    display: flex;
    background: var(--bg-tab-bar);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.tab-bar button {
    flex: 1;
    padding: 0.55rem 0.4rem 0.65rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.18rem;
    color: var(--muted);
    transition: color 0.15s;
}

.tab-bar button.active { color: var(--brand-red); }
.tab-bar button:hover { color: var(--ink); }
.tab-bar button.active:hover { color: var(--brand-red); }

.tab-bar .tab-icon {
    font-size: 1.32rem;
    line-height: 1;
}

.tab-bar .tab-label {
    font-size: 0.66rem;
    letter-spacing: 0.04em;
}

/* ===== 分析 tab：3-段切换 + 对话 ===== */
.seg-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* 每个 segment pane 也要撑满并允许内部滚动 */
[data-seg-pane] {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.segment {
    display: flex;
    background: var(--bg-section);
    margin: 0.5rem 1rem;
    border-radius: 9px;
    padding: 2px;
    flex-shrink: 0;
}

.segment button {
    flex: 1;
    padding: 0.45rem 0.4rem;
    font-size: 0.84rem;
    color: var(--ink-2);
    border-radius: 7px;
    font-weight: 400;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.segment button.active {
    background: white;
    color: var(--brand-red);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    font-weight: 500;
}

/* ===== AI 对话 ===== */
.chat {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-context {
    padding: 0.6rem 1rem;
    background: var(--bg-section);
    margin: 0.5rem 1rem 0;
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.chat-context label {
    color: var(--muted);
    letter-spacing: 0.05em;
}

.chat-context input {
    flex: 1;
    padding: 0.3rem 0;
    color: var(--ink);
    font-size: 0.92rem;
}

.chat-context input::placeholder { color: #c0c0c5; }

.chat-context .ctx-clear {
    color: var(--muted);
    font-size: 0.85rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.msg {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    animation: msgIn 0.25s var(--ease);
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg-bot { align-items: flex-start; }
.msg-user { align-items: flex-end; }

.msg .bubble {
    max-width: 85%;
    padding: 0.7rem 0.95rem;
    border-radius: 14px;
    font-size: 0.94rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-bot .bubble {
    background: var(--bg-section);
    color: var(--ink);
    border-bottom-left-radius: 4px;
}

.msg-user .bubble {
    background: var(--brand-red);
    color: white;
    border-bottom-right-radius: 4px;
}

.msg .who {
    font-size: 0.68rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
}

.msg-bot .bubble.streaming::after {
    content: "▋";
    color: var(--brand-red);
    animation: blink 1s steps(1) infinite;
    margin-left: 1px;
    display: inline-block;
}

@keyframes blink { 50% { opacity: 0; } }

.chat-empty {
    text-align: center;
    padding: 3rem 2rem 1rem;
    color: var(--muted);
}

.chat-empty .greet {
    color: var(--ink);
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
}

.chat-empty .tagline {
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    margin-bottom: 1.5rem;
}

.chat-empty .suggestions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 280px;
    margin: 0 auto;
}

.chat-empty .suggestions button {
    padding: 0.6rem 0.9rem;
    background: var(--bg-section);
    border-radius: var(--r-md);
    font-size: 0.85rem;
    color: var(--ink);
    text-align: left;
    transition: background 0.15s;
}

.chat-empty .suggestions button:hover { background: #eceef2; }

/* 底部输入栏 */
.chat-input {
    padding: 0.6rem 0.8rem 0.8rem;
    border-top: 1px solid var(--line);
    background: var(--bg-phone);
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-input textarea {
    flex: 1;
    min-height: 38px;
    max-height: 120px;
    padding: 0.55rem 0.8rem;
    background: var(--bg-section);
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    color: var(--ink);
}

.chat-input textarea::placeholder { color: var(--muted); }

.chat-input .send-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--brand-red);
    color: white;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: filter 0.15s, transform 0.15s var(--ease);
}

.chat-input .send-btn:disabled {
    background: #c0c0c5;
    cursor: not-allowed;
}

.chat-input .send-btn:not(:disabled):hover { filter: brightness(1.06); }
.chat-input .send-btn:not(:disabled):active { transform: scale(0.92); }

/* ===== 我的 tab ===== */
.me-pane {
    padding: 1rem;
}

.me-card {
    background: var(--bg-section);
    border-radius: var(--r-lg);
    padding: 1.2rem 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.me-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: var(--brand-red);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 500;
    flex-shrink: 0;
}

.me-name {
    font-size: 1.05rem;
    font-weight: 500;
    margin-bottom: 0.15rem;
}

.me-sub {
    font-size: 0.78rem;
    color: var(--muted);
    letter-spacing: 0.05em;
}

.me-list {
    background: var(--bg-section);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.me-list .row {
    padding: 0.9rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    font-size: 0.92rem;
}

.me-list .row:last-child { border-bottom: none; }
.me-list .row .right { color: var(--muted); font-size: 0.85rem; }
.me-list .row.danger { color: #d32f2f; }
