/* ==========================================================================
   苏州智蜜 · 合同发票收支管理 —— 现代化升级版
   （含云智慧同步的「基础设置」样式）
   自包含样式表（不依赖任何外部 CDN）
   ========================================================================== */

:root {
    --bg:          #f4f6fb;
    --surface:     #ffffff;
    --surface-2:   #fafbfe;
    --border:      #e5e9f2;
    --border-2:    #eef1f7;
    --text:        #1f2937;
    --text-2:      #4b5563;
    --muted:       #8a94a6;

    --brand:       #1d6ff2;
    --brand-dark:  #1558c4;
    --brand-soft:  #eaf2ff;
    --brand-grad:  linear-gradient(135deg, #1d6ff2 0%, #22b8f0 100%);

    --green:       #12a150;
    --green-soft:  #e8f7ee;
    --red:         #e5484d;
    --red-soft:    #fdeced;
    --amber:       #d97706;
    --amber-soft:  #fff5e6;

    --radius:      12px;
    --radius-sm:   8px;
    --shadow-sm:   0 1px 2px rgba(16, 24, 40, .06);
    --shadow:      0 4px 16px rgba(16, 24, 40, .08);
    --shadow-lg:   0 18px 48px rgba(16, 24, 40, .18);
    --sidebar-w:   232px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }

/* ---------------------------------------------------------------- 布局 -- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-2);
}
.brand img { width: 40px; height: 40px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; letter-spacing: .5px; }
.brand-text span { font-size: 11px; color: var(--muted); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-weight: 500;
    transition: background .15s, color .15s;
    position: relative;
}
.nav-item svg { flex: 0 0 auto; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-item.active svg { opacity: 1; }
.nav-item.active::before {
    content: "";
    position: absolute;
    left: -10px; top: 8px; bottom: 8px;
    width: 3px; border-radius: 0 3px 3px 0;
    background: var(--brand-grad);
}
.sidebar-foot { padding: 12px 18px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border-2); }

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

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 22px;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.page-title { font-size: 17px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.user-chip .user-name { font-weight: 600; }
.user-chip small { color: var(--muted); font-size: 11px; }

.content { padding: 20px 22px 40px; flex: 1; }
.footer { padding: 14px 22px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border-2); }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface);
    font-size: 16px; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); }
.only-mobile { display: none; }

/* --------------------------------------------------------------- 卡片 -- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
    overflow: hidden;
}
.card-head {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-2);
}
.card-title { font-size: 15px; font-weight: 600; }
.card-title small { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px 18px; }
.card-body.p0 { padding: 0; }

/* --------------------------------------------------------------- 按钮 -- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand-grad); border-color: transparent; color: #fff; box-shadow: 0 2px 8px rgba(29, 111, 242, .3); }
.btn-primary:hover { filter: brightness(1.05); background: var(--brand-grad); }
.btn-danger { color: var(--red); border-color: #f4c9cb; background: var(--red-soft); }
.btn-danger:hover { background: #fbdfe1; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* --------------------------------------------------------- 表单控件 -- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--text-2); font-weight: 500; }
.input, .select, .textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(29, 111, 242, .13);
}
.textarea { min-height: 84px; resize: vertical; }
.input.mini { width: auto; padding: 5px 8px; font-size: 12px; }
.radio-row { display: flex; align-items: center; gap: 16px; padding: 5px 0; }
.radio-row label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .col-span-2 { grid-column: span 2; }

/* --------------------------------------------------------- 筛选栏 -- */
.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.filter-bar .field { margin-bottom: 0; }
.filter-actions { display: flex; gap: 8px; align-items: end; }

/* --------------------------------------------------------- 数据表 -- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border-2); text-align: left; white-space: nowrap; }
.table thead th {
    background: var(--surface-2);
    color: var(--text-2);
    font-weight: 600;
    font-size: 12px;
    position: sticky; top: 0; z-index: 1;
    border-bottom: 1px solid var(--border);
}
.table tbody tr:hover { background: #f8fafe; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td, .table tfoot th {
    background: var(--surface-2);
    font-weight: 600;
    border-top: 1px solid var(--border);
    border-bottom: none;
    position: sticky; bottom: 0;
}
.table .col-actions { text-align: center; }
.table .wrap-cell { white-space: normal; min-width: 160px; max-width: 320px; }

.sortable { color: var(--text-2); font-weight: 600; }
.sortable:hover { color: var(--brand); }
.arrow { color: var(--brand); }

.amt-neg { color: var(--red); }
.amt-bold { font-weight: 700; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* --------------------------------------------------------- 徽标 -- */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600; line-height: 1.7; white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-gray  { background: #eef1f7; color: #64748b; }
.badge-blue  { background: var(--brand-soft); color: var(--brand); }
.badge-red   { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }

/* --------------------------------------------------------- KPI 卡 -- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--brand-grad); opacity: .9; }
.kpi.kpi-green::after { background: linear-gradient(180deg, #12a150, #34d399); }
.kpi.kpi-red::after { background: linear-gradient(180deg, #e5484d, #fb7185); }
.kpi.kpi-amber::after { background: linear-gradient(180deg, #d97706, #fbbf24); }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; letter-spacing: -.3px; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* --------------------------------------------------------- 图表 -- */
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding: 10px 2px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
    width: 100%; max-width: 46px; border-radius: 6px 6px 0 0;
    background: var(--brand-grad); min-height: 2px;
    transition: filter .15s;
}
.bar:hover { filter: brightness(1.08); }
.bar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bar-value { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.dist-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border-2); }
.dist-row:last-child { border-bottom: none; }
.dist-name { width: 96px; flex: 0 0 96px; font-size: 12px; color: var(--text-2); }
.dist-track { flex: 1; height: 8px; background: #eef1f7; border-radius: 4px; overflow: hidden; }
.dist-fill { height: 100%; background: var(--brand-grad); border-radius: 4px; }
.dist-val { width: 110px; flex: 0 0 110px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- 分页 -- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; flex-wrap: wrap; }
.pager-info { color: var(--muted); font-size: 12px; }
.pager-btns { display: flex; gap: 4px; }
.page-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; padding: 0 8px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-2); font-size: 13px;
}
.page-btn:hover { background: var(--surface-2); }
.page-btn.active { background: var(--brand-grad); color: #fff; border-color: transparent; }
.page-btn.disabled { opacity: .45; pointer-events: none; }

/* --------------------------------------------------------- 提示 -- */
.flash-wrap { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid transparent; }
.flash-error   { background: var(--red-soft); color: #b42318; border-color: #f4c9cb; }
.flash-success { background: var(--green-soft); color: #067647; border-color: #c3e9d2; }
.flash-info    { background: var(--brand-soft); color: var(--brand-dark); border-color: #cfe0ff; }

/* --------------------------------------------------------- 弹窗 -- */
.modal { position: fixed; inset: 0; z-index: 100; display: none; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, .48); backdrop-filter: blur(2px); }
.modal-dialog {
    position: relative; margin: 5vh auto; width: min(920px, calc(100% - 32px));
    max-height: 90vh; display: flex; flex-direction: column;
    background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
    animation: modalIn .18s ease-out;
}
.modal-dialog.narrow { width: min(560px, calc(100% - 32px)); }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-2); }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border-2); background: var(--surface-2); border-radius: 0 0 14px 14px; }

/* --------------------------------------------------------- 表格内操作 -- */
.row-actions { display: inline-flex; gap: 6px; }
.link-btn { background: none; border: none; padding: 2px 4px; cursor: pointer; color: var(--brand); font-size: 13px; }
.link-btn.danger { color: var(--red); }
.link-btn:hover { text-decoration: underline; }

/* --------------------------------------------------------- 空状态 -- */
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-icon { font-size: 30px; opacity: .35; margin-bottom: 8px; }

/* --------------------------------------------------------- 自动补全 -- */
.auto-wrap { position: relative; }
.autocomplete-list {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
}
.autocomplete-list:empty { display: none; }
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border-2); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--brand-soft); }
.autocomplete-item .ac-id { color: var(--muted); font-size: 11px; margin-left: 6px; }

/* --------------------------------------------------------- Toast -- */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 11px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
    font-size: 13px; color: #fff; background: #1f2937; animation: modalIn .18s ease-out;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

/* --------------------------------------------------------- 登录页 -- */
.login-body {
    min-height: 100vh; margin: 0;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1200px 600px at 50% -10%, #dbeafe 0%, transparent 60%), var(--bg);
    padding: 20px;
}
.login-card {
    width: 100%; max-width: 380px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; box-shadow: var(--shadow-lg);
    padding: 30px 28px 22px;
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand img { width: 76px; height: 76px; object-fit: contain; }
.login-brand h1 { font-size: 22px; margin-top: 8px; letter-spacing: 2px; }
.login-brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.login-card form { margin-top: 14px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ------------------------------------------------- 总览 · 期间汇总 -- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }

.period-note { margin-top: 12px; font-size: 12px; color: var(--muted); }
.period-note b { color: var(--text-2); font-weight: 600; }
.period-note .dot { margin: 0 8px; color: #cfd6e4; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.seg a { padding: 5px 14px; font-size: 12px; color: var(--text-2); text-decoration: none; border-left: 1px solid var(--border); }
.seg a:first-child { border-left: none; }
.seg a:hover { background: #fff; color: var(--brand); }
.seg a.active { background: var(--brand-grad); color: #fff; font-weight: 600; }

.mini-bar { height: 5px; background: #eef1f7; border-radius: 3px; overflow: hidden; width: 100%; max-width: 110px; margin: 6px 0 0 auto; }
.mini-bar > span { display: block; height: 100%; background: var(--brand-grad); border-radius: 3px; }

.kpi.kpi-blue::after { background: linear-gradient(180deg, #1d6ff2, #38bdf8); }
.kpi.kpi-cyan::after { background: linear-gradient(180deg, #0891b2, #22d3ee); }

.table tbody tr.row-muted { color: var(--muted); background: var(--surface-2); }
.table tbody tr.row-muted td { font-style: normal; }
.more-note { color: var(--muted); font-size: 12px; text-align: center; padding: 10px 0; }

.ref-link { color: var(--brand); text-decoration: none; border-bottom: 1px dashed currentColor; }
.ref-link:hover { opacity: .75; }
.muted-text { color: var(--muted); font-size: 12px; }

/* --------------------------------------------------------- 响应式 -- */
@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; height: 100vh;
        transform: translateX(-100%); transition: transform .22s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: none; }
    .only-mobile { display: inline-flex; }
    .content { padding: 14px; }
    .topbar { padding: 10px 14px; }
    .user-chip small { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .col-span-2 { grid-column: span 1; }
    .modal-dialog { margin: 2vh auto; max-height: 94vh; }
    .page-title { font-size: 15px; }
}
@media (max-width: 560px) {
    .kpi-value { font-size: 19px; }
    .dist-name { width: 68px; flex-basis: 68px; }
    .dist-val { width: 84px; flex-basis: 84px; }
}
