:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #d9e2ea;
  --line-soft: #e8eef3;
  --text: #10212f;
  --muted: #647484;
  --muted-2: #91a0ad;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #e5f6f3;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 16px 40px rgba(16, 33, 47, 0.08);
  --radius: 8px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(244, 247, 249, 0.96)),
    url("assets/quexi-mark.svg") center 18% / 360px 360px no-repeat;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 0;
}

.login-button {
  width: 100%;
}

.login-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background: #ffffff;
  border-right: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
}

.brand-title {
  font-size: 22px;
  line-height: 1.1;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-color: #ccebe5;
}

.nav-icon,
[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-icon svg,
[data-icon] svg,
.kpi-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-icon svg *,
[data-icon] svg *,
.kpi-icon svg * {
  fill: none;
}

.sidebar-card {
  margin-top: auto;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.sidebar-card-title {
  font-weight: 700;
  margin-bottom: 10px;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 13px;
}

.sync-pill span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.sync-pill.good {
  color: #166534;
  background: #e8f7ee;
}

.sync-pill.good span {
  background: var(--green);
}

.sync-pill.warn {
  color: #92400e;
  background: #fff6df;
}

.sync-pill.warn span {
  background: var(--amber);
}

.sidebar-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 4px;
  font-size: 17px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 6px;
  font-size: 15px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: #eaf0f5;
  border-radius: var(--radius);
}

.segmented.small {
  padding: 2px;
}

.segment {
  min-height: 34px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  white-space: nowrap;
}

.segmented.small .segment {
  min-height: 30px;
  font-size: 13px;
}

.segment.active {
  color: var(--text);
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 33, 47, 0.08);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.compact-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.field input,
.field select,
.compact-field select,
.search-box input {
  min-height: 38px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.compact-field select {
  min-height: auto;
  border: 0;
}

.field input,
.field select {
  padding: 0 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 250px;
  min-height: 40px;
  padding: 0 10px;
  color: var(--muted);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
}

.icon-button,
.ghost-button,
.text-button,
.primary-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.icon-button {
  width: 40px;
  color: var(--muted);
  background: #ffffff;
}

.ghost-button,
.text-button {
  padding: 0 12px;
  color: var(--primary-dark);
  background: #ffffff;
}

.text-button {
  border-color: transparent;
  background: transparent;
  font-weight: 700;
}

.primary-button {
  padding: 0 16px;
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 700;
}

.user-chip {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  white-space: nowrap;
}

.connection-banner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 18px;
  background: #f0fdfa;
  border: 1px solid #bde9e1;
  border-radius: var(--radius);
  color: #115e59;
}

.connection-banner span {
  margin-left: 8px;
  color: #2f6f67;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi-card,
.panel,
.merchant-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi-card {
  min-height: 126px;
  padding: 16px;
}

.kpi-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.kpi-icon {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 8px;
}

.kpi-value {
  margin: 12px 0 6px;
  font-size: 25px;
  line-height: 1.1;
  font-weight: 800;
}

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

.kpi-foot strong {
  color: var(--green);
}

.analytics-grid,
.tables-grid,
.revenue-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(320px, 0.9fr);
  gap: 14px;
  margin-bottom: 14px;
}

.sync-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(210px, 1fr));
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-head,
.section-head,
.table-tools {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-head {
  align-items: center;
  margin-bottom: 14px;
}

.section-head p,
.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.panel-tag {
  padding: 5px 9px;
  color: var(--blue);
  background: #e9f0ff;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.trend-panel canvas {
  width: 100%;
  height: 280px;
  margin-top: 14px;
}

.donut-wrap {
  display: grid;
  justify-items: center;
  gap: 12px;
  margin-top: 12px;
}

.donut-wrap canvas {
  width: 230px;
  height: 230px;
}

.legend {
  width: 100%;
  display: grid;
  gap: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.legend-row span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.table-wrap {
  overflow: auto;
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
  font-size: 13px;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 700;
}

td {
  color: #263847;
}

tbody tr:hover {
  background: #fbfcfd;
}

.industry-badge,
.status-badge,
.type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.industry-chess {
  color: #0f766e;
  background: #e5f6f3;
}

.industry-billiards {
  color: #1d4ed8;
  background: #e9f0ff;
}

.industry-carwash {
  color: #047857;
  background: #e8f7ee;
}

.industry-unknown {
  color: #52606d;
  background: #eef2f6;
}

.status-success {
  color: #166534;
  background: #e8f7ee;
}

.status-warning {
  color: #92400e;
  background: #fff6df;
}

.status-muted {
  color: #52606d;
  background: #eef2f6;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.trend-chip {
  color: var(--green);
  font-weight: 800;
}

.resource-list,
.rule-list,
.settlement-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.resource-item,
.rule-item,
.settlement-item,
.sync-item,
.empty-state {
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.resource-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.resource-name {
  font-weight: 800;
}

.resource-meta,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.resource-stats {
  text-align: right;
}

.merchant-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 14px;
}

.merchant-card {
  padding: 18px;
}

.merchant-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.metric {
  display: grid;
  gap: 4px;
}

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

.metric strong {
  font-size: 16px;
}

.table-tools {
  align-items: center;
  margin-bottom: 4px;
}

.rule-item,
.settlement-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rule-rate {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
}

.sync-item h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sync-item p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-panel {
  max-width: 640px;
  display: grid;
  gap: 16px;
}

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

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .brand div,
  .nav-item span:last-child,
  .sidebar-card {
    display: none;
  }

  .brand {
    justify-content: center;
  }

  .nav-item {
    justify-content: center;
    padding: 0;
  }

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

  .analytics-grid,
  .tables-grid,
  .revenue-layout {
    grid-template-columns: 1fr;
  }

  .merchant-grid,
  .sync-grid {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(4, 1fr);
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .section-head,
  .connection-banner {
    display: grid;
    align-items: stretch;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    justify-self: stretch;
  }

  .topbar-actions,
  .search-box,
  .segmented,
  .compact-field,
  .icon-button {
    width: 100%;
  }

  .segmented {
    display: flex;
  }

  .segment {
    flex: 1;
  }

  .kpi-grid,
  .merchant-grid,
  .sync-grid {
    grid-template-columns: 1fr;
  }
}
