/*
 * Layout helpers on top of Polaris web components, plus a full fallback:
 * every `s-*:not(:defined)` rule keeps the page polished even when the
 * Polaris script has not (yet) upgraded the custom elements.
 */

:root {
  --p-bg: #f6f6f7;
  --p-surface: #ffffff;
  --p-border: #e3e3e3;
  --p-text: #202223;
  --p-text-subdued: #616161;
  --p-primary: #1a1a1a;
  --p-focus: #005bd3;
  --p-success-bg: #d5f3e0;
  --p-success-text: #0c5132;
  --p-warning-bg: #ffd6a4;
  --p-warning-text: #5e4200;
  --p-critical-bg: #fed9d9;
  --p-critical-text: #8e1f0b;
  --p-radius: 12px;
  --p-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 6px rgba(0, 0, 0, 0.05);
}

/* ---------- Fallback shell (only when Polaris is not upgraded) ---------- */

s-page:not(:defined) {
  display: block;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}

s-page:not(:defined)::before {
  content: attr(heading);
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--p-text);
  margin: 0.5rem 0 1.25rem;
}

s-section:not(:defined) {
  display: block;
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  box-shadow: var(--p-shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

s-section:not(:defined)::before {
  content: attr(heading);
  display: block;
  font-size: 0.9375rem;
  font-weight: 650;
  color: var(--p-text);
  margin-bottom: 0.75rem;
}

s-text:not(:defined),
s-paragraph:not(:defined) {
  display: inline;
  color: var(--p-text);
  line-height: 1.5;
}

s-paragraph:not(:defined) {
  display: block;
  margin: 0.25rem 0 0.5rem;
  color: var(--p-text-subdued);
}

s-badge:not(:defined) {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 550;
  background: var(--p-success-bg);
  color: var(--p-success-text);
}

s-button:not(:defined) {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 10px;
  background: var(--p-primary);
  color: #ffffff;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.35);
  transition: transform 100ms ease, opacity 120ms ease, box-shadow 120ms ease;
}

s-button:not(:defined):hover {
  opacity: 0.88;
}

s-button:not(:defined):active {
  transform: scale(0.98);
}

s-button:not(:defined)[disabled],
s-button:not(:defined)[loading] {
  opacity: 0.55;
  pointer-events: none;
}

s-banner:not(:defined) {
  display: block;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

s-banner:not(:defined)[tone="critical"] {
  background: var(--p-critical-bg);
}

s-banner:not(:defined)[tone="critical"] s-text {
  color: var(--p-critical-text);
}

s-banner:not(:defined)[tone="success"] {
  background: var(--p-success-bg);
}

s-banner:not(:defined)[tone="warning"] {
  background: var(--p-warning-bg);
}

s-banner:not(:defined)[tone="warning"] s-text {
  color: var(--p-warning-text);
}

s-banner:not(:defined)[tone="success"] s-text {
  color: var(--p-success-text);
}

s-spinner:not(:defined) {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--p-border);
  border-top-color: var(--p-text-subdued);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

body {
  margin: 0;
  background: var(--p-bg);
  font-family: Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--p-text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Shared layout helpers ---------- */

.row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0;
}

.actions {
  margin-top: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0.6rem 0;
}

.field label {
  font-size: 0.8125rem;
  font-weight: 550;
  color: var(--p-text-subdued);
}

.field select {
  appearance: none;
  font: inherit;
  padding: 0.5rem 2.2rem 0.5rem 0.75rem;
  border: 1px solid #8a8a8a;
  border-radius: 8px;
  background: var(--p-surface)
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 20 20'%3E%3Cpath fill='%23616161' d='M10 14 3 7h14z'/%3E%3C/svg%3E")
    no-repeat right 0.7rem center;
  color: var(--p-text);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field select:hover {
  border-color: #616161;
}

.field select:focus {
  outline: none;
  border-color: var(--p-focus);
  box-shadow: 0 0 0 2px rgba(0, 91, 211, 0.25);
}

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0 1.25rem;
  margin-top: 0.75rem;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
}

.plan-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  background: var(--p-bg);
}

.plan-card strong {
  font-size: 0.9375rem;
  color: var(--p-text);
}

.plan-card.current {
  border-color: var(--p-focus);
  background: var(--p-surface);
  box-shadow: 0 0 0 1px var(--p-focus);
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0 1.25rem;
}

.field input {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border: 1px solid #8a8a8a;
  border-radius: 8px;
  background: var(--p-surface);
  color: var(--p-text);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field input:hover {
  border-color: #616161;
}

.field input:focus {
  outline: none;
  border-color: var(--p-focus);
  box-shadow: 0 0 0 2px rgba(0, 91, 211, 0.25);
}

.chip-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chip-entry input {
  flex: 1;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chips:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.4rem 0.2rem 0.7rem;
  border-radius: 999px;
  background: var(--p-bg);
  border: 1px solid var(--p-border);
  font-size: 0.8125rem;
  color: var(--p-text);
}

.chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--p-text-subdued);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}

.chip button:hover {
  background: var(--p-border);
  color: var(--p-text);
}

s-banner {
  display: block;
  margin-top: 1rem;
}

/* ---------- Sync health card ---------- */

.alert {
  display: grid;
  grid-template-columns: auto 1fr auto;
  /* Aligned on the title, not on the card: the icon must sit next to the
     first line whether the card is one, two or four lines tall. */
  align-items: start;
  gap: 0.25rem 0.85rem;
  margin-bottom: 1rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--p-radius);
  border: 1px solid #f2c9c4;
  background: #fef6f5;
  color: #b3261e;
}

.alert-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
  flex: none;
  margin-top: 0.1rem;
}

.alert-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.alert-body strong {
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--p-text);
}

.alert-body span {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--p-text-subdued);
}

.alert-action {
  justify-self: end;
  align-self: center;
  white-space: nowrap;
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  color: #b3261e;
  background: var(--p-surface);
  border: 1px solid #e5b4ae;
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
}

.alert-action:hover {
  border-color: #b3261e;
}

@media (max-width: 34rem) {
  .alert {
    grid-template-columns: auto 1fr;
  }

  .alert-action {
    grid-column: 2;
    justify-self: start;
    margin-top: 0.6rem;
  }
}

/* ---------- Activity journal ---------- */

.activity {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
}

.activity li {
  display: grid;
  grid-template-columns: 0.85rem 4.5rem 1fr auto;
  align-items: baseline;
  gap: 0 0.75rem;
  padding: 0.7rem 0;
  border-top: 1px solid var(--p-border);
}

.activity li:first-child {
  border-top: none;
}

.activity .dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
  background: #b5b5b5;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  transform: translateY(0.1rem);
}

/* Light, friendly fills: the level is spelled out next to them, so the
   colour is a cue, not the message. */
.activity li[data-tone="success"] .dot {
  background: #79d3a5;
}

.activity li[data-tone="info"] .dot {
  background: #8fbdf0;
}

.activity li[data-tone="warning"] .dot {
  background: #f5c96b;
}

.activity li[data-tone="critical"] .dot {
  background: #f09b8d;
}

.activity .level {
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--p-text-subdued);
}

.activity li[data-tone="success"] .level {
  color: #0c5132;
}

.activity li[data-tone="info"] .level {
  color: #1f5199;
}

.activity li[data-tone="warning"] .level {
  color: #7a5800;
}

.activity li[data-tone="critical"] .level {
  color: #8e1f0b;
}

.activity .title {
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--p-text);
}

.activity .detail {
  grid-column: 3 / 5;
  font-size: 0.8125rem;
  color: var(--p-text-subdued);
  margin-top: 0.15rem;
}

.activity .when {
  font-size: 0.75rem;
  color: var(--p-text-subdued);
  white-space: nowrap;
}

.activity .support {
  grid-column: 3 / 5;
  justify-self: start;
  margin-top: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 550;
  color: var(--p-focus);
  text-decoration: none;
  border: 1px solid var(--p-border);
  border-radius: 8px;
  padding: 0.3rem 0.7rem;
  background: var(--p-surface);
}

.activity .support:hover {
  border-color: var(--p-focus);
}

.pager {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.pager s-text {
  font-size: 0.8125rem;
  color: var(--p-text-subdued);
}

[hidden] {
  display: none !important;
}

/* ---------- Motion ---------- */

.reveal {
  animation: rise 260ms ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .reveal,
  s-spinner:not(:defined) {
    animation: none;
  }
}

/* Setup guide — shown once, on a fresh install. */
.setup-steps {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.setup-step {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.setup-step > div {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.setup-step span {
  color: #616161;
}

/* The mark is a circle either way: an empty one reads as "not yet",
   where a missing one would read as a rendering glitch. */
.setup-mark {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  border: 2px solid #c9cccf;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  line-height: 1;
  color: transparent;
}

.setup-step.done .setup-mark {
  background: #0e7c4a;
  border-color: #0e7c4a;
  color: #ffffff;
}

.setup-step.done strong {
  color: #616161;
  text-decoration: line-through;
}
