/* ============================================================
   FinTax 财务税务管理系统 - 全局样式
   设计基调：Grid 网格 / 冷灰蓝 / 精密仪器感
   参考 AGENTS.md UI 设计指南
   ============================================================ */

:root {
    --background: hsl(220, 20%, 97%);
    --card: hsl(0, 0%, 100%);
    --foreground: hsl(215, 25%, 12%);
    --muted-foreground: hsl(215, 15%, 50%);
    --primary: hsl(215, 60%, 18%);
    --primary-foreground: hsl(0, 0%, 100%);
    --accent: hsl(215, 40%, 95%);
    --accent-foreground: hsl(215, 60%, 18%);
    --border: hsl(215, 20%, 88%);
    --sidebar: hsl(215, 35%, 10%);
    --sidebar-foreground: hsl(215, 15%, 75%);
    --sidebar-primary: hsl(215, 60%, 55%);
    --sidebar-accent: hsl(215, 30%, 16%);
    --sidebar-border: hsl(215, 30%, 14%);
    --success: hsl(152, 55%, 38%);
    --success-bg: hsl(152, 55%, 95%);
    --warning: hsl(38, 85%, 32%);
    --warning-bg: hsl(38, 85%, 94%);
    --destructive: hsl(0, 70%, 50%);
    --destructive-bg: hsl(0, 70%, 96%);
    --mono: 'JetBrains Mono', 'Cascadia Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--foreground);
    background: var(--background);
}

/* ---------- 布局 ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-foreground);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: .5px;
}

.sidebar-brand .logo {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: var(--sidebar-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 8px 0;
}

.sidebar-nav .nav-section {
    padding: 14px 16px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: hsl(215, 15%, 45%);
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--sidebar-foreground);
    text-decoration: none;
    font-size: 13.5px;
    border-left: 3px solid transparent;
    transition: background .15s ease-out;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-accent);
    color: hsl(215, 20%, 90%);
}

.sidebar-nav .nav-link.active {
    border-left-color: var(--sidebar-primary);
    color: #fff;
    background: var(--sidebar-accent);
}

.sidebar-nav .nav-link .nav-icon {
    width: 18px;
    text-align: center;
    opacity: .9;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 52px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar .page-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--foreground);
}

.topbar .user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted-foreground);
    font-size: 13px;
}

.content {
    padding: 20px 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ---------- 卡片 ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 16px;
}

.card + .card {
    margin-top: 16px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--foreground);
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title .muted {
    font-weight: 400;
    font-size: 12px;
    color: var(--muted-foreground);
}

/* ---------- 统计卡片 ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 14px 16px;
    border-left: 3px solid var(--primary);
}

.stat-card.s-success { border-left-color: var(--success); }
.stat-card.s-warning { border-left-color: hsl(38, 85%, 45%); }
.stat-card.s-danger { border-left-color: var(--destructive); }

.stat-card .label {
    font-size: 12px;
    color: var(--muted-foreground);
    margin-bottom: 6px;
}

.stat-card .value {
    font-family: var(--mono);
    font-size: 22px;
    font-weight: 600;
    color: var(--foreground);
}

.stat-card .sub {
    font-size: 12px;
    color: var(--muted-foreground);
    margin-top: 4px;
}

/* ---------- 表格 ---------- */
.table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 2px;
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 500;
    color: var(--muted-foreground);
    border-bottom: 1px solid var(--border);
    background: var(--accent);
    white-space: nowrap;
}

table.data-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table.data-table tbody tr:nth-child(even) {
    background: hsl(220, 20%, 98%);
}

table.data-table tbody tr:hover {
    background: var(--accent);
}

table.data-table tbody tr.row-overdue {
    background: var(--destructive-bg);
    border-left: 3px solid var(--destructive);
    box-shadow: inset 3px 0 0 var(--destructive);
}

table.data-table tbody tr.row-warning {
    background: var(--warning-bg);
    box-shadow: inset 3px 0 0 hsl(38, 85%, 45%);
}

td.num, th.num {
    text-align: right;
    font-family: var(--mono);
}

td.mono {
    font-family: var(--mono);
}

.empty-tip {
    text-align: center;
    color: var(--muted-foreground);
    padding: 24px !important;
}

/* ---------- 状态标签 ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.6;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--destructive-bg); color: var(--destructive); }
.badge-info { background: hsl(215, 40%, 93%); color: hsl(215, 60%, 35%); }
.badge-muted { background: hsl(215, 20%, 93%); color: var(--muted-foreground); }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 2px;
    border: 1px solid transparent;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s ease-out, border-color .15s ease-out;
    text-decoration: none;
    background: transparent;
    color: var(--foreground);
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-foreground);
}

.btn-primary:hover:not(:disabled) {
    background: hsl(215, 60%, 26%);
}

.btn-outline {
    border-color: var(--border);
    background: var(--card);
}

.btn-outline:hover:not(:disabled) {
    background: var(--accent);
    border-color: var(--primary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--accent);
}

.btn-danger {
    background: var(--destructive);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: hsl(0, 70%, 42%);
}

.btn-sm {
    padding: 3px 10px;
    font-size: 12px;
}

.btn-link {
    color: hsl(215, 60%, 35%);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
}

.btn-link:hover { text-decoration: underline; }

/* ---------- 表单 ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.form-grid .full { grid-column: 1 / -1; }

.form-field label {
    display: block;
    font-size: 12.5px;
    color: var(--muted-foreground);
    margin-bottom: 5px;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 2px;
    font-size: 13.5px;
    font-family: inherit;
    background: var(--card);
    color: var(--foreground);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: 2px solid hsl(215, 60%, 45%);
    outline-offset: 1px;
    border-color: var(--primary);
}

.form-field input.mono, .form-field select.mono {
    font-family: var(--mono);
}

.form-field input:read-only {
    background: var(--accent);
    color: var(--muted-foreground);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
    grid-column: 1 / -1;
}

.validation-message {
    color: var(--destructive);
    font-size: 12px;
}

/* ---------- 工具栏 ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.toolbar .spacer { flex: 1; }

.toolbar input[type='text'],
.toolbar select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 2px;
    font-size: 13px;
    background: var(--card);
    color: var(--foreground);
}

.toolbar input[type='text']:focus,
.toolbar select:focus {
    outline: 2px solid hsl(215, 60%, 45%);
    outline-offset: 1px;
}

/* ---------- 分页 ---------- */
.pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted-foreground);
}

.pagination .page-btn {
    min-width: 26px;
    height: 26px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--card);
    cursor: pointer;
    font-size: 12px;
    color: var(--foreground);
}

.pagination .page-btn:hover:not(:disabled) { background: var(--accent); }
.pagination .page-btn:disabled { opacity: .4; cursor: not-allowed; }
.pagination .page-btn.current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- 弹窗 ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 32, .45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 16px;
    z-index: 100;
}

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 560px;
    max-width: 100%;
    max-height: 84vh;
    overflow-y: auto;
    padding: 20px;
}

.modal.wide { width: 720px; }

.modal h3 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
}

.modal .close-x {
    float: right;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--muted-foreground);
    line-height: 1;
}

/* ---------- 仪表盘 ---------- */
.dash-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 16px;
}

.dash-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.dash-list-item:last-child { border-bottom: none; }

.dash-list-item .name {
    font-weight: 500;
}

.dash-list-item .date {
    font-family: var(--mono);
    color: var(--muted-foreground);
    font-size: 12px;
}

.dash-list-item .amount {
    font-family: var(--mono);
    font-weight: 600;
}

/* ---------- 快捷链接 ---------- */
.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.link-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 2px;
    text-decoration: none;
    color: var(--foreground);
    transition: border-color .15s ease-out, background .15s ease-out;
}

.link-card:hover {
    border-color: var(--primary);
    background: var(--accent);
}

.link-card .link-icon {
    width: 38px;
    height: 38px;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.link-card .link-name {
    font-weight: 500;
    font-size: 13.5px;
}

.link-card .link-desc {
    font-size: 12px;
    color: var(--muted-foreground);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- 页面头部 ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.page-header .sub {
    color: var(--muted-foreground);
    font-size: 13px;
    margin-top: 2px;
}

/* ---------- 其它 ---------- */
.mono { font-family: var(--mono); }
.text-muted { color: var(--muted-foreground); }
.text-danger { color: var(--destructive); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-right { text-align: right; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }

a { color: hsl(215, 60%, 35%); }

/* 响应式 */
@media (max-width: 900px) {
    .sidebar { width: 64px; }
    .sidebar-brand span.brand-text, .sidebar-nav .nav-link .nav-text, .sidebar-nav .nav-section { display: none; }
    .dash-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .content { padding: 14px; }
    .stat-grid { grid-template-columns: 1fr; }
}

/* 结果提示条 */
.alert { padding: 10px 14px; border-radius: 2px; border: 1px solid var(--border); font-size: 13px; margin-bottom: 12px; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.alert-danger { background: var(--destructive-bg); color: var(--destructive); border-color: var(--destructive); }

/* 查验详情 */
.detail-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; }
.detail-kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.detail-kv span { color: var(--muted-foreground); font-size: 12px; }
.detail-kv b { font-weight: 500; font-size: 13px; text-align: right; }
.detail-json { background: var(--accent); border: 1px solid var(--border); border-radius: 2px; padding: 12px; font-family: 'JetBrains Mono', monospace; font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; max-height: 320px; overflow: auto; margin: 8px 0 0; }

/* 批量查验 */
.col-check { width: 36px; text-align: center; }
.col-check input { accent-color: var(--primary); cursor: pointer; }
.row-selected { background: var(--accent); }
.batch-input { width: 100%; font-family: 'JetBrains Mono', monospace; font-size: 12.5px; line-height: 1.6; border: 1px solid var(--border); border-radius: 2px; padding: 10px; resize: vertical; }
.batch-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.batch-actions .btn { min-width: 140px; }

/* ---------- 图表 ---------- */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-svg { width: 100%; height: auto; max-height: 340px; display: block; }
.chart-legend { display: flex; gap: 24px; justify-content: center; margin-top: 10px; font-size: 12px; color: var(--muted-foreground); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-bar { display: inline-block; width: 16px; height: 10px; background: #1a2f4a; border-radius: 1px; }
.legend-line { display: inline-block; width: 20px; height: 2px; background: #2b7a57; position: relative; }
.legend-line::before { content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 6px; height: 6px; background: #fff; border: 2px solid #2b7a57; border-radius: 50%; }

/* ---- AI 智能识别面板（智谱多模态） ---- */
.ai-panel {
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: hsl(215, 40%, 97%);
    padding: 14px 16px;
    margin-bottom: 16px;
}
.ai-panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.ai-badge {
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 5px;
    letter-spacing: 1px;
}
.ai-tip { font-size: 12px; margin-left: auto; }
.ai-panel-body {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.ai-file-label { cursor: pointer; display: inline-flex; }
.ai-preview {
    max-height: 90px;
    max-width: 140px;
    border: 1px solid var(--border);
    border-radius: 6px;
    object-fit: contain;
}
.ai-placeholder {
    font-size: 13px;
    color: var(--muted-foreground);
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 8px 14px;
}

/* ---- AI 识别结果：多张发票卡片列表 ---- */
.ai-result-list { margin-top: 14px; }
.ai-result-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    font-size: 13px;
}
.ai-result-head .text-muted { margin-left: auto; }
.ai-invoice-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    padding: 10px 14px;
    margin-bottom: 8px;
    transition: border-color .15s;
}
.ai-invoice-card.saved {
    border-color: #2b7a57;
    background: hsl(150, 30%, 97%);
}
.ai-card-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.ai-card-no { font-weight: 700; font-size: 14px; color: var(--foreground); }
.ai-card-type {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 4px;
    background: hsl(215, 30%, 92%);
    color: var(--primary);
}
.ai-card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 16px;
    font-size: 12px;
    color: var(--muted-foreground);
}
.ai-card-grid > div { display: flex; gap: 6px; }
.ai-card-label { color: var(--muted-foreground); min-width: 64px; }
.ai-card-grid > div > span:last-child { color: var(--foreground); }
.ai-card-actions {
    display: flex;
    align-items: center;
    margin-top: 8px;
    gap: 8px;
}
@media (max-width: 640px) {
    .ai-card-grid { grid-template-columns: 1fr; }
}

/* ---- 图片预览模态框 ---- */
.image-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.image-preview-container {
    background: #fff;
    border-radius: 10px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.image-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    background: hsl(215, 40%, 97%);
}
.image-preview-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--foreground);
}
.image-preview-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--muted-foreground);
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}
.image-preview-close:hover { background: rgba(0,0,0,0.08); color: var(--foreground); }
.image-preview-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: #f5f5f5;
    padding: 16px;
}
.image-preview-img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.image-preview-footer {
    padding: 8px 18px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 12px;
}

/* 表格行可双击提示 */
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: hsl(215, 40%, 97%); }

/* 有原始图片的行标识 */
.img-indicator {
    display: inline-block;
    margin-right: 4px;
    font-size: 12px;
    opacity: 0.7;
    vertical-align: middle;
}
.img-indicator:hover { opacity: 1; }
