:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6b7485;
  --line: #dfe5ee;
  --brand: #155bd5;
  --brand-2: #0e9f6e;
  --danger: #d92d20;
  --warn: #b7791f;
  --shadow: 0 16px 38px rgba(18, 32, 51, .10);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font: inherit; }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(21, 91, 213, .28);
  outline-offset: 2px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #eef5ff, #f8fbf7);
}
.login-card {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 30px;
}
.login-card h1 { margin: 0 0 10px; font-size: 24px; }
.login-card p { color: var(--muted); line-height: 1.7; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar {
  width: 238px;
  background: #101827;
  color: #d9e2f1;
  padding: 22px 16px;
}
.brand { color: #fff; font-weight: 700; font-size: 18px; margin-bottom: 22px; }
.nav { display: grid; gap: 6px; }
.nav a {
  padding: 10px 12px;
  border-radius: 6px;
  color: #cbd5e1;
}
.nav a.active, .nav a:hover { background: rgba(255,255,255,.09); color: #fff; }
.content { flex: 1; min-width: 0; }
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.main { padding: 26px; }
.page-title { margin: 0 0 18px; font-size: 24px; }

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: 1.1fr .9fr; align-items: start; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(18,32,51,.04);
}
.card.pad { padding: 18px; }
.stat-card {
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--brand);
}
.stat-card.danger-line::before { background: var(--danger); }
.stat-card.ok-line::before { background: var(--brand-2); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 8px; font-size: 28px; font-weight: 750; }
.stat-value.small { font-size: 20px; }
.stat-sub { margin-top: 6px; color: var(--muted); font-size: 13px; }

.toolbar {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.toolbar > div:first-child {
  min-width: 220px;
  flex: 0 0 auto;
}
.toolbar .page-title {
  margin-bottom: 6px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.86);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(18,32,51,.04);
  transition: background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 8px 18px rgba(21,91,213,.18); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: 0 8px 18px rgba(217,45,32,.14); }
.btn:hover {
  background: #fff;
  border-color: rgba(21,91,213,.34);
  box-shadow: 0 8px 18px rgba(18,32,51,.08);
  transform: translateY(-1px);
}
.btn.primary:hover { background: #0f4ec3; border-color: #0f4ec3; color: #fff; }
.btn.danger:hover { background: #c42419; border-color: #c42419; color: #fff; }
.btn:active { transform: translateY(0); box-shadow: 0 1px 2px rgba(18,32,51,.06); }
.btn.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}
.btn:disabled,
.btn[disabled],
button:disabled,
button[disabled],
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: .56;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 650; background: #f8fafc; }
.table tr:hover td { background: #fbfdff; }
.table tr:last-child td { border-bottom: 0; }
.card > .table,
.card > table.table {
  min-width: 760px;
}
.card {
  overflow-x: auto;
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field.full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.req { color: var(--danger); font-weight: 700; }
.field input, .field select, .field textarea,
.searchbar input[type="search"],
.bulkbar select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.searchbar input[type="search"]:focus,
.bulkbar select:focus {
  border-color: rgba(21,91,213,.55);
  box-shadow: 0 0 0 4px rgba(21,91,213,.10);
  background: #fff;
}
.field textarea { min-height: 92px; resize: vertical; }
.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.check-item input {
  width: auto;
  margin: 0;
}
.check-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
}
.check-inline input {
  width: auto;
  margin: 0;
}
.bulkbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.bulkbar select { width: min(460px, 100%); min-height: 40px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2f7;
  color: #475569;
  white-space: nowrap;
}
.badge.ok { background: #e8f7ef; color: #087443; }
.badge.warn { background: #fff6df; color: #8a5a00; }
.badge.danger { background: #d92d20; color: #fff; }
.badge.muted { background: #eef2f7; color: #475569; }
.danger { color: var(--danger); }
.ok { color: #087443; }
.strong { font-weight: 750; }
.alert { padding: 12px 14px; border-radius: 6px; margin: 14px 0; }
.alert.success { background: #e8f7ef; color: #087443; }
.alert.error { background: #ffebe9; color: #b42318; }
.muted { color: var(--muted); }
.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}
.actions form { margin: 0; flex: 0 0 auto; }
.actions > .btn,
.actions > a,
.actions > button,
.actions > form {
  flex: 0 0 auto;
}
.searchbar {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: nowrap;
  flex: 1 1 420px;
  min-width: 280px;
  max-width: 520px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.78);
  box-shadow: 0 1px 2px rgba(18,32,51,.04);
}
.searchbar input[type="search"] {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  min-height: 36px;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0 10px;
}
.searchbar input[type="search"]:focus {
  box-shadow: none;
  background: transparent;
}
.searchbar .btn,
.searchbar button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  box-shadow: none;
}
.searchbar .btn + .btn,
.searchbar button + .btn {
  margin-left: 4px;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 0;
  flex-wrap: wrap;
}
.filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255,255,255,.76);
  color: #445066;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.filter-chip:hover {
  background: #fff;
  border-color: rgba(21, 91, 213, .32);
  transform: translateY(-1px);
}
.filter-chip.active {
  background: #eaf1ff;
  border-color: rgba(21, 91, 213, .36);
  color: var(--brand);
  font-weight: 650;
}
.risk-stack {
  display: grid;
  gap: 6px;
  min-width: 132px;
}
.risk-line {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
}
.risk-line.ok { background: #e8f7ef; color: #087443; }
.risk-line.warn { background: #fff6df; color: #8a5a00; }
.risk-line.danger { background: #ffebe9; color: #b42318; }
.risk-line.muted { background: #eef2f7; color: #536176; }
.service-pick-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.service-pick-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 150px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.service-pick-item:hover {
  border-color: rgba(21, 91, 213, .28);
  box-shadow: 0 10px 20px rgba(18,32,51,.06);
  transform: translateY(-1px);
}
.service-pick-item input[type="checkbox"] {
  width: auto;
  margin: 0;
}
.service-pick-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.service-pick-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.service-pick-main small {
  color: var(--muted);
  line-height: 1.4;
}
.service-pick-money input {
  width: 100%;
  min-height: 34px;
}
.inline-form { display: inline-flex; margin: 0; }
.service-actions {
  display: grid;
  gap: 8px;
  min-width: 210px;
}
.service-actions-main,
.service-actions-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.guard-note {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #536176;
  font-size: 13px;
  white-space: nowrap;
}
.link-strong { color: var(--brand); font-weight: 700; }
.table-title { padding: 14px 14px 0; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.detail-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fafbfd;
}
.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.detail-grid strong { font-size: 14px; }
.progress {
  width: 138px;
  max-width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e8edf5;
  overflow: hidden;
  margin-bottom: 4px;
}
.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}

@media (max-width: 980px) {
  .app-shell { display: block; }
  .sidebar { width: 100%; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.stats, .grid.two, .form-grid { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .bulkbar { align-items: stretch; flex-direction: column; }
  .bulkbar select { width: 100%; }
  .main { padding: 16px; }
  .toolbar { align-items: stretch; flex-direction: column; overflow-x: visible; }
  .toolbar > div:first-child { min-width: 0; }
  .actions { justify-content: flex-start; gap: 8px; flex-wrap: wrap; overflow-x: visible; }
  .actions form { flex: 1 1 100%; }
  .searchbar {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px;
  }
  .searchbar input[type="search"] {
    width: 100%;
    flex: 1 0 100%;
    min-height: 40px;
    background: #fff;
    border: 1px solid var(--line);
  }
  .searchbar .btn,
  .searchbar button {
    flex: 1 1 auto;
  }
  .pagination { justify-content: flex-start; }
  .filterbar { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .filter-chip { flex: 0 0 auto; }
  .service-pick-item { grid-template-columns: auto minmax(0, 1fr); }
  .service-pick-money { grid-column: 2; width: 100%; }
  .btn { width: fit-content; max-width: 100%; }
}

@media print {
  .sidebar,
  .topbar,
  .toolbar .btn,
  .actions,
  .btn {
    display: none !important;
  }
  body {
    background: #fff;
    color: #111;
  }
  .app-shell,
  .content {
    display: block;
    min-height: auto;
  }
  .main {
    padding: 0;
  }
  .card {
    box-shadow: none;
    border-color: #ccc;
    break-inside: avoid;
    overflow: visible;
  }
  .card > .table,
  .card > table.table {
    min-width: 0;
  }
}
