:root {
  --bg: #f4f7fc;
  --panel: #ffffff;
  --panel-soft: #f6f9ff;
  --ink: #1f2937;
  --muted: #6b7b90;
  --primary: #1677ff;
  --primary-strong: #1258d5;
  --line: #e5ebf5;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --sidebar-grad: linear-gradient(175deg, #0a2133, #0a3246 65%, #104a66);
  --sidebar-link: #b8d9ea;
  --sidebar-active: rgba(255, 255, 255, 0.12);
  --topbar-bg: linear-gradient(180deg, #ffffff, #f8fbff);
  --topbar-border: #e4ebf5;
  --topbar-title: #1d2838;
  --topbar-muted: #6f8097;
}

html.dark {
  --bg: #0e1724;
  --panel: #152233;
  --panel-soft: #1a2b40;
  --ink: #dde9f5;
  --muted: #9eb4c9;
  --line: #2b4058;
  --primary: #3cb9ff;
  --primary-strong: #0d89d2;
  --ok: #43c98f;
  --warn: #ffb84d;
  --danger: #ff6b6b;
  --sidebar-grad: linear-gradient(175deg, #08111c, #0a1b2a 65%, #0f2b40);
  --sidebar-link: #a9c4da;
  --sidebar-active: rgba(255, 255, 255, 0.16);
  --topbar-bg: linear-gradient(90deg, rgba(14, 40, 71, 0.92), rgba(20, 69, 83, 0.92));
  --topbar-border: rgba(142, 174, 205, 0.2);
  --topbar-title: #eef7ff;
  --topbar-muted: rgba(224, 237, 248, 0.75);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: radial-gradient(circle at 8% 0%, color-mix(in srgb, var(--primary) 10%, transparent), transparent 46%),
    radial-gradient(circle at 92% 0%, color-mix(in srgb, #4da3ff 9%, transparent), transparent 44%),
    var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  background: var(--bg);
}

.sidebar {
  background: var(--sidebar-grad);
  color: #e7f2fa;
  border-right: 1px solid rgba(142, 174, 205, 0.16);
  padding: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  align-self: start;
}

.sidebar-brand {
  height: 60px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(142, 174, 205, 0.14);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #dff7ff;
  background: linear-gradient(135deg, #1847d9, #08b1cc);
}

.logo {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.sidebar-menu {
  flex: 1;
  overflow: auto;
  min-height: 0;
  padding: 14px 10px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  margin-bottom: 7px;
  color: #b7cbe2;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
}

.nav-link:hover,
.nav-link.active {
  color: #e8f6ff;
}

.nav-link.active {
  background: linear-gradient(90deg, rgba(35, 192, 201, 0.24), rgba(30, 97, 184, 0.14));
  border-color: rgba(35, 192, 201, 0.22);
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
}

.nav-icon {
  width: 17px;
  height: 16px;
  display: inline-flex;
  flex-shrink: 0;
  opacity: 0.92;
}

.nav-icon svg {
  width: 17px;
  height: 16px;
}

.sidebar-foot {
  padding: 12px 10px 14px;
  border-top: 1px solid rgba(142, 174, 205, 0.14);
  display: grid;
  gap: 6px;
}

.side-tool {
  border: 1px solid rgba(142, 174, 205, 0.24);
  background: rgba(11, 36, 64, 0.7);
  color: #bfd4e8;
  border-radius: 10px;
  height: 36px;
  padding: 0 10px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.side-tool:hover {
  border-color: rgba(35, 192, 201, 0.36);
  color: #e6f8ff;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 78px minmax(0, 1fr);
}

.app-shell.sidebar-collapsed .logo,
.app-shell.sidebar-collapsed .nav-link span:last-child,
.app-shell.sidebar-collapsed .side-tool {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0;
}

.app-shell.sidebar-collapsed .nav-link {
  justify-content: center;
  padding: 11px 0;
}

.app-shell.sidebar-collapsed #sidebar-toggle {
  display: block;
  text-align: center;
}

.main {
  padding: 0;
  min-width: 0;
  min-height: 100vh;
}

.main-body {
  padding: 12px 14px 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 58px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--topbar-border);
  background: var(--topbar-bg);
}

.title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.topbar .title {
  color: var(--topbar-title);
}

.topbar .muted {
  color: var(--topbar-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions form {
  margin: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 20px rgba(16, 39, 71, 0.06);
}

html.dark .panel {
  box-shadow: 0 10px 22px rgba(5, 20, 41, 0.24);
}

h3 {
  font-size: 16px;
  font-weight: 700;
}

h4 {
  font-size: 14px;
  font-weight: 600;
}

.panel + .panel {
  margin-top: 14px;
}

.grid {
  display: grid;
  gap: 14px;
}

/* In grid layout, sibling panel top margin causes row misalignment. */
.grid > .panel,
.grid > .panel + .panel {
  margin-top: 0;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi {
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 12%, var(--panel)), color-mix(in srgb, var(--ok) 10%, var(--panel)));
  border: 1px solid var(--line);
}

.kpi .num {
  font-size: 24px;
  font-weight: 700;
}

.kpi-grid-compact {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: stretch;
}

.kpi-compact {
  padding: 10px 12px;
  border-radius: 10px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.kpi-compact .muted {
  font-size: 12px;
}

.kpi-compact .num {
  font-size: 22px;
  line-height: 1.15;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--panel-soft);
  color: #4e617a;
  font-weight: 600;
}

html.dark th {
  background: rgba(24, 45, 69, 0.88);
  color: #c7dbee;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--panel-soft) 82%, #eef5ff);
}

html.dark tbody tr:hover td {
  background: rgba(34, 60, 89, 0.32);
}

.row-deleted {
  opacity: 0.58;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: block;
  font-size: 12px;
  color: #566980;
  margin-bottom: 4px;
}

html.dark label {
  color: #b8ccdf;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: var(--panel);
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 45%, #9cc4ff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

textarea {
  min-height: 88px;
}

.btn {
  display: inline-block;
  border: 0;
  border-radius: 11px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(90deg, color-mix(in srgb, var(--primary) 86%, #00d2ff), color-mix(in srgb, var(--primary-strong) 80%, #00a37f));
}

.btn-secondary {
  background: #f6f9ff;
  color: #2f5e98;
  border-color: #d8e5fb;
}

.btn-danger {
  background: #fff1f1;
  color: #c53030;
  border-color: #f5c6c6;
}

html.dark .btn-secondary {
  background: linear-gradient(180deg, rgba(20, 44, 70, 0.76), rgba(14, 33, 55, 0.76));
  color: #cbe0f4;
  border-color: rgba(137, 171, 204, 0.36);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

html.dark .btn-secondary:hover {
  border-color: rgba(56, 184, 232, 0.58);
  color: #ebf7ff;
}

html.dark .btn-danger {
  background: rgba(128, 43, 56, 0.32);
  color: #ffc2cb;
  border-color: rgba(226, 112, 130, 0.42);
}

.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar {
  gap: 7px;
  align-items: center;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

html.dark .filter-bar {
  border-color: rgba(137, 171, 204, 0.28);
  background: rgba(23, 43, 66, 0.72);
}

.filter-bar label {
  margin-bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.filter-bar input,
.filter-bar select {
  width: auto;
  min-width: 98px;
  height: 32px;
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 9px;
  border-color: #d8e4f6;
  background: #ffffff;
}

html.dark .filter-bar input,
html.dark .filter-bar select {
  border-color: rgba(137, 171, 204, 0.3);
  background: rgba(10, 24, 41, 0.74);
  color: var(--ink);
}

.filter-bar input[type="text"],
.filter-bar input[type="search"] {
  min-width: 170px;
}

.filter-bar input[type="date"] {
  min-width: 130px;
}

.filter-bar .btn {
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
}

.agent-assign-inline {
  flex-wrap: nowrap;
  gap: 4px;
}

.agent-assign-inline select {
  width: 110px;
  min-width: 110px;
  padding: 4px 6px;
  font-size: 12px;
}

.identity-inline {
  flex-wrap: nowrap;
  gap: 4px;
}

.identity-inline input {
  width: 138px;
  min-width: 138px;
  padding: 4px 6px;
  font-size: 12px;
}

.customer-inline-select {
  width: 118px;
  min-width: 118px;
  padding: 4px 6px;
  font-size: 12px;
}

.customer-inline-input {
  width: 138px;
  min-width: 138px;
  padding: 4px 6px;
  font-size: 12px;
}

.btn-sm {
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}

.table-wrap .btn {
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}

.table-wrap select,
.table-wrap input {
  padding: 6px 8px;
  font-size: 12px;
}

.badge {
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
  display: inline-block;
}

.badge-ok {
  background: #e7f7ef;
  color: var(--ok);
}

.badge-warn {
  background: #fff4e0;
  color: var(--warn);
}

.badge-danger {
  background: #fde9e9;
  color: var(--danger);
}

.alert {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 14px;
}

.alert-success {
  background: color-mix(in srgb, var(--ok) 20%, var(--panel));
  color: color-mix(in srgb, var(--ok) 70%, #14573a);
}

.alert-warning {
  background: color-mix(in srgb, var(--warn) 20%, var(--panel));
  color: color-mix(in srgb, var(--warn) 78%, #7a4a00);
}

.alert-error {
  background: color-mix(in srgb, var(--danger) 18%, var(--panel));
  color: color-mix(in srgb, var(--danger) 75%, #7f1d1d);
}

.mt-10 {
  margin-top: 10px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  font-size: 13px;
}

.detail-label {
  color: var(--muted);
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 9px 12px;
}

html.dark .pager {
  border-color: rgba(137, 171, 204, 0.28);
  background: rgba(23, 43, 66, 0.7);
}

.pager-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 9px;
  border: 1px solid #d8e4f6;
  background: #ffffff;
  color: #3f5775;
  font-size: 12px;
  font-weight: 700;
}

html.dark .pager-btn {
  border-color: rgba(137, 171, 204, 0.3);
  background: rgba(10, 24, 41, 0.72);
  color: #c7ddf0;
}

.pager-btn:hover {
  border-color: color-mix(in srgb, var(--primary) 60%, #6ae0ff);
}

.pager-disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.pager-info {
  color: var(--muted);
  font-size: 12px;
}

.pager-summary {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.pager-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager-current {
  min-width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: 1px solid color-mix(in srgb, var(--primary) 45%, #9cc4ff);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
}

.dashboard-section {
  margin-top: 14px;
}

.dashboard-section:first-child {
  margin-top: 0;
}

.dashboard-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.dashboard-grid > .panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.dashboard-grid > .panel + .panel {
  margin-top: 0;
}

.dashboard-chart-panel {
  min-height: 380px;
}

.dashboard-insight-grid {
  grid-template-columns: 1fr 1fr;
}

.dashboard-chart-wrap {
  position: relative;
  height: 210px;
}

.dashboard-chart-wrap-donut {
  height: 210px;
}

.dashboard-trend-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-trend-wrap {
  position: relative;
  height: 180px;
}

.dashboard-trend-wrap-refund {
  height: 150px;
}

.dashboard-canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.sync-jobs-section {
  margin-top: 14px;
}

.sync-jobs-section:first-child {
  margin-top: 0;
}

.sync-jobs-head {
  justify-content: space-between;
  align-items: flex-end;
}

.sync-jobs-head .btn {
  min-width: 84px;
  justify-content: center;
}

.sync-jobs-grid {
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
}

.sync-jobs-grid > .panel {
  min-height: 270px;
}

.sync-jobs-grid > .panel + .panel {
  margin-top: 0;
}

.sync-jobs-grid .table-wrap {
  flex: 1;
}

.sync-jobs-retry-actions {
  justify-content: flex-start;
  gap: 8px;
}

.sync-jobs-retry-actions form {
  margin: 0;
}

.sync-jobs-filter {
  align-items: center;
}

.pager-per-page {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.app-shell-secondary {
  grid-template-columns: 72px 126px minmax(0, 1fr);
}

.nav-primary,
.nav-secondary {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.nav-primary {
  background: var(--sidebar-grad);
  border-right: 1px solid rgba(142, 174, 205, 0.16);
}

.nav-primary .sidebar-brand {
  height: 52px;
  justify-content: center;
  padding: 0 8px;
  border-bottom: 1px solid rgba(142, 174, 205, 0.14);
}

.nav-primary .logo {
  display: none;
}

.primary-menu {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  grid-auto-rows: min-content;
  gap: 6px;
  padding: 8px 6px 10px;
}

.primary-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  padding: 8px 6px;
  border-radius: 10px;
  color: #b7cbe2;
  border: 1px solid transparent;
}

.primary-link .nav-icon {
  width: 18px;
  height: 18px;
}

.primary-link .nav-icon svg {
  width: 18px;
  height: 18px;
}

.primary-label {
  font-size: 11px;
  line-height: 1.15;
  font-weight: 600;
  text-align: center;
}

.primary-link:hover,
.primary-link.active {
  color: #e8f6ff;
}

.primary-link:hover {
  background: rgba(255, 255, 255, 0.07);
}

.primary-link.active {
  background: linear-gradient(180deg, rgba(35, 192, 201, 0.26), rgba(30, 97, 184, 0.15));
  border-color: rgba(35, 192, 201, 0.28);
}

.nav-secondary {
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.secondary-head {
  height: 52px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
  color: var(--topbar-title);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.secondary-menu {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 3px;
  padding: 7px 6px;
}

.secondary-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 8px;
  padding: 5px 7px;
  font-size: 12px;
  color: #4f6178;
  border: 1px solid transparent;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.secondary-link:hover {
  background: color-mix(in srgb, var(--panel-soft) 75%, #edf4ff);
  border-color: #d7e5fb;
}

.secondary-link.active {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, var(--panel));
  border-color: color-mix(in srgb, var(--primary) 30%, #b2d3ff);
  font-weight: 700;
}

.nav-secondary .sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 6px;
  gap: 5px;
}

.nav-secondary .side-tool {
  height: 30px;
  border-radius: 9px;
  border: 1px solid #d8e4f6;
  background: #f6f9ff;
  color: #2f5e98;
  font-size: 12px;
  padding: 0 8px;
}

.nav-secondary .side-tool:hover {
  border-color: color-mix(in srgb, var(--primary) 42%, #7ee0ff);
  color: var(--primary);
}

html.dark .nav-secondary .side-tool {
  background: rgba(20, 44, 70, 0.76);
  border-color: rgba(137, 171, 204, 0.36);
  color: #cbe0f4;
}

html.dark .nav-secondary .side-tool:hover {
  border-color: rgba(56, 184, 232, 0.58);
  color: #ebf7ff;
}

.app-shell-secondary.sidebar-collapsed {
  grid-template-columns: 72px 50px minmax(0, 1fr);
}

.app-shell-secondary.sidebar-collapsed .secondary-head {
  height: auto;
  min-height: 56px;
  justify-content: center;
  text-align: center;
  padding: 8px 6px;
  font-size: 12px;
}

.app-shell-secondary.sidebar-collapsed .secondary-menu {
  display: none;
}

.app-shell-secondary.sidebar-collapsed .nav-secondary .side-tool {
  display: block;
  text-align: center;
  font-size: 12px;
  padding: 0 6px;
}

.app-shell-secondary.sidebar-collapsed .nav-secondary .side-tool:first-child {
  display: none;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .nav-primary,
  .nav-secondary {
    display: none;
  }

  .main {
    padding: 0;
  }

  .main-body {
    padding: 10px;
  }

  .topbar {
    padding: 8px 10px;
  }

  .title {
    font-size: 24px;
  }

  .form-grid,
  .grid-2,
  .grid-3,
  .detail-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .sync-jobs-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-chart-panel {
    min-height: 340px;
  }

  .dashboard-chart-wrap,
  .dashboard-chart-wrap-donut,
  .dashboard-trend-wrap {
    height: 190px;
  }

  .dashboard-trend-wrap-refund {
    height: 160px;
  }

  .pager {
    flex-direction: column;
    align-items: flex-start;
  }

  .pager-right {
    width: 100%;
    justify-content: flex-end;
  }
}
