:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --text: #1d2b3a;
  --muted: #64748b;
  --border: #e3e9f0;
  --border-strong: #cdd8e6;
  --accent: #1763da;
  --accent-hover: #1054c0;
  --accent-soft: #edf4ff;
  --success: #16755e;
  --success-soft: #e8f6ef;
  --warn: #9a5412;
  --warn-soft: #fff4e2;
  --warn-border: #f5d8a8;
  --danger: #bd3345;
  --danger-soft: #fff2f4;
  --danger-border: #f4ccd2;
  --radius: 14px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 25px; line-height: 1.35; letter-spacing: -.4px; font-weight: 700; }
h2 { font-size: 17px; line-height: 1.45; font-weight: 650; }
h3 { font-size: 15px; line-height: 1.45; font-weight: 650; }
small { font-size: 12px; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

input:not([type="checkbox"]),
textarea,
select {
  width: 100%;
  border: 1px solid #d7e0eb;
  background: #fff;
  border-radius: 9px;
  padding: 9px 12px;
  min-height: 40px;
  color: var(--text);
}
textarea { resize: vertical; min-height: 82px; }
input:disabled { background: var(--surface-subtle); color: var(--muted); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #1763da1f;
}

.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* Buttons & Chips */
.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 38px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.button:hover { background: #f3f6fb; border-color: var(--border-strong); text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.button.danger:hover { background: #ffe4e8; }
.button.quiet { background: transparent; border-color: transparent; padding: 6px 10px; }
.button.quiet:hover { background: #eef2f7; }
.button.sm { min-height: 30px; padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.button.large { min-height: 50px; padding: 12px 22px; font-size: 16px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: #bfd6fb; color: var(--accent); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: #2157a8;
  font-weight: 600;
  white-space: nowrap;
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: #eef2f6; color: #526277; }

/* Brand & Public Login */
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}
.brand small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 450;
  margin-top: 2px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-radius: 11px;
  color: #fff;
  font-size: 18px;
  font-weight: 750;
  box-shadow: 0 4px 10px #1763da24;
  flex: none;
}

.loading-box {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
}
.public-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: radial-gradient(ellipse at 80% 0, #e7f0ff, transparent 55%), var(--bg);
  padding: 36px 24px;
}
.public-page > header { width: min(1080px, 100%); }
.public-page footer { color: var(--muted); font-size: 12px; margin-top: auto; padding-top: 30px; text-align: center; }
.login-card {
  width: min(500px, 100%);
  margin: 72px auto 48px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  padding: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 14px 48px #28518d0d;
}
.login-card h1 { font-size: 26px; line-height: 1.45; }
.login-card .large { width: 100%; }
.login-note { font-size: 12px; color: var(--muted); width: 100%; text-align: center; }

/* App Shell */
.shell { display: flex; min-height: 100dvh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  display: flex;
  flex-direction: column;
  padding: 26px 16px 20px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 20;
}
.sidebar .brand { padding: 0 8px 26px; }
.sidebar nav { display: flex; flex-direction: column; gap: 6px; }
.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  color: #4f6075;
  font-weight: 550;
  border-radius: 10px;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-link:hover { background: #f3f6fa; color: var(--text); }
.nav-link.selected { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.sidebar-foot {
  margin-top: auto;
  padding: 18px 10px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.status-line { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #22a07a; flex: none; }

.workspace { margin-left: 244px; width: calc(100% - 244px); min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 32px;
  min-height: 76px;
  border-bottom: 1px solid var(--border);
  background: #ffffffee;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}
.avatar {
  width: 36px;
  height: 36px;
  background: #e6effe;
  border: 1px solid #d5e3f8;
  color: var(--accent);
  font-weight: 700;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.content {
  padding: 28px 32px 56px;
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.page-heading p { margin-top: 4px; color: var(--muted); }

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color .15s, box-shadow .15s;
}
.kpi-card:hover { border-color: #bfd6fb; box-shadow: 0 6px 18px #1763da0c; }
.kpi-card.active { border-color: var(--accent); background: #f8fbff; box-shadow: 0 0 0 2px #1763da1a; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 550; }
.kpi-value { font-size: 28px; font-weight: 750; line-height: 1.25; color: var(--text); }
.kpi-card.ok .kpi-value { color: var(--success); }
.kpi-card.warn .kpi-value { color: var(--warn); }
.kpi-card.danger .kpi-value { color: var(--danger); }
.kpi-sub { font-size: 12px; color: var(--muted); }

/* Panels & Filter Bar */
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  box-shadow: 0 2px 6px #10213a05;
}
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.search-box { flex: 1; min-width: 240px; max-width: 380px; }

/* Project Header inside Panel */
.project-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px solid #edf2f7;
}
.project-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.project-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; max-width: 100%; }
@media (min-width: 1081px) {
  .table-wrap { overflow: visible; }
}
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-subtle);
  padding: 10px 12px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 13px 12px;
  border-bottom: 1px solid #eef2f7;
  vertical-align: top;
  overflow-wrap: anywhere;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcff; }
.cell-title { font-weight: 650; font-size: 14px; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.link-list { display: flex; flex-direction: column; gap: 4px; }
.cmd-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f3f6fa;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 8px;
  max-width: 340px;
}
.cmd-chip code {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #334155;
}
.tip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.tip-btn {
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  border-radius: 50%;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.tip-btn:hover,
.tip-wrap.open .tip-btn {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.tip-pop {
  display: none;
  position: absolute;
  left: calc(100% + 8px);
  top: -4px;
  min-width: 240px;
  max-width: 340px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 12px;
  font-weight: 450;
  line-height: 1.55;
  box-shadow: 0 10px 28px #0f172a33;
  z-index: 50;
  white-space: normal;
  word-break: break-word;
}
.tip-wrap:hover .tip-pop,
.tip-wrap:focus-within .tip-pop,
.tip-wrap.open .tip-pop {
  display: block;
}

/* Notices & Redline */
.notice {
  padding: 13px 16px;
  border: 1px solid #d6e5fb;
  border-radius: 10px;
  background: #f1f6fe;
  color: #2f517c;
  font-size: 13px;
}
.notice.warn {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: #7c430d;
}

/* Entities & Bank Payout Cards */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.entity-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.entity-card:hover { border-color: #bfd6fb; box-shadow: 0 6px 18px #1a33500d; }
.entity-card.selected { border-color: var(--accent); background: #f8fbff; box-shadow: 0 0 0 2px #1763da1f; }

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.kv-item {
  border: 1px solid #e9eef5;
  background: var(--surface-subtle);
  border-radius: 10px;
  padding: 11px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.kv-label { font-size: 12px; color: var(--muted); }
.kv-val { font-size: 14px; font-weight: 600; word-break: break-word; margin-top: 2px; }

.payout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}
.payout-card {
  border: 1px solid #d5e2f4;
  background: linear-gradient(160deg, #ffffff 0%, #f7faff 100%);
  border-radius: 13px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.payout-num {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 9px;
  background: #edf4ff;
  border: 1px solid #c9ddf9;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  font-weight: 650;
  color: #164894;
}

/* Native Top-Layer Drawer & Modal */
.modal, .drawer {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  width: min(620px, calc(100vw - 28px));
  max-height: 92dvh;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 20px 90px #12274435;
  overflow: auto;
}
.modal::backdrop, .drawer::backdrop {
  background: #10213966;
  backdrop-filter: blur(3px);
}
.drawer {
  margin: 0 0 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  width: min(760px, 100vw);
  border-radius: 16px 0 0 16px;
  padding: 28px;
}
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  min-width: 0;
}
.field.full { grid-column: 1 / -1; }
.field small { font-weight: 400; color: var(--muted); }
.payout-editor-card {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.advanced-box {
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fbfcfe;
}
.advanced-box summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 36px 20px;
  color: var(--muted);
}
.division-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.division-card {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cmd-block {
  border: 1px solid var(--border);
  background: #f8fafd;
  border-radius: 11px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cmd-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cmd-block pre {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eef3fa;
  border: 1px solid #dbe6f5;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #1e334d;
  white-space: pre-wrap;
  word-break: break-all;
}
.menu-toggle { display: none !important; }

#toasts {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  border: 1px solid #b7dfd0;
  border-radius: 10px;
  background: #f1fbf6;
  color: #16654e;
  box-shadow: 0 6px 24px #1d3b5524;
  font-size: 14px;
}
.toast.error { background: #fff4f5; border-color: #ecc6cc; color: #a3293b; }

@media (max-width: 1120px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); box-shadow: 10px 0 36px #10213922; }
  .sidebar.open { transform: none; top: 76px; }
  .workspace { margin-left: 0; width: 100%; }
  .topbar { padding: 12px 16px; }
  .menu-toggle { display: inline-flex !important; }
  .content { padding: 20px 14px 48px; }
  .kpi-grid, .kv-grid, .form-grid, .payout-grid, .division-grid { grid-template-columns: 1fr; }
  .drawer { border-radius: 0; padding: 20px 16px; }
}
