:root {
  --purple: #542649;
  --purple-soft: #EDE5F0;
  --purple-text: #4A2B55;
  --green: #D9EAD3;
  --green-d: #2F5D34;
  --line: #e3dce6;
  --bg: #f7f5f8;
  --card: #fff;
  --ink: #222;
  --muted: #6b6270;
  --warn: #b3541e;
  --danger: #b42318;
  --blue: #2563eb;
  --shadow: 0 8px 24px rgba(84, 38, 73, 0.10);
  --radius: 12px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.6; font-size: 14px; }
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #f3edf5 0%, #f7f5f8 55%, #eef4ec 100%); padding: 20px; }
.login-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 32px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.login-brand h1 { font-size: 20px; margin: 0 0 4px; }
.login-brand p { color: var(--muted); margin: 0; font-size: 13px; }
.brand-mark { width: 46px; height: 46px; border-radius: 12px; background: var(--purple); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; flex: 0 0 auto; }
.brand-mark.small { width: 36px; height: 36px; font-size: 18px; border-radius: 10px; }
label { display: block; font-weight: 600; margin: 12px 0 5px; color: var(--purple-text); }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-soft); }
textarea { min-height: 72px; resize: vertical; }
.form-error { color: var(--danger); background: #fdf2f2; border: 1px solid #f3c6c2; border-radius: 8px; padding: 8px 10px; margin-top: 10px; font-size: 13px; }
.login-hint { margin: 18px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: #43203a; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--purple-soft); }
.btn-link { background: transparent; color: var(--purple); border: none; padding: 4px 6px; }
.btn-link:hover { text-decoration: underline; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; margin-top: 20px; padding: 11px; }

.app-view { display: flex; min-height: 100vh; }
.sidebar { width: 198px; flex: 0 0 198px; background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 14px; border-bottom: 1px solid var(--line); }
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand span { display: block; color: var(--muted); font-size: 12px; }
.nav-menu { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item { text-align: left; border: none; background: transparent; padding: 9px 12px; border-radius: 7px; color: #4b4350; font-weight: 600; font-size: 13.5px; }
.nav-item:hover { background: var(--purple-soft); }
.nav-item.active { background: var(--purple); color: #fff; }
.sidebar-footer { margin-top: auto; padding: 12px 14px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 14px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.topbar h2 { margin: 0; font-size: 19px; color: var(--purple); }
.topbar p { margin: 1px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.content { padding: 18px 24px 36px; }
.view { display: none; }
.view.active { display: block; }

.hero-card { background: linear-gradient(120deg, #542649 0%, #6d305f 55%, #4a2b55 100%); color: #fff; border-radius: var(--radius); padding: 20px 24px; margin-bottom: 16px; display: flex; gap: 32px; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.hero-main { min-width: 260px; }
.hero-label { font-size: 13px; opacity: .85; display: flex; align-items: center; gap: 8px; }
.hero-live { background: rgba(255,255,255,.2); border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.hero-value { font-size: 38px; font-weight: 700; line-height: 1.2; margin: 6px 0 4px; letter-spacing: -.5px; }
.hero-sub { font-size: 12px; opacity: .8; }
.hero-split { flex: 1; max-width: 460px; }
.hero-split-title { font-size: 12px; opacity: .85; margin-bottom: 8px; }
.split-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; margin: 6px 0; }
.split-row > span { width: 62px; flex: none; opacity: .9; }
.split-row > strong { width: 96px; text-align: right; flex: none; font-weight: 600; }
.split-track { flex: 1; height: 9px; background: rgba(255,255,255,.18); border-radius: 6px; overflow: hidden; }
.split-fill { height: 100%; background: #a8d5a0; border-radius: 6px; transition: width .4s; }
.split-fill.alt { background: #ffd28a; }
@media (max-width: 900px) { .hero-card { flex-direction: column; align-items: stretch; gap: 18px; } .hero-split { max-width: none; } }

.perm-body { padding: 14px 16px; }
.perm-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.perm-item { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fcfafd; }
.perm-item-label { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.perm-opts { display: flex; gap: 5px; }
.perm-opts button { flex: 1; font-size: 12px; padding: 4px 2px; border: 1px solid var(--line); background: #fff; border-radius: 6px; color: var(--muted); }
.perm-opts button.on { background: var(--purple); color: #fff; border-color: var(--purple); }
.perm-opts button.on.view { background: #2563eb; border-color: #2563eb; }
.perm-foot { padding: 0 16px 16px; text-align: right; }
@media (max-width: 900px) { .perm-grid { grid-template-columns: repeat(2, 1fr); } }

.range-list { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.range-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fcfafd; }
.range-row:has(.range-on:checked) { border-color: #c8a9c0; background: #fbf5fa; }
.range-check { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 104px; }
.range-check input { width: 15px; height: 15px; accent-color: var(--purple); }
.range-tag { font-size: 11px; color: var(--muted); background: var(--purple-soft); border-radius: 8px; padding: 1px 8px; }
.range-sep { color: var(--muted); font-size: 12.5px; }
.range-row .search-input { width: 140px; }
.range-row .range-channel { width: 180px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-grid.compact { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; border-top: 3px solid var(--purple); }
.kpi-card.warm { border-top-color: var(--warn); }
.kpi-card.green { border-top-color: var(--green-d); }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 25px; font-weight: 700; margin: 5px 0 2px; }
.kpi-value.money { font-size: 20px; }
.kpi-foot { color: var(--muted); font-size: 11.5px; }

.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.panel-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel-head h3 { margin: 0; font-size: 15px; color: var(--purple); }
.panel-note { padding: 0 16px; color: var(--muted); font-size: 12.5px; }
.sync-guide { padding: 12px 16px 16px; color: var(--text); font-size: 13px; line-height: 1.75; }
.sync-guide p { margin: 0 0 8px; }
.sync-guide ol { margin: 0 0 10px; padding-left: 22px; }
.sync-guide li { margin: 2px 0; }
.sync-warn { color: #b3541e; background: #fff5ea; border-left: 3px solid #e08c3c; padding: 8px 12px; border-radius: 4px; font-size: 12.5px; }
.expert-detail-row > td { background: #faf7fb; padding: 0 !important; }
.expert-detail { padding: 8px 16px 12px 34px; display: flex; flex-direction: column; gap: 4px; }
.detail-line { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--text); padding: 4px 0; border-bottom: 1px dashed #e6dcea; }
.detail-line:last-child { border-bottom: none; }
.detail-proj { flex: 1; min-width: 180px; color: var(--muted); }
.button-row { padding: 16px; display: flex; gap: 10px; flex-wrap: wrap; }

.status-bars { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.status-row { display: grid; grid-template-columns: 110px 1fr 90px; gap: 8px; align-items: center; font-size: 12.5px; }
.status-track { height: 8px; background: var(--purple-soft); border-radius: 999px; overflow: hidden; }
.status-fill { height: 100%; background: var(--purple); border-radius: 999px; }
.status-count { text-align: right; color: var(--muted); }
.aging-row { grid-template-columns: 78px 1fr 168px; }
.detail-money { white-space: nowrap; font-variant-numeric: tabular-nums; }
.mini-list { padding: 6px 16px 12px; }
.mini-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 12.5px; }
.mini-item:last-child { border-bottom: none; }
.mini-item strong { display: block; }
.mini-item span { color: var(--muted); }
.mini-amount { color: var(--green-d); font-weight: 700; white-space: nowrap; }
.empty { padding: 22px 16px; text-align: center; color: var(--muted); }
.notice { background: #fff4e6; border: 1px solid #f0c9a0; color: var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar-note { color: var(--muted); font-size: 12.5px; }
.inline-label { margin: 0; font-size: 12.5px; }
.search-input { max-width: 230px; }
.select-input { max-width: 150px; }

.table-scroll { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table th { background: var(--purple-soft); color: var(--purple-text); font-weight: 600; }
.data-table tr:nth-child(even) td { background: #faf7fb; }
.data-table tbody tr:hover td { background: #f3eef6; }
.data-table tr.done td { color: var(--muted); text-decoration: line-through; }
.cell-wrap { white-space: normal; min-width: 180px; max-width: 320px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.profit { color: var(--green-d); }
.amount.due { color: var(--warn); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; background: #eee9f0; color: var(--purple-text); }
.tag.blue { background: #e8f0fe; color: #1d4ed8; }
.tag.green { background: var(--green); color: var(--green-d); }
.tag.orange { background: #fff0e2; color: var(--warn); }
.tag.red { background: #fdecea; color: var(--danger); }
.tag.gray { background: #eee; color: #666; }
.row-actions { display: flex; gap: 2px; }

.schedule-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.expert-block { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.expert-bar { background: var(--green); color: var(--green-d); font-weight: 700; padding: 8px 12px; display: flex; justify-content: space-between; }
.schedule-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.schedule-table th { background: var(--purple-soft); color: var(--purple-text); padding: 6px 8px; text-align: left; }
.schedule-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.schedule-table tr:nth-child(even) td { background: #F3EEF6; }
.schedule-table td:nth-child(2) { word-break: break-all; max-width: 150px; }
.schedule-table td:nth-child(3) { white-space: normal; }
.proj-sub { display: block; color: var(--muted); font-size: 11.5px; }
.channel-prefix { color: var(--purple); font-weight: 600; }

.settings-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 14px; }
.settings-grid .panel { margin-bottom: 0; }
.form-stack { padding: 16px; }
.form-stack .btn { margin-top: 16px; }

.modal-mask { position: fixed; inset: 0; background: rgba(84, 38, 73, .42); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100; }
.modal-card { background: var(--card); border-radius: 14px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; color: var(--purple); }
.modal-form { padding: 4px 18px 12px; }
.modal-form .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-form .full { grid-column: 1 / -1; }
.modal-form .check-row { display: flex; align-items: center; gap: 8px; }
.modal-form .check-row input { width: auto; }
.modal-form .check-row label { margin: 0; }
#modalError { margin: 0 18px 12px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.icon-btn { border: none; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); padding: 2px 8px; }
.toast { position: fixed; right: 22px; bottom: 22px; background: var(--purple); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 200; max-width: 360px; }

.ocr-card { width: min(1080px, 94vw); max-height: 92vh; display: flex; flex-direction: column; }
.ocr-body { display: grid; grid-template-columns: 320px 1fr; gap: 16px; padding: 16px 18px; overflow: auto; }
.ocr-left img { width: 100%; max-height: 340px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; }
.ocr-status { margin-top: 8px; font-size: 13px; color: var(--muted); }
.ocr-right label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.ocr-right textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 9px; font-family: inherit; font-size: 13px; }
.ocr-right .btn { margin-top: 8px; }
.ocr-rows { margin-top: 12px; max-height: 320px; overflow: auto; }
.ocr-rows table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ocr-rows th, .ocr-rows td { border-bottom: 1px solid var(--line); padding: 5px; text-align: left; white-space: nowrap; }
.ocr-rows input { width: 100%; min-width: 54px; border: 1px solid var(--line); border-radius: 4px; padding: 4px; font-size: 12px; }

@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } .kpi-grid.compact { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .panel-grid, .settings-grid { grid-template-columns: 1fr; } .kpi-grid, .kpi-grid.compact { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) {
  .app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex: none; }
  .sidebar-brand { padding: 10px 14px; }
  .nav-menu { flex-direction: row; overflow-x: auto; padding: 8px; }
  .nav-item { white-space: nowrap; padding: 7px 10px; }
  .sidebar-footer { display: none; }
  .topbar { padding: 12px 14px; }
  .content { padding: 14px; }
  .search-input, .select-input { max-width: none; }
  .modal-form .form-row { grid-template-columns: 1fr; }
  .modal-form .full { grid-column: auto; }
}
