:root {
    --color-primary: #0048b8;
    --color-primary-light: #165dff;
    --color-bg: #f2f3f5;
    --color-card: #ffffff;
    --color-text: #1d2129;
    --color-text-secondary: #4e5969;
    --color-text-muted: #86909c;
    --color-border: #e5e6eb;
    --color-danger: #e34d59;
    --color-success: #00b42a;
    --color-warning: #ff7d00;
    --radius: 4px;
    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.04);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.dashboard-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}

.dashboard-header {
    height: 64px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    background: #fff;
    flex-shrink: 0;
    border-bottom: 1px solid var(--color-border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-logo .logo-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    border-radius: 6px;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--color-border);
    margin: 0 4px;
}

.header-sys-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-login {
    height: 36px;
    padding: 0 20px;
    border-radius: 4px;
    background: var(--color-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-login:hover {
    background: var(--color-primary-light);
    box-shadow: 0 2px 8px rgba(0, 72, 184, 0.3);
}

.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.welcome-banner {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    border-radius: 8px;
    padding: 32px 40px;
    margin-bottom: 24px;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.welcome-banner::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.08) 0%, transparent 70%);
    border-radius: 50%;
}

.welcome-banner::after {
    content: '';
    position: absolute;
    bottom: -30%;
    right: 15%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.05) 0%, transparent 70%);
    border-radius: 50%;
}

.welcome-text h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
}

.welcome-text p {
    font-size: 14px;
    opacity: 0.85;
    position: relative;
    z-index: 1;
}

.welcome-icon {
    font-size: 64px;
    opacity: 0.15;
    position: relative;
    z-index: 1;
}

.grid-layout {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.grid-layout-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.flex-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-card);
    border-left: 4px solid var(--color-primary-light);
    transition: box-shadow 0.2s;
}

.stat-card:hover {
    box-shadow: var(--shadow-hover);
}

.stat-card .stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--color-primary-light);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
}

.stat-card .stat-suffix {
    font-size: 14px;
    color: var(--color-text-muted);
    margin-left: 4px;
    font-weight: 400;
}

.chart-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-card);
    transition: box-shadow 0.2s;
}

.chart-card:hover {
    box-shadow: var(--shadow-hover);
}

.chart-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-card-title .chart-hint {
    font-size: 12px;
    color: var(--color-text-muted);
    font-weight: 400;
}

.chart-body {
    height: 240px;
    width: 100%;
}

.full-width {
    grid-column: span 3;
}

.table-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-card);
}

.table-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 16px;
}

.recent-table {
    width: 100%;
    border-collapse: collapse;
}

.recent-table th {
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    background: #fafbfc;
}

.recent-table td {
    font-size: 14px;
    color: var(--color-text-secondary);
    padding: 12px;
    border-bottom: 1px solid var(--color-border);
}

.recent-table tr:last-child td {
    border-bottom: none;
}

.recent-table tbody tr:hover {
    background: #f7f8fa;
}

.model-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
}

.model-tag.gpt {
    background: #e8f3ff;
    color: #165dff;
}

.model-tag.claude {
    background: #fff3e8;
    color: #ff7d00;
}

.model-tag.other {
    background: #e8fff0;
    color: #00b42a;
}

.status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-dot.online {
    background: var(--color-success);
    box-shadow: 0 0 0 3px rgba(0, 180, 42, 0.15);
}

.status-dot.offline {
    background: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(227, 77, 89, 0.15);
}

.dashboard-footer {
    text-align: center;
    padding: 16px 0;
    color: var(--color-text-muted);
    font-size: 13px;
    line-height: 1.8;
}

.dashboard-footer p {
    margin: 0;
}

@media (max-width: 1200px) {
    .grid-layout {
        grid-template-columns: repeat(2, 1fr);
    }
    .grid-layout-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    .full-width {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    .grid-layout {
        grid-template-columns: 1fr;
    }
    .grid-layout-4 {
        grid-template-columns: 1fr;
    }
    .full-width {
        grid-column: span 1;
    }
    .welcome-banner {
        padding: 24px;
    }
    .welcome-text h2 {
        font-size: 20px;
    }
}

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

.fade-in {
    animation: fadeInUp 0.4s ease-out forwards;
}

.fade-in-delay-1 {
    animation-delay: 0.08s;
    opacity: 0;
}

.fade-in-delay-2 {
    animation-delay: 0.16s;
    opacity: 0;
}

.fade-in-delay-3 {
    animation-delay: 0.24s;
    opacity: 0;
}

.fade-in-delay-4 {
    animation-delay: 0.32s;
    opacity: 0;
}

.login-modal-content {
    padding: 40px 48px 32px;
}

.login-modal-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 32px;
    text-align: center;
}

.login-error {
    color: var(--color-danger);
    font-size: 13px;
    margin-top: 8px;
    text-align: center;
    min-height: 20px;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 13px;
    color: var(--color-text-muted);
}

.cas-login-info {
    font-size: 14px;
    color: var(--color-text-secondary);
    text-align: center;
    line-height: 1.6;
    padding: 16px 0;
}

.captcha-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.captcha-img {
    height: 50px;
    width: 160px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    user-select: none;
}

/* ── App Shell (authenticated layout) ── */

.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--color-bg);
}

.sidebar {
    width: 220px;
    background: #fff;
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    height: 64px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 20px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    font-size: 14px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: #f2f3f5;
    color: var(--color-primary);
}

.nav-item.active {
    background: #e8f3ff;
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    font-weight: 500;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.proxy-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--color-success);
    margin-bottom: 4px;
}

.proxy-url {
    font-size: 12px;
    color: var(--color-text-muted);
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ── Header user area ── */

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-primary-light);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.user-name {
    font-size: 14px;
    color: var(--color-text);
    font-weight: 500;
}

.user-role-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #e8f3ff;
    color: var(--color-primary-light);
}

.btn-logout {
    height: 36px;
    padding: 0 16px;
    border-radius: 4px;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 14px;
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: #fff3f3;
    color: var(--color-danger);
    border-color: var(--color-danger);
}

/* ── Page wrapper ── */

.page-wrapper {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.page-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
}

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

/* ── Forms ── */

.form-error {
    color: var(--color-danger);
    font-size: 13px;
    min-height: 18px;
}

/* ── Settings ── */

.settings-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-card);
}

.settings-card h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* ── Date range picker ── */

.date-range-picker {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

/* ── Chat page ── */

.chat-page {
    height: calc(100vh - 112px);
}

.chat-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.chat-header-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    min-height: 400px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-message {
    display: flex;
    gap: 12px;
    max-width: 80%;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.assistant-avatar {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
    color: #fff;
}

.user-avatar {
    background: #e8f3ff;
    color: var(--color-primary-light);
}

.chat-bubble {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.assistant-bubble {
    background: #f2f3f5;
    color: var(--color-text);
}

.user-bubble {
    background: var(--color-primary-light);
    color: #fff;
}

.chat-markdown p {
    margin: 0 0 8px 0;
}
.chat-markdown p:last-child {
    margin-bottom: 0;
}
.chat-markdown pre {
    background: #1d2129;
    color: #e5e6eb;
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
    margin: 8px 0;
}
.chat-markdown code {
    font-size: 13px;
}
.chat-markdown ul, .chat-markdown ol {
    padding-left: 20px;
    margin: 8px 0;
}
.chat-markdown h1, .chat-markdown h2, .chat-markdown h3 {
    margin: 8px 0 4px 0;
    font-size: 15px;
}

.chat-reasoning {
    margin-bottom: 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: #f7f8fa;
    overflow: hidden;
}
.chat-reasoning-summary {
    cursor: pointer;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--color-text-muted);
    user-select: none;
}
.chat-reasoning-summary:hover {
    background: #eef0f3;
}
.chat-reasoning-content {
    padding: 8px 12px;
    border-top: 1px solid var(--color-border);
    font-size: 13px;
    color: var(--color-text-secondary);
    max-height: 300px;
    overflow-y: auto;
}

.chat-input-area {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--color-border);
    align-items: flex-end;
}

/* ── Feather icons fallback ── */

.feather {
    width: 16px;
    height: 16px;
    display: inline-block;
}

.sync-status-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-success);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 1000;
    font-size: 14px;
    color: var(--color-text-primary);
    max-width: 400px;
}

.announcement-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.announcement-item {
    border: 1px solid #e5e6eb;
    border-radius: 6px;
    padding: 12px 16px;
    background: #fafbfc;
}

.announcement-item.pinned {
    border-color: #0048b8;
    background: #f5f8ff;
}

.announcement-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 6px;
}

.announcement-item-title {
    font-weight: 600;
    font-size: 14px;
    color: #1d2129;
}

.announcement-item-time {
    font-size: 12px;
    color: #86909c;
    white-space: nowrap;
}

.announcement-item-content {
    font-size: 13px;
    color: #4e5969;
    line-height: 1.6;
}

.announcement-item-content p {
    margin: 4px 0;
}

.announcement-item-content img {
    max-width: 100%;
}
