:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-alt: #eef2ed;
  --ink: #171a17;
  --muted: #687067;
  --line: #d9dfd7;
  --green: #087f5b;
  --green-soft: #dff3ea;
  --blue: #2563a9;
  --amber: #a85d00;
  --amber-soft: #fff1d6;
  --red: #b4232f;
  --red-soft: #fde7e9;
  --shadow: 0 8px 24px rgba(25, 35, 26, 0.07);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

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

button {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.topbar-inner,
.product-bar-inner,
main {
  width: min(1360px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar-inner {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.identity {
  min-width: 0;
}

.product-kicker {
  margin-bottom: 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 860px;
  overflow: hidden;
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

.topbar-command {
  position: relative;
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #384037;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.topbar-command:hover {
  border-color: #aeb7ad;
  background: var(--surface-alt);
}

.topbar-command svg {
  width: 16px;
  height: 16px;
}

.count-badge {
  min-width: 19px;
  height: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border-radius: 10px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.account-name {
  max-width: 120px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-bar {
  border-top: 1px solid #edf0ec;
  background: #f8f9f7;
}

.product-bar-inner {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.product-selector-group,
.product-selector,
.select-control,
.baseline-scope,
.product-bar-actions {
  display: flex;
  align-items: center;
}

.product-selector-group {
  min-width: 0;
  flex: 1 1 auto;
  gap: 10px;
}

.product-selector-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  color: var(--green);
}

.product-selector {
  min-width: 0;
  gap: 10px;
}

.product-select-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.select-control {
  position: relative;
  width: min(520px, 48vw);
  min-width: 300px;
}

.select-control select {
  width: 100%;
  height: 36px;
  appearance: none;
  overflow: hidden;
  padding: 0 36px 0 12px;
  border: 1px solid #cbd2c9;
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-control select:focus-visible,
.form-field input:focus-visible {
  border-color: var(--blue);
  outline: 3px solid rgba(37, 99, 169, 0.16);
  outline-offset: 1px;
}

.select-control svg {
  position: absolute;
  right: 11px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.baseline-scope {
  flex: 0 0 auto;
  gap: 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.baseline-scope.observed {
  color: var(--blue);
}

.baseline-scope.unavailable {
  color: var(--amber);
}

.baseline-scope.direct {
  color: var(--green);
}

.baseline-scope svg {
  width: 15px;
  height: 15px;
}

.product-bar-actions {
  flex: 0 0 auto;
  gap: 8px;
}

.connection {
  min-width: 94px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-alt);
  font-size: 12px;
  font-weight: 650;
}

.connection-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #8d958c;
}

.connection.live {
  color: var(--green);
  border-color: #a9d8c5;
  background: var(--green-soft);
}

.connection.live .connection-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.14);
}

.connection.error {
  color: var(--red);
  border-color: #efb8bd;
  background: var(--red-soft);
}

.connection.error .connection-dot {
  background: var(--red);
}

.icon-button {
  position: relative;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #384037;
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
}

.icon-button:hover {
  border-color: #aeb7ad;
  background: var(--surface-alt);
}

.danger-icon-button {
  color: var(--red);
}

.danger-icon-button:hover {
  border-color: #d9989f;
  background: var(--red-soft);
}

.icon-button:disabled,
.primary-button:disabled,
.danger-button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-button:focus-visible,
.segments button:focus-visible {
  outline: 3px solid rgba(37, 99, 169, 0.2);
  outline-offset: 2px;
}

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

.icon-button[data-tooltip]::after {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 60;
  padding: 5px 8px;
  border-radius: 5px;
  color: #ffffff;
  background: #252a25;
  content: attr(data-tooltip);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(-2px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.icon-button[data-tooltip]:hover::after,
.icon-button[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.icon-button.loading svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

main {
  padding-bottom: 28px;
}

.status-strip {
  min-height: 44px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid #e3b36f;
  border-radius: 6px;
  color: #754100;
  background: var(--amber-soft);
}

.status-strip svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.status-strip.info {
  border-color: #9dbdde;
  color: #174f80;
  background: #e8f1fb;
}

.metric-band {
  padding: 22px 0 24px;
  border-bottom: 1px solid var(--line);
}

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

.metric-card {
  min-width: 0;
  min-height: 128px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-primary {
  border-top: 3px solid var(--green);
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.metric-value {
  min-height: 52px;
  margin-top: 6px;
  overflow: hidden;
  color: var(--ink);
  font-size: 38px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-value.metric-text {
  display: flex;
  align-items: center;
  overflow: visible;
  font-size: 24px;
  line-height: 1.25;
  text-overflow: clip;
  white-space: normal;
}

.metric-change.positive { color: var(--green); }
.metric-change.negative { color: var(--red); }

.metric-meta {
  min-height: 20px;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-flash {
  animation: flash 0.9s ease-out;
}

@keyframes flash {
  0% { background: #bcebd8; }
  100% { background: var(--surface); }
}

.campaign-band,
.sku-band,
.trend-band,
.events-band {
  padding: 26px 0;
  border-bottom: 1px solid var(--line);
}

.campaign-total {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.campaign-total strong {
  color: var(--green);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.campaign-table-wrap {
  max-height: none;
}

.campaign-table {
  min-width: 820px;
}

.campaign-table th:first-child,
.campaign-table td:first-child {
  width: 38%;
  padding-left: 14px;
}

.campaign-table td:first-child strong,
.campaign-table td:first-child span {
  display: block;
}

.campaign-table td:first-child span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.campaign-active-row {
  background: #f3f8f5;
}

.campaign-sales {
  color: var(--green);
  font-weight: 750;
}

.campaign-sales.unknown {
  color: var(--amber);
}

.campaign-error {
  color: var(--red);
}

.sku-total {
  color: var(--green);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.sku-table-wrap {
  max-height: none;
}

.sku-table {
  min-width: 720px;
}

.sku-table th:first-child,
.sku-table td:first-child {
  width: 55%;
  padding-left: 14px;
}

.sku-sales-value {
  font-weight: 700;
}

.sku-sales-value.positive {
  color: var(--green);
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.segments {
  flex: 0 0 auto;
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #e9ede8;
}

.segments button {
  min-width: 60px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}

.segments button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(20, 30, 21, 0.1);
  font-weight: 700;
}

.trend-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.3fr) minmax(260px, 0.7fr);
  gap: 20px;
}

.chart-panel,
.health-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.chart-panel {
  padding: 12px 14px 6px;
}

.chart-shell {
  position: relative;
  width: 100%;
  min-height: 280px;
  aspect-ratio: 16 / 5.6;
}

#salesChart {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-grid-line {
  stroke: #e6eae4;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart-axis-label {
  fill: #7b837a;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.chart-area {
  fill: rgba(8, 127, 91, 0.09);
}

.chart-point {
  fill: var(--surface);
  stroke: var(--green);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-hover-line {
  stroke: #899187;
  stroke-width: 1;
  stroke-dasharray: 4 4;
  vector-effect: non-scaling-stroke;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 132px;
  padding: 8px 10px;
  border: 1px solid #cbd2c9;
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.health-panel {
  padding: 18px;
}

.health-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.health-title svg {
  width: 18px;
  height: 18px;
  color: var(--blue);
}

.health-list {
  margin: 0;
}

.health-list > div {
  min-height: 45px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #edf0ec;
}

.health-list > div:last-child {
  border-bottom: 0;
}

.health-list dt {
  color: var(--muted);
}

.health-list dd {
  margin: 0;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.health-list dd.interval-setting {
  overflow: visible;
}

.interval-control {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.interval-control input {
  width: 68px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid #cbd2c9;
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  text-align: right;
}

.interval-control input:focus-visible {
  border-color: var(--blue);
  outline: 3px solid rgba(37, 99, 169, 0.16);
  outline-offset: 1px;
}

.interval-control > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.interval-save {
  width: 30px;
  height: 30px;
}

.interval-save svg {
  width: 15px;
  height: 15px;
}

.health-ok { color: var(--green); }
.health-error { color: var(--red); }
.health-info { color: var(--blue); }

.event-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.events-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.event-view-switch button {
  min-width: 86px;
}

.table-wrap {
  max-height: min(560px, 70vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid #e8ece6;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0;
  color: var(--muted);
  background: #f7f8f6;
  font-size: 12px;
  font-weight: 700;
}

.sort-button {
  width: 100%;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-weight: inherit;
  white-space: nowrap;
}

th.numeric .sort-button {
  justify-content: flex-end;
}

.sort-button:hover,
.sort-button.active {
  color: var(--ink);
  background: #eef2ed;
}

.sort-button:focus-visible {
  outline: 3px solid rgba(37, 99, 169, 0.2);
  outline-offset: -3px;
}

.sort-icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
}

.sort-icon svg {
  width: 14px;
  height: 14px;
}

.sort-ascending,
.sort-descending,
.sort-button[data-direction="asc"] .sort-neutral,
.sort-button[data-direction="desc"] .sort-neutral {
  display: none;
}

.sort-button[data-direction="asc"] .sort-ascending,
.sort-button[data-direction="desc"] .sort-descending {
  display: block;
}

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

tbody tr:hover td {
  background: #fafbf9;
}

.numeric {
  text-align: right;
}

.event-type {
  display: inline-flex;
  align-items: center;
  min-width: 72px;
  height: 24px;
  justify-content: center;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
}

.event-sale { color: var(--green); background: var(--green-soft); }
.event-adjustment { color: var(--red); background: var(--red-soft); }
.event-orders { color: var(--blue); background: #e5effc; }
.event-baseline { color: #50584f; background: #ecefeb; }
.event-confirmed_sale { color: var(--green); background: var(--green-soft); }
.event-confirmed_refund { color: var(--red); background: var(--red-soft); }

.delta-positive { color: var(--green); font-weight: 700; }
.delta-negative { color: var(--red); font-weight: 700; }
.delta-order { color: var(--blue); font-weight: 700; }

.empty-cell {
  height: 108px;
  color: var(--muted);
  text-align: center;
}

footer {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: var(--muted);
  font-size: 12px;
}

footer a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--blue);
  text-decoration: none;
}

footer svg {
  width: 13px;
  height: 13px;
}

.footer-separator {
  margin: 0 5px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: min(360px, calc(100% - 40px));
  padding: 10px 14px;
  border: 1px solid #b9c1b7;
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 25, 20, 0.38);
}

.modal {
  width: min(480px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid #cfd5cd;
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 18px 54px rgba(20, 28, 21, 0.2);
}

.wide-modal {
  width: min(920px, 100%);
}

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

.modal-header {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

.modal form {
  padding: 20px;
}

.confirm-modal {
  width: min(440px, 100%);
}

.confirm-question {
  margin: 0 0 14px;
  color: #3f463e;
  font-size: 14px;
  line-height: 1.6;
}

.confirm-target {
  min-width: 0;
  margin-bottom: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.confirm-target strong,
.confirm-target span {
  display: block;
  overflow-wrap: anywhere;
}

.confirm-target strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.confirm-target span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.confirm-note {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.form-field {
  min-width: 0;
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

.form-field > label,
.form-field legend {
  display: block;
  margin-bottom: 7px;
  color: #3f463e;
  font-size: 12px;
  font-weight: 700;
}

.form-field input[type="text"],
.form-field input[type="password"],
.form-field input[type="number"] {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #cbd2c9;
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

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

.login-panel {
  width: min(390px, 100%);
  padding: 28px;
  border: 1px solid #cfd5cd;
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel > div:nth-child(2) {
  margin-bottom: 24px;
}

.login-panel h1 {
  max-width: none;
  overflow: visible;
  white-space: normal;
}

.login-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 7px;
  color: #ffffff;
  background: var(--green);
}

.login-mark svg {
  width: 22px;
  height: 22px;
}

.login-panel form {
  margin: 0;
}

.login-submit {
  width: 100%;
}

.archive-list {
  min-height: 160px;
  max-height: min(620px, calc(100vh - 150px));
  overflow: auto;
}

.archive-empty {
  min-height: 160px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
}

.archive-item {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.archive-item:last-child {
  border-bottom: 0;
}

.archive-copy {
  min-width: 0;
}

.archive-copy strong,
.archive-copy span {
  display: block;
}

.archive-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive-copy span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.archive-actions {
  display: flex;
  gap: 8px;
}

.archive-actions button {
  min-width: auto;
}

.audit-table-wrap {
  max-height: min(620px, calc(100vh - 130px));
  overflow: auto;
}

.audit-table {
  min-width: 800px;
}

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

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

.user-create-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(220px, 1.4fr) 130px auto;
  align-items: end;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.user-create-form .form-field {
  margin: 0;
}

.form-field select,
.user-role-select {
  width: 100%;
  height: 40px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  font: inherit;
}

.form-field select:focus,
.user-role-select:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(37, 99, 169, 0.14);
}

.user-create-button {
  height: 40px;
  white-space: nowrap;
}

.user-form-error {
  grid-column: 1 / -1;
  margin: 0;
}

.user-table-wrap {
  max-height: min(520px, calc(100vh - 270px));
  overflow: auto;
}

.user-table {
  min-width: 720px;
}

.user-table td:first-child strong,
.current-account-label {
  display: block;
}

.current-account-label {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.user-active-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.user-active-control input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.user-role-select {
  min-width: 104px;
}

.user-save-button {
  margin-left: auto;
}

.form-field input::placeholder {
  color: #989f97;
}

.mode-segments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #e9ede8;
}

.mode-segments label {
  position: relative;
  min-width: 0;
  cursor: pointer;
}

.mode-segments input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.mode-segments span {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.mode-segments input:checked + span {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(20, 30, 21, 0.1);
  font-weight: 700;
}

.mode-segments input:focus-visible + span {
  outline: 3px solid rgba(37, 99, 169, 0.2);
  outline-offset: 1px;
}

.form-error {
  margin: -4px 0 14px;
  padding: 9px 10px;
  border: 1px solid #efb8bd;
  border-radius: 6px;
  color: var(--red);
  background: var(--red-soft);
  font-size: 12px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 2px;
}

.text-button,
.primary-button,
.danger-button {
  min-width: 82px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.text-button {
  border: 1px solid var(--line);
  color: #444b43;
  background: var(--surface);
}

.primary-button {
  border: 1px solid var(--green);
  color: #ffffff;
  background: var(--green);
}

.danger-button {
  border: 1px solid var(--red);
  color: #ffffff;
  background: var(--red);
}

.text-button:hover {
  background: var(--surface-alt);
}

.primary-button:hover {
  background: #066d4e;
}

.danger-button:hover {
  background: #a8212f;
}

.primary-button svg,
.danger-button svg {
  width: 16px;
  height: 16px;
}

@media (max-width: 980px) {
  .user-create-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .user-create-button {
    align-self: end;
  }

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

  .trend-grid {
    grid-template-columns: 1fr;
  }

  .health-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 28px;
  }
}

@media (max-width: 680px) {
  .user-create-form {
    grid-template-columns: 1fr;
  }

  .user-create-button {
    width: 100%;
  }

  .topbar-inner,
  .product-bar-inner,
  main {
    width: min(100% - 24px, 1360px);
  }

  .topbar-inner {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    padding: 13px 0;
  }

  h1 {
    max-width: 100%;
    display: -webkit-box;
    overflow: hidden;
    font-size: 16px;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

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

  .account-name,
  .topbar-command > span:not(.count-badge) {
    display: none;
  }

  .topbar-command {
    width: 36px;
    justify-content: center;
    padding: 0;
  }

  .topbar-command .count-badge {
    position: absolute;
    margin: -27px -27px 0 0;
  }

  .connection {
    min-width: 36px;
    width: 36px;
    padding: 0;
  }

  .connection span:last-child {
    display: none;
  }

  .product-bar-inner {
    min-height: 58px;
    gap: 8px;
  }

  .product-selector-group {
    gap: 0;
  }

  .product-selector-icon,
  .product-select-label,
  .baseline-scope {
    display: none;
  }

  .product-selector,
  .select-control {
    width: 100%;
    min-width: 0;
  }

  .select-control select {
    font-size: 12px;
  }

  .metric-band {
    padding-top: 14px;
  }

  .metric-card {
    min-height: 116px;
    padding: 14px;
  }

  .metric-value {
    min-height: 45px;
    font-size: 32px;
  }

  .metric-value.metric-text {
    font-size: 21px;
  }

  .campaign-total {
    width: 100%;
    justify-content: space-between;
  }

  .campaign-table-wrap {
    overflow-x: hidden;
  }

  .campaign-table {
    min-width: 0;
    table-layout: fixed;
  }

  .campaign-table th:first-child,
  .campaign-table td:first-child {
    width: auto;
    padding: 9px 12px;
    line-height: 1.35;
    white-space: normal;
  }

  .campaign-table th:nth-child(2),
  .campaign-table td:nth-child(2),
  .campaign-table th:nth-child(4),
  .campaign-table td:nth-child(4),
  .campaign-table th:nth-child(5),
  .campaign-table td:nth-child(5) {
    display: none;
  }

  .campaign-table th:nth-child(3),
  .campaign-table td:nth-child(3) {
    width: 112px;
  }

  .sku-table-wrap {
    overflow-x: hidden;
  }

  .sku-table {
    min-width: 0;
    table-layout: fixed;
  }

  .sku-table th:first-child,
  .sku-table td:first-child {
    width: auto;
    padding: 10px 12px;
    line-height: 1.35;
    white-space: normal;
  }

  .sku-table th:nth-child(2),
  .sku-table td:nth-child(2) {
    width: 82px;
  }

  .sku-table th:nth-child(3),
  .sku-table td:nth-child(3),
  .sku-table th:nth-child(4),
  .sku-table td:nth-child(4) {
    display: none;
  }

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

  .events-controls {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
  }

  .events-controls .event-count {
    text-align: right;
  }

  .segments {
    width: 100%;
  }

  .segments button {
    min-width: 0;
    flex: 1 1 0;
  }

  .chart-panel {
    padding: 8px 8px 2px;
  }

  .chart-shell {
    min-height: 230px;
    aspect-ratio: 1.35 / 1;
  }

  .health-list {
    display: block;
  }

  footer {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 14px 0;
  }

  .login-panel {
    padding: 22px;
  }

  .archive-item {
    align-items: stretch;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px;
  }

  .archive-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 400px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
