:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --text: #18212a;
  --muted: #66717d;
  --line: #e1e6eb;
  --line-strong: #cdd5dd;
  --primary: #246fda;
  --primary-dark: #1858b3;
  --primary-soft: #eaf2fd;
  --teal: #14816f;
  --teal-soft: #e8f5f2;
  --amber: #a8650f;
  --amber-soft: #fff4df;
  --red: #b43c42;
  --red-soft: #fdecee;
  --purple: #7654a7;
  --purple-soft: #f1ecf8;
  --sidebar: #17211d;
  --sidebar-muted: #9aaba4;
  --shadow: 0 8px 24px rgba(23, 33, 29, .07);
  --radius: 8px;
  --sidebar-width: 252px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
svg { flex: 0 0 auto; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: var(--sidebar-width);
  color: #f4f7f5;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.05);
}
.brand {
  min-height: 76px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #2673dd;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(38,115,221,.32);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-name { font-size: 17px; font-weight: 700; line-height: 1.2; }
.brand-subtitle { margin-top: 4px; color: var(--sidebar-muted); font-size: 11px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px 22px; }
.nav-group { margin: 14px 9px 7px; color: #72827c; font-size: 11px; font-weight: 700; }
.nav-item {
  min-height: 42px;
  margin: 3px 0;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 11px;
  color: #b7c4bf;
  border: 1px solid transparent;
  border-radius: 7px;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: #273831; border-color: rgba(255,255,255,.08); }
.nav-item.active::before { content: ""; width: 3px; align-self: stretch; margin-left: -11px; background: #4da77e; border-radius: 0 2px 2px 0; }
.nav-item svg { width: 18px; height: 18px; }
.nav-label { flex: 1; white-space: nowrap; }
.nav-badge { min-width: 21px; height: 21px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 11px; font-size: 11px; font-weight: 700; background: rgba(255,255,255,.1); }
.nav-badge.danger { color: #ffdadd; background: rgba(214,76,84,.2); }
.sidebar-profile { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.profile-row { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  border-radius: 50%;
  font-weight: 700;
}
.profile-meta { min-width: 0; flex: 1; }
.profile-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-role { margin-top: 3px; color: var(--sidebar-muted); font-size: 11px; }
.profile-logout { width: 34px; height: 34px; padding: 0; color: #a9b8b2; background: transparent; border: 0; border-radius: 6px; display: grid; place-items: center; }
.profile-logout:hover { color: #fff; background: rgba(255,255,255,.07); }
.profile-logout svg { width: 17px; height: 17px; }

.main-shell { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 35;
  height: 64px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: rgba(255,255,255,.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.icon-button.menu-toggle { display: none; }
.global-search { position: relative; width: min(430px, 42vw); }
.global-search svg { position: absolute; left: 12px; top: 50%; width: 17px; height: 17px; color: #7c8994; transform: translateY(-50%); }
.global-search input { width: 100%; height: 38px; padding: 0 14px 0 39px; color: var(--text); background: #f5f7f9; border: 1px solid transparent; border-radius: 7px; outline: 0; }
.global-search input:focus { background: #fff; border-color: #9dc2ef; box-shadow: 0 0 0 3px rgba(38,115,221,.1); }
.topbar-spacer { flex: 1; }
.topbar-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.icon-button { position: relative; width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; color: #52606c; background: transparent; border: 1px solid var(--line); border-radius: 7px; }
.icon-button:hover { color: var(--primary); background: var(--primary-soft); border-color: #bfd5f2; }
.icon-button svg { width: 18px; height: 18px; }
.notification-dot { position: absolute; top: 7px; right: 7px; width: 7px; height: 7px; background: var(--red); border: 2px solid #fff; border-radius: 50%; }

.page { padding: 26px 28px 48px; }
.page-head { margin-bottom: 22px; display: flex; align-items: flex-start; gap: 18px; }
.page-head-main { flex: 1; min-width: 0; }
.page-title { margin: 0; font-size: 25px; line-height: 1.25; font-weight: 720; color: #17232d; }
.page-subtitle { margin: 7px 0 0; color: var(--muted); line-height: 1.5; }
.page-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

.button {
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #27333d;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  font-weight: 650;
  white-space: nowrap;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.button:hover { background: #f8fafb; box-shadow: 0 3px 10px rgba(23,33,29,.06); }
.button:active { transform: translateY(1px); }
.button svg { width: 16px; height: 16px; }
.button.primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.success { color: #fff; background: var(--teal); border-color: var(--teal); }
.button.danger { color: var(--red); background: #fff; border-color: #efc4c7; }
.button.ghost { background: transparent; border-color: transparent; }
.button.small { min-height: 32px; padding: 0 10px; font-size: 12px; }
.button.icon-only { width: 38px; padding: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { min-width: 0; min-height: 130px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 9px rgba(23,33,29,.025); }
.stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stat-label { color: var(--muted); font-weight: 600; }
.stat-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 7px; }
.stat-icon svg { width: 18px; height: 18px; }
.stat-icon.blue { color: var(--primary); background: var(--primary-soft); }
.stat-icon.green { color: var(--teal); background: var(--teal-soft); }
.stat-icon.amber { color: var(--amber); background: var(--amber-soft); }
.stat-icon.red { color: var(--red); background: var(--red-soft); }
.stat-icon.purple { color: var(--purple); background: var(--purple-soft); }
.stat-value { margin-top: 15px; font-size: 25px; font-weight: 750; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-foot { margin-top: 12px; color: var(--muted); font-size: 12px; }
.trend-up { color: var(--teal); font-weight: 700; }
.trend-down { color: var(--red); font-weight: 700; }

.grid-2 { display: grid; grid-template-columns: minmax(0,1.55fr) minmax(320px,.8fr); gap: 16px; margin-bottom: 16px; }
.grid-equal { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; margin-bottom: 16px; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(23,33,29,.025); }
.panel-head { min-height: 58px; padding: 14px 17px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.panel-title-wrap { min-width: 0; flex: 1; }
.panel-title { margin: 0; font-size: 15px; font-weight: 720; }
.panel-subtitle { margin-top: 4px; color: var(--muted); font-size: 12px; }
.panel-body { padding: 17px; }
.panel-body.flush { padding: 0; }
.chart-wrap { position: relative; height: 278px; }
.chart-wrap.small { height: 230px; }

.toolbar { margin-bottom: 14px; padding: 12px; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar form { width: 100%; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.field, .select, .textarea { width: 100%; color: var(--text); background: #fff; border: 1px solid var(--line-strong); border-radius: 7px; outline: none; }
.field, .select { height: 38px; padding: 0 11px; }
.textarea { min-height: 96px; padding: 10px 11px; resize: vertical; line-height: 1.55; }
.field:focus, .select:focus, .textarea:focus { border-color: #8eb7e9; box-shadow: 0 0 0 3px rgba(38,115,221,.1); }
.toolbar-search { position: relative; min-width: 250px; flex: 1; }
.toolbar-search svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; color: #7e8a94; transform: translateY(-50%); }
.toolbar-search .field { padding-left: 35px; }
.toolbar .select { width: auto; min-width: 150px; }

.table-scroll { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.data-table th { height: 43px; padding: 0 14px; color: #6f7a84; background: #f8fafb; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; text-align: left; }
.data-table td { height: 57px; padding: 8px 14px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafcfd; }
.cell-title { max-width: 320px; color: #1e2a34; font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.cell-title a:hover { color: var(--primary); }
.cell-sub { margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 400; }
.cell-money { font-variant-numeric: tabular-nums; font-weight: 700; }
.align-right { text-align: right !important; }
.align-center { text-align: center !important; }
.muted { color: var(--muted); }
.text-danger { color: var(--red); }
.text-success { color: var(--teal); }
.text-amber { color: var(--amber); }

.badge { min-height: 25px; padding: 3px 8px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; color: #53616d; background: #eef1f4; border: 1px solid transparent; border-radius: 6px; font-size: 12px; font-weight: 650; }
.badge.blue { color: #1c61b7; background: var(--primary-soft); }
.badge.green { color: #116b5b; background: var(--teal-soft); }
.badge.amber { color: #8a570d; background: var(--amber-soft); }
.badge.red { color: #a22f36; background: var(--red-soft); }
.badge.purple { color: #68458f; background: var(--purple-soft); }
.badge.outline { color: #53616d; background: #fff; border-color: var(--line-strong); }
.priority-dot { width: 7px; height: 7px; border-radius: 50%; background: #8c98a3; }
.priority-dot.high { background: var(--amber); }
.priority-dot.urgent { background: var(--red); }

.progress { width: 100%; height: 7px; overflow: hidden; background: #edf1f4; border-radius: 4px; }
.progress-bar { height: 100%; background: var(--primary); border-radius: inherit; }
.progress-bar.green { background: var(--teal); }
.progress-bar.amber { background: var(--amber); }
.progress-label { margin-top: 6px; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab { min-height: 44px; padding: 0 15px; display: inline-flex; align-items: center; gap: 7px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 650; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab svg { width: 16px; height: 16px; }

.detail-grid { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 16px; }
.info-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 0; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.info-item { min-width: 0; min-height: 80px; padding: 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.info-item:nth-child(3n) { border-right: 0; }
.info-label { color: var(--muted); font-size: 12px; }
.info-value { margin-top: 7px; color: var(--text); font-weight: 650; line-height: 1.45; word-break: break-word; }
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: 8px; width: 1px; background: var(--line-strong); }
.timeline-item { position: relative; padding: 0 0 19px 8px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot { position: absolute; left: -19px; top: 5px; width: 9px; height: 9px; background: #fff; border: 2px solid var(--primary); border-radius: 50%; }
.timeline-title { font-weight: 650; line-height: 1.45; }
.timeline-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }
.timeline-content { margin-top: 7px; color: #52606b; line-height: 1.55; }

.form-section { margin-bottom: 18px; padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.form-section-title { margin: 0 0 16px; font-size: 15px; font-weight: 720; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
.form-grid.cols-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.form-group { min-width: 0; }
.form-group.full { grid-column: 1 / -1; }
.form-label { margin-bottom: 7px; display: block; color: #46545f; font-size: 12px; font-weight: 700; }
.required::after { content: " *"; color: var(--red); }
.form-hint { margin-top: 6px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.form-actions { position: sticky; bottom: 0; z-index: 10; padding: 12px 0; display: flex; justify-content: flex-end; gap: 9px; background: linear-gradient(to bottom, rgba(244,246,248,0), var(--bg) 28%); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 22px; display: none; align-items: center; justify-content: center; background: rgba(13,20,17,.48); }
.modal-backdrop.open { display: flex; }
.modal { width: min(620px,100%); max-height: calc(100vh - 44px); overflow-y: auto; background: #fff; border: 1px solid #d9dfe4; border-radius: 8px; box-shadow: 0 22px 70px rgba(13,20,17,.25); }
.modal.wide { width: min(780px,100%); }
.modal-head { min-height: 62px; padding: 14px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.modal-title { flex: 1; margin: 0; font-size: 17px; }
.modal-close { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; color: #64717c; background: transparent; border: 0; border-radius: 6px; }
.modal-close:hover { background: #f0f3f5; }
.modal-close svg { width: 18px; height: 18px; }
.modal-body { padding: 18px; }
.modal-actions { padding: 13px 18px; display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); background: #fafbfc; }

.flash { position: fixed; top: 78px; right: 24px; z-index: 120; min-width: 280px; max-width: 420px; padding: 13px 15px; display: flex; align-items: flex-start; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); animation: flash-in .22s ease; }
.flash.success { border-left: 4px solid var(--teal); }
.flash.error { border-left: 4px solid var(--red); }
.flash svg { width: 18px; height: 18px; margin-top: 1px; }
.flash.success svg { color: var(--teal); }
.flash.error svg { color: var(--red); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 48px; height: 48px; margin: 0 auto 13px; display: grid; place-items: center; color: #83909a; background: #eef2f4; border-radius: 50%; }
.empty-icon svg { width: 22px; height: 22px; }
.empty-title { color: #384650; font-weight: 700; }
.empty-text { margin-top: 6px; font-size: 12px; }
.list-stack { display: grid; gap: 0; }
.list-row { min-height: 64px; padding: 11px 0; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #edf0f2; }
.list-row:last-child { border-bottom: 0; }
.list-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; }
.list-icon svg { width: 17px; height: 17px; }
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 650; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-meta { margin-top: 4px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-value { color: #34424c; font-weight: 700; white-space: nowrap; }

.metric-strip { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.metric { min-width: 0; padding: 14px; background: #fff; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric-label { color: var(--muted); font-size: 11px; }
.metric-value { margin-top: 8px; font-size: 19px; font-weight: 730; }

.sidebar-overlay { display: none; }
.mobile-bottom-nav { display: none; }

@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .grid-3 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .info-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .info-item:nth-child(3n) { border-right: 1px solid var(--line); }
  .info-item:nth-child(2n) { border-right: 0; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 45; display: none; background: rgba(14,20,18,.42); }
  body.sidebar-open .sidebar-overlay { display: block; }
  .main-shell { margin-left: 0; }
  .icon-button.menu-toggle { display: inline-grid; }
  .topbar { padding: 0 18px; }
  .topbar-date { display: none; }
  .page { padding: 22px 18px 88px; }
  .grid-2, .grid-equal, .detail-grid { grid-template-columns: 1fr; }
  .form-grid.cols-3 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .mobile-bottom-nav { position: fixed; inset: auto 0 0; z-index: 40; height: 65px; padding: 5px 10px max(5px,env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(5,1fr); background: rgba(255,255,255,.97); border-top: 1px solid var(--line); backdrop-filter: blur(10px); }
  .mobile-nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #71808b; font-size: 10px; }
  .mobile-nav-item svg { width: 19px; height: 19px; }
  .mobile-nav-item.active { color: var(--primary); font-weight: 700; }
}

@media (max-width: 620px) {
  .topbar { height: 58px; padding: 0 12px; gap: 9px; }
  .global-search { flex: 1; width: auto; }
  .global-search input { height: 36px; }
  .topbar .icon-button:last-child { display: none; }
  .page { padding: 18px 12px 84px; }
  .page-head { margin-bottom: 17px; align-items: center; }
  .page-title { font-size: 21px; }
  .page-subtitle { font-size: 12px; }
  .page-actions .button:not(.primary) { display: none; }
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .stat-card { min-height: 116px; padding: 14px; }
  .stat-value { font-size: 21px; }
  .stat-foot { font-size: 11px; }
  .grid-3 { grid-template-columns: 1fr; }
  .panel-head { padding: 12px 13px; }
  .panel-body { padding: 13px; }
  .toolbar { padding: 9px; }
  .toolbar .select { min-width: 0; flex: 1; }
  .toolbar-search { min-width: 100%; }
  .data-table th, .data-table td { padding-left: 11px; padding-right: 11px; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .info-item, .info-item:nth-child(3n), .info-item:nth-child(2n) { border-right: 0; }
  .metric-strip { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; border-radius: 8px 8px 0 0; }
  .modal-body { padding: 15px; }
  .flash { top: 68px; right: 12px; left: 12px; min-width: 0; }
}
