:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --brand: #1d4ed8;
  --brand-dark: #1e3a8a;
  --brand-soft: #e8eefc;
  --ink: #14181f;
  --muted: #667085;
  --line: #e7eaf0;
  --line-strong: #d0d5dd;
  --bg: #f3f5f8;
  --card: #ffffff;
  --edit: #f6f7f6;
  --ok: #e8f6ee;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(18, 28, 24, .04);
  --control: 32px;
  --row: 47px;
  --radius: 6px;
  --radius-lg: 8px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23667085' stroke-width='1.5' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
  --side: 216px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 14px/1.5 "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
.app { display: flex; min-height: 100vh; }
.side {
  width: var(--side);
  flex: 0 0 var(--side);
  background: #0c1222;
  color: rgba(255,255,255,.65);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 0 0 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: white;
  text-decoration: none;
  height: 56px;
  padding: 0 16px;
  margin: 0 0 8px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-weight: 650;
  letter-spacing: .01em;
}
.brand:hover { text-decoration: none; }
.mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--brand);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a {
  height: 40px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  border-radius: var(--radius);
  color: rgba(255,255,255,.65);
  text-decoration: none;
  margin: 0 8px;
}
.side nav a:hover { background: rgba(255,255,255,.08); color: white; text-decoration: none; }
.side nav a.on { background: rgba(255,255,255,.08); color: white; box-shadow: inset 3px 0 0 #8eafff; }
.side-foot { margin-top: auto; padding: 12px; }
.lang {
  display: flex;
  background: rgba(255,255,255,.06);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}
.lang button {
  flex: 1;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255,255,255,.65);
  cursor: pointer;
}
.lang button.on { background: white; color: var(--ink); }
.main { flex: 1; min-width: 0; }
.top {
  height: 56px;
  box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
.crumb { font-size: 16px; font-weight: 650; letter-spacing: 0; line-height: 1.4; }
.content {
  padding: var(--space-5) var(--space-6) var(--space-8);
}
.content > * + * { margin-top: var(--space-4); }
.msg, .error {
  border-radius: var(--radius);
  padding: 10px 14px;
  line-height: 1.45;
}
.msg { background: var(--ok); border: 1px solid #c6e6d2; color: #146c43; }
.error { background: #fdecea; border: 1px solid #f5c2c0; color: var(--danger); }
.cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-3);
}
.card, .panel, .table-wrap, .sheet {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: none;
}
.sheet { overflow: hidden; }
.sheet-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}
.sheet-head .toolbar { flex: 1 1 auto; margin: 0; }
.bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  padding: 12px 16px;
}
.sheet-head h2, .sheet-title {
  margin: 0;
  font-size: 14px;
  line-height: 36px;
  font-weight: 650;
}
.sheet > .table-wrap, .sheet form > .table-wrap {
  border: 0;
  border-radius: 0;
  max-height: calc(100vh - 210px);
}
.sheet > form > .actions, .sheet > .actions {
  margin: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.sheet.form { padding: 16px; }
tr.composer td { background: #f8fafc; }
tr.composer input, tr.composer select { width: 100%; }
.metrics .cards { gap: 0; }
.metrics .card {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  border-right: 1px solid var(--line);
}
.metrics .card:last-child { border-right: 0; }
.card { padding: 14px 16px 12px; }
.card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card b {
  display: block;
  margin-top: 6px;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.card b.name { font-size: 18px; letter-spacing: 0; }
.panel { padding: var(--space-4); }
.panel > * + * { margin-top: var(--space-4); }
.panel h2, .block-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 650;
}
.toolbar, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
}
.actions { margin-top: 0; }
.table-wrap + .actions, .form-grid + .actions { margin-top: var(--space-4); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4) var(--space-4);
  align-items: start;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}
.field.grow { flex: 1 1 220px; }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: 1 / -1; }
.field input, .field select, .toolbar input, .toolbar select { width: 100%; }
input, select {
  height: var(--control);
  border: 1px solid var(--line-strong);
  background-color: white;
  border-radius: var(--radius);
  padding: 0 12px;
  min-width: 0;
}
select {
  appearance: none;
  padding-right: 28px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 8px center;
}
input:focus, select:focus { outline: 2px solid rgba(29,78,216,.16); border-color: var(--brand); }
button, .btn {
  height: var(--control);
  border: 0;
  border-radius: var(--radius);
  padding: 0 14px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 600;
}
button:hover, .btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.light, button.light { background: white; color: var(--ink); border: 1px solid var(--line-strong); font-weight: 500; }
.btn.light:hover, button.light:hover { background: #f7f8fb; border-color: #b8c0cc; }
button.danger { background: white; color: #ff4d4f; border: 1px solid #ffccc7; }
button.danger:hover { background: #fff2f0; }
button.link, a.link {
  height: 28px;
  padding: 0 4px;
  background: transparent;
  color: var(--brand);
  border: 0;
  font-size: 14px;
}
button.link:hover, a.link:hover { background: transparent; color: var(--brand-dark); }
button.link.danger, a.link.danger { color: #ff4d4f; }
button.link.danger:hover { color: #ff7875; background: transparent; }
.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  color: rgba(0,0,0,.65);
  border: 0;
}
.icon-btn:hover { background: rgba(0,0,0,.04); color: var(--brand); }
.account { display: flex; align-items: center; gap: 2px; }
.who { font-weight: 650; color: var(--ink); padding: 0 10px; }
button.text {
  background: transparent;
  color: var(--muted);
  border: 0;
  height: 32px;
  padding: 0 10px;
  font-weight: 500;
}
button.text:hover { background: #eef1f6; color: var(--ink); }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ops { display: flex; align-items: center; gap: 2px; }
.pro { background: white; border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.pro-search {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 24px;
  padding: 20px 24px 0;
}
.pro-search-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-bottom: 16px;
}
.pro-toolbar, .pro-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 24px;
}
.pro-search + .pro-toolbar { border-top: 1px solid var(--line); }
.pro-toolbar h2 { margin: 0; font-size: 16px; font-weight: 600; line-height: 32px; }
.pro-actions, .pro-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pro > .table-wrap, .pro form > .table-wrap { border: 0; border-radius: 0; max-height: calc(100vh - 280px); }
.pro-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.stat {
  position: relative;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 22px 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); }
.stat span { color: var(--muted); font-size: 13px; display: block; }
.stat b { display: block; margin-top: 8px; font-size: 28px; line-height: 1.15; font-weight: 650; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat b.name { font-size: 18px; }
dialog .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 20px -16px -16px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.btn.sm, button.sm { height: 30px; padding: 0 10px; font-size: 13px; }
td .btn, td button { vertical-align: middle; }
.table-wrap { overflow: auto; max-height: calc(100vh - 188px); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; line-height: 1.4; }
th, td {
  height: var(--row);
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  height: 44px;
  background: #f4f6f9;
  font-size: 13px;
  font-weight: 650;
  color: #5c6570;
  letter-spacing: .01em;
  z-index: 3;
  box-shadow: inset 0 -1px 0 var(--line);
}
tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) td { background: #f7f8fb; }
tbody tr:hover td { background: #eef3fb; }
tbody tr.group-head td, tbody tr.group-head:hover td { background: var(--brand-soft); }
.group-head td {
  height: 36px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 650;
  letter-spacing: .01em;
}
table input, table select, td.tap input, td.tap select {
  width: 100%;
  height: var(--control);
  border-radius: var(--radius);
}
td select, select.quick-group { min-width: 128px; }
.money, .days {
  width: 100%;
  min-width: 96px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.num, td.calc { font-variant-numeric: tabular-nums; text-align: right; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.4; }
.nick { font-weight: 650; }
.sub { color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.4; }
form.inline { display: inline; }
.account-line { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: var(--bg);
}
.login {
  width: min(400px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
}
.login h1 { margin: 12px 0 4px; font-size: 24px; line-height: 1.3; letter-spacing: -.02em; }
.login .field { margin-top: var(--space-3); }
.login .lang { background: var(--bg); }
.login .lang button { color: var(--muted); }
.login .lang button.on { background: white; color: var(--ink); }
.login button[type=submit] { width: 100%; margin-top: var(--space-4); }
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  line-height: 1;
}
.tag.off { background: #eef0f0; color: var(--muted); }
.tag.warn { background: #fff7e6; color: #d48806; }
.tag.bad { background: #fff1f0; color: #cf1322; }
.ico { width: 18px; height: 18px; }
td.tap { cursor: pointer; }
td.tap:hover { background: #f0f7ff; }
td.flash, tr.flash td { animation: cellflash .7s ease; }
@keyframes cellflash { from { background: #e4edf8; } }
.sheet-pad .toolbar { padding: 12px 16px 0; }
.sheet-pad .actions { padding: 12px 16px; }
#dlg, #ask {
  border: 0;
  padding: 0;
  color: var(--ink);
  background: white;
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(14, 22, 38, .28);
}
#dlg { width: min(560px, calc(100vw - 48px)); max-height: min(88vh, 920px); }
#dlg.sm { width: min(420px, calc(100vw - 48px)); }
#dlg.lg { width: min(720px, calc(100vw - 48px)); }
#dlg::backdrop, #ask::backdrop { background: rgba(14, 22, 38, .46); }
.dlg-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}
.dlg-bar h2 { margin: 0; font-size: 16px; line-height: 1.4; }
#dlg-body { padding: 16px; overflow: auto; max-height: calc(88vh - 64px); }
#dlg-error { margin: 0 16px 0; }
#dlg-error[hidden] { display: none; }
#ask { width: min(420px, calc(100vw - 32px)); padding: 20px; }
#ask p { margin: 0 0 16px; font-size: 15px; }
dialog .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
dialog .span-4 { grid-column: 1 / -1; }
dialog .table-wrap { max-height: 52vh; border: 0; box-shadow: none; }
#toasts {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.bubble {
  pointer-events: none;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
  padding: 10px 16px;
  font-size: 14px;
  animation: bubble-in .2s ease;
}
.bubble.err { color: #cf1322; }
.bubble.out { animation: bubble-out .2s ease forwards; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(-6px); } }
@keyframes bubble-out { to { opacity: 0; transform: translateY(-6px); } }
#pop {
  position: fixed;
  z-index: 70;
  min-width: 148px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
  padding: 4px;
}
#pop[hidden] { display: none; }
#pop .opt {
  display: block;
  width: 100%;
  height: var(--control);
  margin: 0;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 400;
}
#pop .opt:hover, #pop .opt.on { background: var(--brand-soft); color: var(--brand); }
#pop input { width: 100%; }
button.pill {
  height: var(--control);
  min-width: 96px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background-color: #fff;
  color: var(--ink);
  font-weight: 400;
  justify-content: flex-start;
}
button.pill[data-pop="status"] {
  min-width: 128px;
  padding-right: 28px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 8px center;
}
button.pill:hover { border-color: var(--brand); background-color: #fff; }
button.pill.quiet { color: var(--muted); }
button.pill.info { color: var(--brand); background-color: var(--brand-soft); }
button.pill.warn { color: #d48806; background-color: #fff7e6; }
button.pill.bad { color: #cf1322; background-color: #fff1f0; }
.table-wrap thead th:first-child { z-index: 4; background: #f4f6f9; }
@media (max-width: 1200px) {
  .form-grid, .pro-search { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-4 { grid-column: 1 / -1; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1023px) and (min-width: 768px) {
  :root { --side: 84px; }
  .brand { justify-content: center; padding: 0; }
  .brand-name, .side nav a span { display: none; }
  .side nav a { justify-content: center; padding: 0; }
  .lang { flex-direction: column; }
  .lang button { padding: 0 4px; }
  th, td { padding: 0 10px; }
  .table-wrap tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #fff;
    box-shadow: 1px 0 0 var(--line);
  }
  .table-wrap thead th:first-child { position: sticky; left: 0; z-index: 5; background: #f4f6f9; }
  .table-wrap tbody tr:nth-child(even) td:first-child { background: #f7f8fb; }
  .table-wrap tbody tr:hover td:first-child { background: #eef3fb; }
  .group-head td { position: static; box-shadow: none; }
}
@media (max-width: 767px) {
  :root { --control: 42px; --row: 48px; }
  .cards, .stat-grid, .pro-search, .form-grid, dialog .form-grid { grid-template-columns: 1fr; }
  .metrics .card { border-right: 0; border-bottom: 1px solid var(--line); }
  .metrics .card:nth-child(odd) { border-right: 1px solid var(--line); }
  .metrics .card:last-child { border-bottom: 0; border-right: 0; }
  .app { display: block; }
  .side {
    width: auto;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 8px 10px;
  }
  .brand { height: 40px; margin-bottom: 8px; justify-content: flex-start; }
  .brand-name, .side nav a span { display: inline; }
  .side nav { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .side nav a { flex: 0 0 auto; justify-content: flex-start; white-space: nowrap; padding: 0 10px; gap: 8px; }
  .side-foot { margin-top: 8px; padding-top: 8px; }
  .lang { flex-direction: row; }
  .content, .top { padding-left: 12px; padding-right: 12px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .page-head { align-items: stretch; }
  .page-actions .btn, .page-actions button { flex: 1 1 auto; }
  .pro-search, .form-grid, dialog .form-grid { grid-template-columns: 1fr; }
  .pro > .table-wrap, .pro form > .table-wrap { max-height: none; }
  .span-2, .span-4, dialog .span-4 { grid-column: auto; }
  .toolbar .field, .toolbar .field.grow { flex: 1 1 100%; }
  .top { height: auto; min-height: 52px; padding-top: 10px; padding-bottom: 10px; }
  table input, table select, button.pill { height: var(--control); }
  th, td { padding: 0 10px; }
  .table-wrap, .sheet > .table-wrap, .sheet form > .table-wrap { max-height: none; }
  .table-wrap tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #fff;
    box-shadow: 1px 0 0 var(--line);
  }
  .table-wrap thead th:first-child { position: sticky; left: 0; z-index: 5; background: #f4f6f9; }
  .table-wrap tbody tr:nth-child(even) td:first-child { background: #f7f8fb; }
  .table-wrap tbody tr:hover td:first-child { background: #eef3fb; }
  .group-head td { position: static; box-shadow: none; }
  #dlg, #dlg.sm, #dlg.lg {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
  }
  #dlg-body { max-height: calc(100dvh - 58px); }
  #ask { width: calc(100vw - 24px); }
}
