:root {
  --ink: #171717;
  --muted: #666661;
  --line: #d9d9d3;
  --line-strong: #bdbdb5;
  --surface: #ffffff;
  --canvas: #f3f3f0;
  --header: #202221;
  --green: #087554;
  --green-soft: #e4f4ec;
  --amber: #8b5400;
  --amber-soft: #fff1d2;
  --red: #ae2b2b;
  --red-soft: #fde8e8;
  --blue: #205e9b;
  --blue-soft: #e8f1fb;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
a,
input,
select,
summary {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(32, 94, 155, 0.25);
  outline-offset: 2px;
}

.topbar {
  min-height: 64px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: #fff;
  background: var(--header);
  border-bottom: 3px solid #55b78e;
}

.brand,
.login-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  color: #0b241a;
  background: #55b78e;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 800;
}

.brand h1,
.login-brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.brand p,
.login-brand p {
  margin: 3px 0 0;
  color: #bdbdbd;
  font-size: 11px;
}

.toolbar,
.panel-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.auto-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #dfdfdf;
  font-size: 12px;
  white-space: nowrap;
}

.auto-refresh input,
.row-enabled {
  accent-color: var(--green);
}

.icon-button,
.text-button,
.primary-button {
  height: 34px;
  border-radius: 5px;
  cursor: pointer;
}

.icon-button {
  width: 34px;
  padding: 0;
  color: #fff;
  background: #2c2f2d;
  border: 1px solid #505451;
  font-size: 19px;
}

.icon-button:hover,
.text-button.dark:hover {
  background: #3a3e3b;
}

.icon-button:disabled,
.text-button:disabled,
.primary-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.text-button,
.primary-button {
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}

.text-button:hover {
  background: #f5f5f2;
}

.text-button.dark {
  color: #fff;
  background: #2c2f2d;
  border-color: #505451;
}

.primary-button {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.primary-button:hover {
  background: #076747;
}

.sync-state {
  min-width: 76px;
  color: #bdbdbd;
  font-size: 11px;
  white-space: nowrap;
}

.sync-state[data-tone="success"] {
  color: #9de0c1;
}

.sync-state[data-tone="danger"] {
  color: #ffb2b2;
}

.market-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(125px, 1fr)) repeat(2, minmax(175px, 1.25fr)) auto;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.market-strip > div {
  min-height: 61px;
  padding: 10px 13px;
  border-right: 1px solid var(--line);
}

.market-strip span,
.metric-band span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.market-strip strong,
.metric-band strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.market-strip strong.compact {
  display: block;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-strip small,
.metric-band small {
  color: var(--muted);
  font-size: 10px;
}

.market-strip > a {
  min-width: 80px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}

.warning-band {
  padding: 9px 18px;
  color: #633b00;
  background: var(--amber-soft);
  border-bottom: 1px solid #e8cc91;
  font-size: 12px;
  line-height: 1.45;
}

.metric-band {
  margin: 14px 18px 0;
  display: grid;
  grid-template-columns: repeat(10, minmax(105px, 1fr));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.metric-band > div {
  min-height: 70px;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.metric-band > div:last-child {
  border-right: 0;
}

.metric-band .positive strong {
  color: var(--green);
}

.metric-band .negative strong {
  color: var(--red);
}

.metric-band .caution strong {
  color: var(--amber);
}

.panel {
  margin: 12px 18px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.offers-panel {
  margin-bottom: 18px;
}

.panel-head {
  min-height: 52px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.settings-grid {
  padding: 11px 12px 12px;
  display: grid;
  grid-template-columns: repeat(8, minmax(110px, 1fr));
  gap: 9px;
}

.settings-grid label,
.login-form label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.settings-grid input,
.route-controls select,
.offers-table input,
.offers-table select,
.login-form input {
  width: 100%;
  min-height: 33px;
  margin-top: 5px;
  padding: 6px 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c7c7c0;
  border-radius: 4px;
  outline: 0;
}

.settings-grid input:focus,
.route-controls select:focus,
.offers-table input:focus,
.offers-table select:focus,
.login-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-soft);
}

.route-controls {
  padding: 11px 12px 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 280px));
  gap: 9px;
}

.route-controls label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.route-controls select {
  width: 100%;
  min-height: 35px;
  margin-top: 5px;
  padding: 6px 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c7c7c0;
  border-radius: 4px;
}

.gate-grid {
  padding: 11px 12px 8px;
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
}

.gate-item {
  min-height: 42px;
  padding: 8px 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: #3f3f3b;
  font-size: 11px;
  line-height: 1.3;
}

.gate-item input {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  accent-color: var(--green);
}

.control-note {
  margin: 0;
  padding: 0 12px 11px;
  color: var(--muted);
  font-size: 10px;
}

.snapshot-time {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

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

.audit-block + .audit-block {
  border-top: 1px solid var(--line);
}

.audit-block h3 {
  margin: 0;
  padding: 9px 12px;
  color: #4f4f4b;
  background: #f7f7f4;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}

.audit-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: 11px;
}

.pair-table {
  min-width: 1120px;
}

.audit-table th,
.audit-table td {
  padding: 8px 9px;
  border-right: 1px solid #ecece7;
  border-bottom: 1px solid #ecece7;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.audit-table th {
  color: #4f4f4b;
  background: #efefeb;
  font-size: 10px;
}

.audit-table .number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.audit-table .profit {
  color: var(--green);
  font-weight: 700;
}

.audit-table .loss {
  color: var(--red);
  font-weight: 700;
}

.audit-table .wrap-cell {
  max-width: 420px;
  white-space: normal;
  line-height: 1.4;
}

.audit-table a {
  color: var(--blue);
  text-decoration: none;
}

.formula-audit {
  padding: 0 12px 11px;
  color: var(--muted);
  font-size: 11px;
}

.formula-audit summary {
  width: max-content;
  color: var(--blue);
  cursor: pointer;
  font-weight: 600;
}

.formula-audit > div {
  margin-top: 8px;
  padding: 9px 10px;
  display: grid;
  gap: 5px;
  background: #f5f5f2;
  border-left: 3px solid var(--blue);
}

.formula-audit code {
  overflow-wrap: anywhere;
  font-family: "Cascadia Code", Consolas, monospace;
}

.table-scroll {
  max-width: 100%;
  overflow: auto;
}

.offers-table {
  width: 100%;
  min-width: 3260px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11px;
}

.offers-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 40px;
  padding: 7px 8px;
  color: #4f4f4b;
  background: #efefeb;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line-strong);
  text-align: left;
  white-space: nowrap;
}

.offers-table td {
  height: 48px;
  padding: 6px 8px;
  background: #fff;
  border-right: 1px solid #ecece7;
  border-bottom: 1px solid #ecece7;
  white-space: nowrap;
}

.offers-table tr:hover td {
  background: #fafaf7;
}

.offers-table tr.disabled-row td {
  opacity: 0.5;
}

.offers-table input,
.offers-table select {
  min-height: 31px;
  margin: 0;
  font-size: 11px;
}

.offers-table .number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.offers-table .profit {
  color: var(--green);
  font-weight: 700;
}

.offers-table .loss {
  color: var(--red);
  font-weight: 700;
}

.offers-table .rank {
  color: var(--blue);
  font-weight: 700;
}

.offers-table .sticky-col {
  position: sticky;
}

.offers-table th.sticky-col {
  z-index: 5;
}

.offers-table td.sticky-col {
  z-index: 2;
}

.offers-table .col-enabled {
  left: 0;
  width: 56px;
  min-width: 56px;
  text-align: center;
}

.offers-table .col-name {
  left: 56px;
  width: 130px;
  min-width: 130px;
  box-shadow: 1px 0 var(--line-strong);
}

.offers-table .amount-input {
  width: 84px;
  text-align: right;
}

.offers-table .rate-input {
  width: 104px;
  text-align: right;
}

.offers-table .channel-select {
  width: 164px;
}

.offers-table .compliance-select {
  width: 88px;
}

.status {
  min-width: 66px;
  height: 24px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
}

.status.success {
  color: var(--green);
  background: var(--green-soft);
}

.status.warning {
  color: var(--amber);
  background: var(--amber-soft);
}

.status.danger {
  color: var(--red);
  background: var(--red-soft);
}

.status.muted {
  color: #555;
  background: #ecece8;
}

.delete-button {
  width: 29px;
  height: 29px;
  padding: 0;
  color: var(--red);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 19px;
}

.delete-button:hover {
  background: var(--red-soft);
}

.footer {
  padding: 0 18px 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.footer a {
  margin-left: 14px;
  color: var(--blue);
  text-decoration: none;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #ededE9;
}

.login-shell {
  width: min(100%, 390px);
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(25, 25, 25, 0.12);
}

.login-brand {
  min-height: 76px;
  padding: 16px 18px;
  color: #fff;
  background: var(--header);
  border-bottom: 3px solid #55b78e;
}

.login-form {
  padding: 20px 18px;
  display: grid;
  gap: 14px;
}

.login-form label {
  font-size: 12px;
}

.login-form input {
  min-height: 42px;
  font-size: 14px;
}

.login-button {
  height: 42px;
  margin-top: 2px;
  font-size: 14px;
}

.login-error {
  padding: 9px 10px;
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid #f0c2c2;
  border-radius: 4px;
  font-size: 12px;
}

@media (max-width: 1280px) {
  .market-strip {
    grid-template-columns: repeat(4, minmax(130px, 1fr));
  }

  .market-strip > a {
    min-height: 44px;
  }

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

  .metric-band > div:nth-child(4n) {
    border-right: 0;
  }

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

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

@media (max-width: 720px) {
  .topbar {
    padding: 9px 10px;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .brand {
    width: 100%;
  }

  .brand p {
    display: none;
  }

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

  .auto-refresh {
    margin-right: auto;
  }

  .sync-state {
    min-width: auto;
  }

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

  .market-strip > div {
    min-width: 0;
  }

  .market-strip > a {
    grid-column: 1 / -1;
  }

  .metric-band,
  .panel {
    margin-left: 8px;
    margin-right: 8px;
  }

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

  .metric-band > div:nth-child(2n) {
    border-right: 0;
  }

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

  .panel-actions {
    width: 100%;
    justify-content: flex-end;
  }

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

  .route-controls {
    grid-template-columns: 1fr;
  }

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

  .footer {
    padding: 0 10px 14px;
    flex-direction: column;
  }

  .footer a {
    margin: 0 14px 0 0;
  }

  .login-page {
    padding: 12px;
  }
}

@media (max-width: 410px) {
  .auto-refresh {
    font-size: 0;
  }

  .auto-refresh input {
    width: 18px;
    height: 18px;
  }

  .sync-state {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
