:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --ink: #172033;
  --muted: #687386;
  --line: #e3e8ef;
  --line-strong: #d3dae4;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  --coral: #ef654d;
  --coral-soft: #fff0ed;
  --green: #168a62;
  --green-soft: #e9f7f1;
  --amber: #a96608;
  --amber-soft: #fff5dc;
  --danger: #c93d36;
  --danger-soft: #fff0ef;
  --shadow: 0 18px 48px rgba(22, 32, 51, 0.1);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 42%) minmax(420px, 58%);
  background: var(--surface);
}

.login-brand {
  min-height: 100vh;
  display: flex;
  align-items: flex-end;
  gap: 18px;
  padding: 64px;
  color: #fff;
  background: #182033;
  position: relative;
  overflow: hidden;
}

.login-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image: linear-gradient(rgba(255,255,255,.12) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.12) 1px, transparent 1px);
  background-size: 56px 56px;
}

.login-brand::after {
  content: "";
  position: absolute;
  width: 360px;
  height: 360px;
  right: -100px;
  top: -80px;
  border: 64px solid rgba(239, 101, 77, 0.72);
  border-radius: 50%;
}

.login-brand img { width: 76px; height: 76px; object-fit: contain; position: relative; z-index: 1; }
.login-brand div { position: relative; z-index: 1; display: grid; gap: 4px; }
.login-brand strong { font-size: 34px; line-height: 1; }
.login-brand span { color: #bfc8d8; }

.login-panel { width: min(420px, calc(100% - 48px)); margin: auto; display: grid; gap: 22px; }
.login-heading p, dialog header p { margin: 0 0 7px; color: var(--coral); font-size: 12px; font-weight: 800; }
.login-heading h1 { margin: 0 0 14px; font-size: 34px; font-weight: 750; }
label { display: grid; gap: 8px; color: #354052; font-weight: 650; }
label small { color: var(--muted); font-weight: 400; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  min-height: 42px;
  padding: 9px 12px;
  outline: none;
}
textarea { resize: vertical; min-height: 82px; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.form-error { min-height: 20px; margin: -6px 0 -4px; color: var(--danger); }

.button, .icon-button, .text-button {
  border: 0;
  border-radius: 6px;
  min-height: 38px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 700;
}
.button.primary { background: var(--blue); color: #fff; }
.button.primary:hover { background: #1d55cf; }
.button.ghost { color: #445066; background: var(--surface); border: 1px solid var(--line-strong); }
.button.danger { color: var(--danger); background: var(--danger-soft); border: 1px solid #f2c6c2; }
.button.small { min-height: 30px; padding: 0 9px; font-size: 12px; }
.login-submit { min-height: 46px; }
.icon-button { width: 38px; min-width: 38px; padding: 0; font-size: 20px; color: #445066; background: var(--surface); border: 1px solid var(--line); }
.text-button { min-height: 32px; padding: 0; color: var(--blue); background: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #172033;
  color: #fff;
  border-right: 1px solid #242f46;
}
.sidebar-brand { min-height: 84px; display: flex; align-items: center; gap: 11px; padding: 18px 22px; border-bottom: 1px solid #2a354d; }
.sidebar-brand img { width: 42px; height: 42px; object-fit: contain; }
.sidebar-brand div { display: grid; gap: 2px; }
.sidebar-brand strong { font-size: 18px; }
.sidebar-brand span { color: #aeb8c9; font-size: 12px; }
.sidebar nav { display: grid; gap: 4px; padding: 18px 12px; }
.nav-item { min-height: 45px; display: flex; align-items: center; gap: 12px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: #bdc6d5; text-align: left; font-weight: 650; }
.nav-item:hover { background: #212c42; color: #fff; }
.nav-item.active { color: #fff; background: #293650; box-shadow: inset 3px 0 var(--coral); }
.nav-mark { color: #7f8ca2; font-size: 10px; font-variant-numeric: tabular-nums; }
.nav-item.active .nav-mark { color: #ff9b89; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-top: 1px solid #2a354d; }
.sidebar-footer div { display: grid; gap: 2px; }
.sidebar-footer strong { font-size: 12px; }
.sidebar-footer span { color: #9eabc0; font-size: 11px; }
.system-dot { width: 9px; height: 9px; border-radius: 50%; background: #31c48d; box-shadow: 0 0 0 4px rgba(49,196,141,.13); }

.workspace { min-width: 0; }
.topbar { height: 84px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1 { margin: 2px 0 0; font-size: 22px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 10px; font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.account-block { display: flex; align-items: center; gap: 9px; padding: 0 4px; }
.account-block > span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--coral-soft); color: var(--coral); font-weight: 800; }
.account-block div { display: grid; gap: 1px; }
.account-block small { color: var(--muted); }

.view { display: none; padding: 24px 28px 36px; }
.view.active { display: block; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--surface); border-radius: 8px; overflow: hidden; }
.metric { min-height: 120px; padding: 22px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: grid; align-content: space-between; }
.metric:nth-child(4n) { border-right: 0; }
.metric:nth-last-child(-n+4) { border-bottom: 0; }
.metric span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric strong { font-size: 29px; font-variant-numeric: tabular-nums; }
.metric em { font-style: normal; font-size: 11px; color: var(--green); }
.metric.coral strong { color: var(--coral); }
.metric.blue strong { color: var(--blue); }
.metric.amber strong { color: var(--amber); }

.section-block { margin-top: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.section-heading { min-height: 70px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 0 0 3px; font-size: 16px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 12px; }

.toolbar { min-height: 62px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.filters { display: flex; align-items: center; gap: 9px; min-width: 0; }
.filters input, .filters select { min-height: 38px; background: var(--surface); }
.search-input { width: min(320px, 32vw); }
.filters select { width: 132px; }
.table-wrap { width: 100%; overflow: auto; background: var(--surface); }
.data-table { border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 900px; table-layout: auto; }
th { height: 42px; padding: 0 14px; color: #687386; background: #f7f9fc; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-size: 11px; font-weight: 800; }
td { min-height: 54px; padding: 12px 14px; border-bottom: 1px solid #edf0f4; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfcfe; }
.actions-col { text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; white-space: nowrap; }
.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.cell-stack { display: grid; gap: 4px; min-width: 120px; }
.cell-stack small { color: var(--muted); }
.truncate { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.blue { color: var(--blue); background: var(--blue-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.red { color: var(--danger); background: var(--danger-soft); }
.badge.gray { color: #647084; background: #eef1f5; }
.empty-state { height: 180px; color: var(--muted); text-align: center; }
.pagination { min-height: 54px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; color: var(--muted); }
.pagination button { min-width: 34px; min-height: 32px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); }
.pagination button:disabled { cursor: not-allowed; opacity: .45; }

dialog { width: min(620px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 8px; box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(19, 27, 42, .55); backdrop-filter: blur(2px); }
.dialog-panel { display: grid; }
.dialog-panel header { min-height: 72px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-panel h2 { margin: 0; font-size: 19px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 20px; }
.form-grid .wide { grid-column: 1 / -1; }
.dialog-panel footer { min-height: 66px; padding: 13px 18px; display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); background: var(--surface-subtle); }
.feedback-content { margin: 20px 20px 0; padding: 14px; background: var(--surface-subtle); border-left: 3px solid var(--coral); white-space: pre-wrap; line-height: 1.65; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: min(420px, calc(100vw - 48px)); padding: 12px 16px; border-radius: 6px; background: #172033; color: #fff; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; z-index: 20; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 190px minmax(0, 1fr); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-last-child(-n+4) { border-bottom: 1px solid var(--line); }
  .metric:nth-last-child(-n+2) { border-bottom: 0; }
  .account-block div { display: none; }
}

@media (max-width: 720px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 180px; align-items: center; padding: 32px 24px; }
  .login-brand::after { width: 220px; height: 220px; border-width: 42px; }
  .login-panel { margin: 44px auto; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; }
  .sidebar-brand { min-height: 66px; }
  .sidebar nav { display: flex; overflow-x: auto; padding: 8px 10px; }
  .nav-item { flex: 0 0 auto; min-height: 38px; }
  .sidebar-footer { display: none; }
  .topbar { height: auto; min-height: 76px; padding: 13px 16px; }
  .topbar-actions { gap: 7px; }
  .view { padding: 16px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 102px; padding: 16px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .filters { align-items: stretch; flex-direction: column; }
  .search-input, .filters select { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
}
