:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --text: #17202a;
  --muted: #687385;
  --quiet: #8a94a3;
  --border: #dfe4ea;
  --border-strong: #cfd6df;
  --green: #23764d;
  --green-bg: #e8f5ee;
  --blue: #2563ad;
  --blue-bg: #eaf2ff;
  --yellow: #7a5600;
  --yellow-bg: #fff2cc;
  --orange: #ad5700;
  --orange-bg: #fff0df;
  --red: #a23b3b;
  --red-bg: #fdeaea;
  --grey: #5f6b7a;
  --grey-bg: #eef1f4;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg: #11161c;
  --surface: #18212b;
  --surface-soft: #111922;
  --text: #edf2f7;
  --muted: #a8b2bf;
  --quiet: #8794a4;
  --border: #2c3947;
  --border-strong: #3a4654;
  --green: #69c08f;
  --green-bg: #173826;
  --blue: #8db8ff;
  --blue-bg: #132a4a;
  --yellow: #f0c468;
  --yellow-bg: #3a2c12;
  --orange: #ffb36c;
  --orange-bg: #3a2412;
  --red: #f2a2a2;
  --red-bg: #3a1d1d;
  --grey: #b4bfcc;
  --grey-bg: #27303a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.4;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

button {
  color: inherit;
}

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

a:hover {
  text-decoration: underline;
}

.panel {
  width: 100%;
  min-height: 280px;
  overflow-x: hidden;
  background: var(--surface);
}

.standalone {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
  background: var(--surface-soft);
}

.setup {
  width: min(560px, calc(100vw - 32px));
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.setup h1,
.empty h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.setup p,
.empty p {
  margin: 10px 0 0;
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  margin-top: 20px;
  padding: 0 14px;
  color: #ffffff;
  background: var(--green);
  border-radius: 6px;
}

.customer-card,
.products-bought,
.open-orders,
.activity {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.identity-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.identity-name {
  min-width: 0;
}

.eyebrow,
.email,
.snapshot dt,
.activity-title-row p,
.subscription-detail span,
.order-detail span,
.filter-note,
.empty-note,
.muted {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.identity-row h1 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 700;
}

.email {
  flex: 1 1 auto;
  margin: 18px 0 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-size: 11px;
}

.subscriptions-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.subscription-detail {
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.subscription-toggle {
  display: flex;
  width: 100%;
  min-width: 0;
  padding: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
}

.subscription-caret {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  transform: rotate(0deg);
}

.subscription-toggle[aria-expanded='true'] .subscription-caret {
  transform: rotate(90deg);
}

.subscriptions-list-toggle[aria-expanded='true'] .subscription-caret {
  transform: rotate(90deg);
}

.subscription-summary {
  display: grid;
  flex: 1 1 auto;
  min-width: 0;
  gap: 2px;
}

.subscription-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  padding-top: 8px;
}

.subscription-body[hidden] {
  display: none;
}

.subscription-body div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.subscription-detail span {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.subscription-detail strong {
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.25;
}

.subscription-pill {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.subscription-pill-active {
  color: var(--green);
  background: var(--green-bg);
}

.subscription-pill-paused,
.subscription-pill-other {
  color: var(--yellow);
  background: var(--yellow-bg);
}

.subscription-pill-completed {
  color: var(--grey);
  background: var(--grey-bg);
}

.subscription-pill-ended {
  color: var(--red);
  background: var(--red-bg);
}

.subscriptions-list-toggle {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  color: var(--blue);
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.subscriptions-list-toggle .subscription-caret {
  font-size: 16px;
}

.snapshot {
  display: grid;
  grid-template-columns: 1fr;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.snapshot div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  padding: 8px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.snapshot div:last-child {
  border-bottom: 0;
}

.snapshot dt {
  font-size: 12px;
  font-weight: 600;
}

.snapshot dd {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
}

.vip-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  padding: 2px 6px;
  color: #765100;
  background: #fff1bd;
  border: 1px solid #e2bd55;
  border-radius: 999px;
  font-size: 9px;
  line-height: 1;
  font-weight: 900;
}

.products-title-row,
.open-orders-title-row,
.activity-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.products-title-row h2,
.open-orders-title-row h2,
.activity-title-row h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
}

.activity-title-row p {
  margin: 2px 0 0;
  font-size: 12px;
}

.products-count {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 22px;
  padding: 1px 7px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.open-orders-count {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 22px;
  padding: 1px 7px;
  color: var(--orange);
  background: var(--orange-bg);
  border: 1px solid rgba(173, 87, 0, 0.25);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.open-orders-list {
  display: grid;
  gap: 6px;
}

.open-order {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--orange);
  border-radius: 6px;
  text-decoration: none;
}

.open-order:hover,
.open-order:focus-visible {
  background: var(--orange-bg);
  outline: none;
}

.open-order div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.open-order strong {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.open-order span:not(.order-status) {
  color: var(--muted);
  font-size: 11px;
}

.product-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.product-list li {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 26px;
  gap: 6px;
  padding: 4px 7px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

.product-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-list strong {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.activity.is-collapsed {
  padding-bottom: 8px;
}

.activity.is-collapsed .activity-title-row {
  margin-bottom: 0;
}

.activity-toggle {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  padding: 0;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.activity-toggle:hover h2,
.activity-toggle:focus-visible h2 {
  color: var(--blue);
}

.activity-toggle:focus-visible {
  border-radius: 4px;
  outline: 2px solid rgba(37, 99, 173, 0.18);
  outline-offset: 3px;
}

.activity-caret,
.caret {
  flex: 0 0 auto;
  color: var(--quiet);
  transform: rotate(90deg);
  transition: transform 0.16s ease;
}

.activity.is-collapsed .activity-caret,
.order:not(.is-expanded) .caret {
  transform: rotate(0deg);
}

.status-filter {
  display: block;
  flex: 0 0 154px;
}

.status-filter span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.status-filter select {
  width: 154px;
  min-height: 32px;
  padding: 0 28px 0 9px;
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  appearance: none;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 15px,
    calc(100% - 9px) 15px;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
  font-size: 12px;
  font-weight: 600;
}

.status-filter select:focus {
  border-color: var(--blue);
  outline: 2px solid rgba(37, 99, 173, 0.16);
}

.feed-head,
.order-button {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr) 88px;
  gap: 6px;
}

.feed-head {
  padding: 0 8px 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.feed-head span:last-child {
  text-align: right;
}

.orders {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.order + .order {
  border-top: 1px solid var(--border);
}

.order-button {
  width: 100%;
  padding: 10px 8px;
  text-align: left;
  background: var(--surface);
  border: 0;
  cursor: pointer;
}

.order-button:hover,
.order-button:focus-visible,
.order.is-expanded .order-button {
  background: var(--surface-soft);
  outline: none;
}

.date-cell,
.order-cell,
.amount-cell {
  min-width: 0;
}

.date-cell,
.order-cell {
  display: grid;
  align-content: start;
  gap: 3px;
}

.date-cell strong,
.amount-cell strong {
  font-size: 12px;
  line-height: 1.15;
}

.date-cell span,
.method-line,
.product-line {
  color: var(--muted);
  font-size: 12px;
}

.order-line {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 3px;
}

.order-number {
  overflow: hidden;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-line {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.method-line {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 6px;
}

.source,
.order-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
}

.source {
  padding: 3px 6px;
  color: var(--blue);
  background: var(--blue-bg);
}

.source-pos {
  color: var(--yellow);
  background: var(--yellow-bg);
}

.amount-cell {
  display: grid;
  justify-items: end;
  align-content: start;
  gap: 5px;
  text-align: right;
}

.order-status {
  max-width: 88px;
  padding: 4px 6px;
  overflow-wrap: anywhere;
  text-align: center;
  line-height: 1.1;
  white-space: normal;
}

.status-completed,
.status-completed-in-stor,
.status-enrolled,
.status-acc-enrolled,
.status-acc-sub-payment,
.status-partial-paid,
.status-rental-paid-dep-r,
.status-rental-paid-depos {
  color: var(--green);
  background: var(--green-bg);
}

.status-processing,
.status-on-hold {
  color: var(--blue);
  background: var(--blue-bg);
}

.status-pending,
.status-pending-payment,
.status-pending-supplier {
  color: var(--orange);
  background: var(--orange-bg);
}

.status-cancelled,
.status-failed,
.status-refunded {
  color: var(--red);
  background: var(--red-bg);
}

.order-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 10px 80px;
  background: var(--surface-soft);
  border-top: 1px solid var(--border);
}

.item-note {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.order-detail span {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.order-detail strong {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.open-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 28px;
  gap: 5px;
  padding: 0 9px;
  color: var(--blue);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.open-link:hover,
.open-link:focus-visible {
  background: var(--blue-bg);
  outline: none;
}

.loading,
.empty {
  display: grid;
  justify-items: center;
  padding: 28px 18px;
  text-align: center;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading p {
  margin: 12px 0 0;
  color: var(--muted);
}

.filter-note,
.empty-note {
  padding: 10px 8px 0;
  font-size: 12px;
  text-align: center;
}

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

@media (max-width: 330px) {
  .identity-row,
  .activity-title-row {
    display: grid;
  }

  .email {
    margin-top: 0;
    text-align: left;
  }

  .status-filter,
  .status-filter select {
    width: 100%;
  }

  .subscription-body {
    grid-template-columns: 1fr;
  }
}
