:root {
    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #0f172a;
    --text-subtle: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-press: #1d4ed8;
    --secondary: #0f766e;
    --secondary-press: #115e59;
    --accent: #7c3aed;
    --accent-press: #6d28d9;
    --danger: #dc2626;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.12);
    --btn-primary-shadow: 0 8px 18px rgba(37, 99, 235, 0.24);
    --btn-secondary-shadow: 0 8px 18px rgba(37, 99, 235, 0.2);
    --btn-accent-shadow: 0 8px 18px rgba(37, 99, 235, 0.26);
    --user-bubble-shadow: 0 8px 16px rgba(37, 99, 235, 0.18);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    color: var(--text);
    background: radial-gradient(circle at 0 0, #f8fbff 0%, #eef3f9 46%, #e8eef7 100%);
}
body {
    display: flex;
    flex-direction: column;
    padding: 12px;
}

.app-topbar {
    min-height: 52px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #fdfefe 0%, #f8fbff 100%);
}

.app-topbar-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-topbar-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: #0f172a;
}

.app-topbar-subtitle {
    font-size: 11px;
    color: #64748b;
}

.app-topbar-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    color: #166534;
    font-size: 11px;
    font-weight: 600;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
}

.app-shell {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    height: calc(100vh - 24px);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}
.tab-header {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    min-height: 56px;
    padding: 6px;
    gap: 6px;
}
.tab-item {
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-subtle);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
}

.tab-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-item .bi {
    font-size: 14px;
}

.tab-item:hover {
    color: var(--text);
    background: #ffffff;
    border-color: #dbe4f2;
}

.tab-item:focus-visible,
.btn:focus-visible,
.btn-send:focus-visible,
.form-input:focus-visible,
.form-textarea:focus-visible,
#aiInput:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: 1px;
}
.tab-item.is-active {
    color: var(--primary);
    background: #ffffff;
    border-color: #cfe0ff;
    box-shadow: var(--shadow-sm);
}

.tab-item.is-active::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -7px;
    width: 24px;
    height: 2px;
    border-radius: 99px;
    background: var(--primary);
    transform: translateX(-50%);
}

.tab-content {
    display: none;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    flex-direction: column;
}

.tab-content.is-active {
    display: flex;
}

.scroll-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px;
}
.panel-muted {
    background: var(--surface-muted);
}

.panel-white {
    background: var(--surface);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    padding: 15px;
    margin-bottom: 12px;
}
.live-card {
    border-color: #cfe0ff;
    background: linear-gradient(180deg, #ffffff 0%, #f5f9ff 100%);
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.08);
}

.live-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
}

.live-title {
    font-size: 14px;
    font-weight: 700;
    color: #1d4ed8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.live-time {
    font-size: 12px;
    color: var(--text-subtle);
}

.live-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.stat-box {
    border: 1px solid #dbe5f3;
    border-radius: 12px;
    padding: 10px 6px;
    text-align: center;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.04);
}

.stat-label {
    font-size: 11px;
    color: #64748b;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.stat-value.highlight {
    color: #dc2626;
}

.toolbar {
    margin-bottom: 12px;
}

.toolbar-surface {
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    backdrop-filter: blur(4px);
}
.btn {
    width: 100%;
    min-height: 42px;
    border-radius: 10px;
    border: 0;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s ease, background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    box-shadow: var(--btn-primary-shadow);
}

.btn:hover,
.btn-send:hover {
    transform: translateY(-1px);
}
.btn .bi {
    font-size: 14px;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled,
.btn-send:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    box-shadow: var(--btn-primary-shadow);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}

.btn-secondary {
    background: linear-gradient(135deg, #3f8cff 0%, #2563eb 100%);
    box-shadow: var(--btn-secondary-shadow);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #2f7cf6 0%, #1d4ed8 100%);
}

.btn-accent {
    background: linear-gradient(135deg, #2f7cf6 0%, #1d4ed8 100%);
    box-shadow: var(--btn-accent-shadow);
}

.btn-accent:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}

.report-card {
    border-left: 3px solid var(--primary);
}

.msg-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-bottom: 12px;
}

.msg-row.self {
    flex-direction: row-reverse;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: #e2e8f0;
    color: #475569;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid #d8e1ed;
}

.msg-bubble {
    max-width: 76%;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
}

.msg-row.other .msg-bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.msg-row.self .msg-bubble {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    border-top-right-radius: 4px;
    border: 1px solid #2f64d3;
    box-shadow: var(--user-bubble-shadow);
}

.msg-meta {
    margin-top: 4px;
    color: #94a3b8;
    font-size: 11px;
}

.ai-message,
.user-message {
    max-width: 90%;
    border-radius: 12px;
    padding: 11px 13px;
    line-height: 1.6;
    font-size: 14px;
    margin-bottom: 12px;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.ai-message {
    background: #ffffff;
    border: 1px solid #dbe5f3;
    border-top-left-radius: 4px;
}

.user-message {
    margin-left: auto;
    background: linear-gradient(135deg, #2f7cf6 0%, #2563eb 100%);
    border: 1px solid #2f64d3;
    color: #ffffff;
    border-top-right-radius: 4px;
    box-shadow: var(--user-bubble-shadow);
}

.input-area {
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid var(--border);
    padding: 10px 14px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
    color: var(--text);
    font-size: 14px;
    resize: none;
    outline: none;
}

#aiInput {
    flex: 1;
    min-height: 40px;
    max-height: 88px;
    padding: 9px 12px;
}

#aiInput:focus,
.form-textarea:focus,
.form-input:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.btn-send {
    width: 64px;
    min-height: 40px;
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--btn-primary-shadow);
}

.btn-send:hover {
    background: var(--primary-press);
}

.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
}

.form-textarea {
    min-height: 110px;
    padding: 10px 12px;
}

.form-input {
    width: 100%;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 12px;
    outline: none;
    font-size: 14px;
    background: #f8fafc;
}

.result-panel {
    margin-top: 16px;
    min-height: 100px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    padding: 12px;
}

.empty-tip {
    margin-top: 28px;
    text-align: center;
    color: var(--text-subtle);
    font-size: 13px;
}

.tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
}

.tag-group {
    background: #dbeafe;
    color: #1d4ed8;
}

.loading-spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

.is-hidden {
    display: none !important;
}

.markdown-body p {
    margin: 0 0 8px;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.markdown-body th,
.markdown-body td {
    white-space: nowrap;
    text-align: left;
    font-size: 12px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.markdown-body th {
    background: #f1f5f9;
    font-weight: 600;
}

@media (max-width: 760px) {
    body {
        padding: 0;
    }

    .app-shell {
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        height: 100vh;
    }

    .app-topbar {
        padding: 9px 12px;
    }

    .app-topbar-title {
        font-size: 14px;
    }

    .tab-header {
        gap: 4px;
        padding: 4px;
    }

    .tab-item {
        flex-direction: column;
        gap: 2px;
        padding: 6px 2px;
    }

    .tab-item span {
        font-size: 11px;
    }

    .tab-item .bi {
        font-size: 13px;
    }

    .toolbar-surface {
        padding: 8px 12px;
    }

    .scroll-area {
        padding: 14px;
    }

    .input-area {
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .live-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
