/* Shared pieces (lib/ui.js draws them): buttons, type labels, chips, the segmented control, cards,
   fields and switches, skeletons, empty and error cards, external links, the sheet, the menu, the
   undo bar and "Saved". Every tap target is at least 44 by 44 px. Area styles live in their own files. */

/* ---------- Buttons ---------- */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font: 600 13px/1 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
}
.btn .icon {
  width: 18px;
  height: 18px;
}
.btn.primary {
  background: var(--jade);
  border-color: var(--jade);
  color: #fff;
}
/* Hover only where a pointer hovers: on a phone it would stick after a tap. */
@media (hover: hover) {
  .btn.primary:hover {
    background: var(--jade-deep);
    border-color: var(--jade-deep);
  }
  .menu-item:hover {
    background: var(--inset);
  }
}
.btn.wide {
  width: 100%;
}
.btn.quiet {
  border-color: transparent;
  background: none;
  color: var(--jade-deep);
  letter-spacing: 0.02em;
  text-transform: none;
  font-size: 15px;
}
.btn.good {
  background: var(--sage-soft);
  border-color: var(--sage-line);
  color: var(--fern);
}
.btn.danger {
  border-color: transparent;
  background: none;
  color: var(--crak);
  letter-spacing: 0.02em;
  text-transform: none;
  font-size: 15px;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
.link-btn {
  min-height: var(--tap);
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--jade-deep);
  font: 500 16px var(--sans);
}

/* ---------- Type labels (section 3.0 table) ---------- */
.label {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  font: 600 12px/1 var(--sans);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.t-bug {
  background: #f8e1d8;
  color: #8f4630;
}
.t-idea {
  background: #e5ebfa;
  color: #4a5e9c;
}
.t-email {
  background: #f6f0e5;
  color: #615a66;
  box-shadow: inset 0 0 0 1px var(--line-soft);
}
.t-tile {
  background: #ece6f7;
  color: #5b4a94;
}
.t-review {
  background: #f3e8d2;
  color: #86652f;
}
.t-report {
  background: #f7e3e5;
  color: #7e3c4b;
}
.t-alert {
  background: #fbe7e5;
  color: #a3201a;
}
.t-change {
  background: #e4ece0;
  color: #4f6b55;
}
.t-plain {
  background: var(--inset);
  color: var(--ink-soft);
}

/* ---------- Chips: 44 px targets around 36 px faces ---------- */
.chips {
  display: flex;
  gap: 8px;
  margin: 6px calc(-1 * var(--pad)) 0 0;
  padding-right: var(--pad);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 48px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 48px), transparent);
}
.chips::-webkit-scrollbar {
  display: none;
}
.chips.wrap {
  flex-wrap: wrap;
  gap: 0 8px;
  margin-right: 0;
  padding-right: 0;
  overflow: visible;
  -webkit-mask-image: none;
  mask-image: none;
}
.chip {
  flex: none;
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  text-decoration: none;
  color: var(--ink);
}
.chip-face {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--paper);
  font: 500 14px var(--sans);
  white-space: nowrap;
}
.chip small,
.seg-item small {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
  font-variant-numeric: lining-nums tabular-nums;
}
.chip[aria-current] .chip-face,
.chip[aria-pressed="true"] .chip-face {
  background: var(--jade-soft);
  border-color: var(--jade);
  color: var(--jade-ink);
  font-weight: 600;
}
.chip[aria-current] small,
.chip[aria-pressed="true"] small {
  color: var(--jade-ink);
}

/* ---------- Segmented control: 40 px visual, 44 px targets ---------- */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: 40px;
  padding: 0 3px;
  border-radius: 12px;
  background: var(--inset);
  border: 1px solid var(--line-soft);
}
.seg-item {
  height: var(--tap);
  margin: -3px 0;
  padding: 0;
  display: flex;
  align-items: center;
  border: 0;
  background: none;
  color: var(--ink-soft);
  text-decoration: none;
  min-width: 0;
}
.seg-item-face {
  width: 100%;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 9px;
  font: 500 14px var(--sans);
  white-space: nowrap;
}
.seg-item[aria-current] .seg-item-face,
.seg-item[aria-pressed="true"] .seg-item-face {
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(46, 42, 51, 0.08);
}

/* ---------- Cards and text ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
}
.card + .card {
  margin-top: 12px;
}
.card h2 {
  font-size: 22px;
}
.sub {
  font-size: var(--text-2);
  line-height: 1.45;
  color: var(--ink-soft);
}
.fine {
  font-size: var(--text-meta);
  line-height: 1.45;
  color: var(--ink-soft);
}

/* ---------- Fields and switches ---------- */
.field {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--field-line);
  border-radius: var(--radius-row);
  background: var(--paper);
  font: 400 16px var(--sans);
  color: var(--ink);
}
textarea.field {
  padding: 10px 14px;
  line-height: 1.45;
  resize: none;
}
.field::placeholder {
  color: var(--ink-faint);
}
/* One clear focus mark for fields (border and a soft ring), not the outline on top of the border. */
.field:focus {
  outline: none;
  border-color: var(--jade);
  box-shadow: 0 0 0 3px var(--jade-soft);
}
/* Search fields draw no browser clear button: the row has its own Cancel. */
input[type="search"].field {
  -webkit-appearance: none;
  appearance: none;
}
input[type="search"].field::-webkit-search-cancel-button,
input[type="search"].field::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  cursor: pointer;
}
.switch input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 13px;
  background: #d9cdb4;
  position: relative;
  transition: background 0.15s;
}
.switch input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(46, 42, 51, 0.2);
  transition: transform 0.15s;
}
.switch input:checked {
  background: var(--fern);
}
.switch input:checked::before {
  transform: translateX(18px);
}

/* ---------- Skeletons ---------- */
.sk-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sk {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: var(--skeleton);
  animation: sk-pulse 1.4s ease-in-out infinite;
}
.sk-tag {
  width: 70px;
  height: 20px;
}
.sk-mid {
  width: 72%;
  height: 15px;
}
.sk-line {
  width: 88%;
}
.sk-short {
  width: 42%;
}
.sk-head {
  width: 40%;
  height: 18px;
}
.sk-title {
  width: 75%;
  height: 26px;
}
.sk-big {
  width: 60%;
  height: 34px;
}
.sk-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0 14px;
  border-bottom: 1px solid var(--line-soft);
}
.sk-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: var(--pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}
.sk-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@keyframes sk-pulse {
  50% {
    opacity: 0.55;
  }
}

/* ---------- Empty, error and still-loading cards ---------- */
.state-card {
  margin-top: 8px;
  padding: 22px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  text-align: center;
}
.state-title {
  font-size: 22px;
}
.state-line {
  margin-top: 6px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-soft);
}
.state-card .btn {
  margin-top: 16px;
}

/* ---------- External links (section 6.8) ---------- */
.ext {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: var(--tap);
  color: var(--jade-deep);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
.ext-mark {
  width: 15px;
  height: 15px;
  flex: none;
}

/* ---------- Sheet (covers only Backstage's frame, section 6.4) ---------- */
.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 40;
}
.scrim {
  position: absolute;
  inset: 0;
  background: rgba(46, 42, 51, 0.32);
  opacity: 0;
  transition: opacity 0.18s ease;
}
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--bottom-space);
  border-radius: 20px 20px 0 0;
  background: var(--canvas);
  box-shadow: 0 -8px 30px rgba(46, 42, 51, 0.12);
  transform: translateY(100%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet:focus {
  outline: none;
}
.sheet-wrap.open .scrim {
  opacity: 1;
}
.sheet-wrap.open .sheet {
  transform: none;
}
.sheet-wrap.closing .scrim {
  opacity: 0;
}
.sheet-wrap.closing .sheet {
  transform: translateY(100%);
}
.grab {
  flex: none;
  width: 40px;
  height: 5px;
  margin: 8px auto 0;
  border-radius: 3px;
  background: #d9cdb4;
}
.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  padding: 2px 4px 2px var(--pad);
}
.sheet-title {
  font-size: 24px;
}
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--pad) var(--pad);
}
.sheet-foot {
  flex: none;
  padding: 12px var(--pad);
  border-top: 1px solid var(--line);
  background: var(--bar);
}
@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(560px, calc(100% - 48px));
    max-height: 84%;
    padding-bottom: 0;
    border-radius: var(--radius);
    box-shadow: 0 18px 50px rgba(46, 42, 51, 0.18);
    transform: translate(-50%, -46%);
    opacity: 0;
    transition:
      transform 0.18s ease,
      opacity 0.18s ease;
  }
  .sheet-wrap.open .sheet {
    transform: translate(-50%, -50%);
    opacity: 1;
  }
  .sheet-wrap.closing .sheet {
    transform: translate(-50%, -46%);
    opacity: 0;
  }
  .grab {
    display: none;
  }
  .sheet-head {
    padding-top: 10px;
  }
}

/* ---------- Menu (More) ---------- */
.menu-list {
  display: flex;
  flex-direction: column;
  margin: 0 calc(-1 * var(--pad));
  border-top: 1px solid var(--line-soft);
}
.menu-item {
  min-height: 56px;
  padding: 0 var(--pad);
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: none;
  text-align: left;
  font: 500 16px var(--sans);
  color: var(--ink);
}
.menu-item:last-child {
  border-bottom: 0;
}
.menu-item.danger {
  color: var(--crak);
}

/* ---------- Undo bar (section 3.0.1) ---------- */
.undo-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--bottom-space);
  z-index: 50;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 0 var(--pad);
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  transform: translateY(calc(100% + var(--bottom-space)));
  transition: transform 0.2s ease;
}
.undo-bar.open {
  transform: none;
}
.undo-bar.closing {
  transform: translateY(calc(100% + var(--bottom-space)));
}
.undo-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.undo-btn {
  flex: none;
  min-width: 64px;
  min-height: var(--tap);
  padding: 0 12px;
  border: 0;
  background: none;
  color: #fff;
  font: 600 15px var(--sans);
  text-decoration: underline;
  text-underline-offset: 3px;
}
@media (min-width: 720px) {
  .undo-bar {
    left: auto;
    right: 24px;
    bottom: 24px;
    width: 420px;
    border-radius: var(--radius-row);
    box-shadow: 0 8px 24px rgba(46, 42, 51, 0.2);
    transform: translateY(calc(100% + 32px));
  }
  .undo-bar.closing {
    transform: translateY(calc(100% + 32px));
  }
}

/* ---------- Saved ---------- */
.saved {
  margin-left: 8px;
  color: var(--fern);
  font-size: var(--text-2);
  font-weight: 600;
}

/* ---------- Common text blocks ---------- */
.detail-title {
  font-size: 24px;
  line-height: 1.2;
}
.detail-title + .sub {
  margin-top: 6px;
}
.foot-line {
  margin-top: 24px;
  text-align: center;
}
.link-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 20px;
  margin-top: 4px;
}
