:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --nav: #0f172a;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --warn: #d97706;
    --ok: #059669;
    --radius: 10px;
    --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13.5px;
    line-height: 1.5;
}

.hidden { display: none !important; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 7px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    white-space: nowrap;
}
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px 16px; font-size: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-outline-light { background: transparent; color: #e2e8f0; border-color: rgba(255,255,255,0.28); }
.btn-outline-light:hover { background: rgba(255,255,255,0.1); }
.btn-danger-outline { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger-outline:hover { background: #fef2f2; }

/* Login */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #1e3a8a 100%);
}
.login-card {
    width: 100%;
    max-width: 440px;
    background: #fff;
    border-radius: 14px;
    padding: 30px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}
.login-brand h1 { margin: 0; font-size: 19px; color: #0f172a; }
.login-brand p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff;
    font-weight: 800;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.5px;
}
.brand-mark.sm { width: 34px; height: 34px; font-size: 12px; border-radius: 8px; }

.login-tip {
    margin-top: 16px;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    color: var(--muted);
}

.local-quick {
    margin-top: 14px;
    padding: 10px 12px;
    background: #eff6ff;
    border: 1px dashed #93c5fd;
    border-radius: 8px;
}
.local-quick-title { font-size: 12px; font-weight: 700; color: #1e40af; margin-bottom: 6px; }
.local-quick-btns { display: flex; flex-wrap: wrap; gap: 5px; }
.quick-chip {
    padding: 3px 8px;
    font-size: 11.5px;
    background: #fff;
    border: 1px solid #bfdbfe;
    border-radius: 5px;
    color: #1d4ed8;
    cursor: pointer;
}
.quick-chip:hover { background: #dbeafe; }

/* Topbar */
.topbar {
    background: var(--nav);
    color: #fff;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 40;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 15.5px; font-weight: 700; letter-spacing: 0.3px; }
.topbar-sub { font-size: 12px; color: #94a3b8; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar .btn-ghost { background: rgba(255,255,255,0.1); color: #f8fafc; border-color: rgba(255,255,255,0.2); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.18); }

.main-container {
    max-width: 1480px;
    margin: 0 auto;
    padding: 18px 22px 48px;
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.03);
    transition: border-color 0.15s;
}
.kpi-card.clickable { cursor: pointer; }
.kpi-card.clickable:hover { border-color: var(--primary); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-val { font-size: 23px; font-weight: 700; color: #0f172a; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi-card.warn .kpi-val { color: var(--warn); }
.kpi-card.danger .kpi-val { color: var(--danger); }
.kpi-card.ok .kpi-val { color: var(--ok); }
.kpi-card.primary .kpi-val { color: var(--primary); }

/* Tabs */
.tabs-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.tab-sep {
    width: 1px;
    height: 18px;
    background: #cbd5e1;
    margin: 0 4px;
    display: inline-block;
}
.filters input[type="date"] {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12.5px;
    background: #fff;
    font-family: inherit;
}
.tab-btn {
    padding: 7px 15px;
    border-radius: 7px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    font-family: inherit;
}
.tab-btn:hover { color: var(--text); background: #e2e8f0; }
.tab-btn.active { background: #0f172a; color: #fff; }

/* Panel & Toolbar */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select, .filters input[type="text"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    font-family: inherit;
}
.filters input[type="text"] { min-width: 220px; }
.chk-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    font-size: 12.5px;
    cursor: pointer;
    user-select: none;
}
.table-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.2px; }
.data-table th {
    background: #f8fafc;
    color: #334155;
    font-weight: 700;
    text-align: left;
    padding: 8px 7px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 8px 7px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}
.data-table tr:hover td { background: #f8fafc; }
.data-table tr.row-conflict td { background: #fff5f5; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.sub-text { font-size: 11.8px; color: var(--muted); margin-top: 2px; }
.ellipsis-2 {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}
.b-gray { background: #f1f5f9; color: #475569; }
.b-blue { background: #dbeafe; color: #1d4ed8; }
.b-green { background: #d1fae5; color: #065f46; }
.b-amber { background: #fef3c7; color: #b45309; }
.b-red { background: #fee2e2; color: #b91c1c; }
.b-purple { background: #ede9fe; color: #5b21b6; }

.tag-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }

/* Sections & Forecast */
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.section-head h3 { margin: 0; font-size: 15px; }
.sub-h3 { margin: 18px 0 10px; font-size: 14px; color: #0f172a; }
.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; }
@media (max-width: 960px) { .split-grid { grid-template-columns: 1fr; } }

.seg-group { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg-btn {
    border: none;
    background: #fff;
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    font-family: inherit;
}
.seg-btn.active { background: var(--primary); color: #fff; }

/* SMTP box */
.smtp-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}
.smtp-form-grid {
    display: grid;
    grid-template-columns: 1fr 1.4fr auto;
    gap: 12px;
    align-items: end;
    margin-top: 10px;
}
@media (max-width: 820px) { .smtp-form-grid { grid-template-columns: 1fr; } }
.small-tip { font-size: 12px; margin-top: 8px; }

/* Forms & Inputs */
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 680px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
    padding: 7px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.14);
}
.field input:disabled, .field select:disabled { background: #f1f5f9; color: #64748b; }
.dual-select { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.month-row { display: flex; align-items: center; gap: 10px; }
.chk-inline { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.muted { color: var(--muted); font-size: 12.5px; margin: 0; }

.alert { padding: 9px 12px; border-radius: 7px; font-size: 12.5px; margin-top: 6px; }
.alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }

/* Modals & Drawer */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}
.modal-card {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-card.sm { max-width: 460px; }
.modal-card.md { max-width: 680px; }
.modal-card.lg { max-width: 820px; }

.modal-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.icon-close {
    background: transparent;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
}
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.readonly-banner {
    padding: 10px 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid var(--border);
    margin-bottom: 14px;
    font-size: 12.5px;
}
.vscp-box {
    margin-top: 12px;
    padding: 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
}

/* Drawer */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    justify-content: flex-end;
    z-index: 95;
}
.drawer-card {
    width: 100%;
    max-width: 620px;
    height: 100%;
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.18);
}
.drawer-body { padding: 16px 20px 30px; overflow-y: auto; flex: 1; }
.detail-kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px; font-size: 12.8px; }
.kv-item { border-bottom: 1px dashed #f1f5f9; padding-bottom: 5px; }
.kv-k { color: var(--muted); font-size: 11.5px; }
.kv-v { font-weight: 600; color: #0f172a; word-break: break-all; }

.conflict-panel {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 12.5px;
}
.conflict-panel.hit { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.conflict-panel.clean { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.conflict-panel ul { margin: 6px 0 0 18px; padding: 0; }

.audit-radio-group { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-card {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
}
.radio-card.ok { border-color: #6ee7b7; background: #ecfdf5; color: #065f46; }
.radio-card.bad { border-color: #fca5a5; background: #fef2f2; color: #991b1b; }
.radio-card.warn { border-color: #fcd34d; background: #fffbeb; color: #92400e; }

.drawer-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.mail-preview-box { border: 1px solid var(--border); border-radius: 8px; padding: 14px; background: #fff; overflow-x: auto; }

/* Toast */
.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    background: #0f172a;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

/* POS & Analytics additions */
.search-wrap { position: relative; }
.search-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: 2px;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    max-height: 230px;
    overflow-y: auto;
    z-index: 120;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}
.search-opt {
    padding: 7px 11px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 12.8px;
}
.search-opt:hover { background: #eff6ff; color: var(--primary); }
.search-opt .ser-tag { font-size: 11px; color: var(--muted); white-space: nowrap; }

.hint-line { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hint-line.warn { color: #b45309; font-weight: 600; background: #fffbeb; padding: 4px 8px; border-radius: 5px; border: 1px solid #fde68a; }
.hint-line.ok { color: #065f46; }

.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
    font-size: 12.5px;
    color: var(--muted);
}

.analytics-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 14px 16px;
}
.chart-box { width: 100%; overflow-x: auto; }
.bar-list { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 120px; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-label { font-weight: 600; color: #334155; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #2563eb, #3b82f6); border-radius: 999px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: #0f172a; white-space: nowrap; }
@media (max-width: 680px) {
    .bar-row { grid-template-columns: 90px 1fr 95px; font-size: 12px; }
}
