/* tech2 components — cards, buttons, forms, sheets, toasts, skeletons. */

/* ---------- Icons ----------
   Every icon() call emits .ico. An SVG with only a viewBox and no width/height
   renders at the default 300x150 replaced-element size, so a single missing rule
   turns into a screen-filling glyph. This is the floor that prevents that;
   component rules below override it where a different size is wanted. */

.ico {
  width: var(--icon-md);
  height: var(--icon-md);
  flex: none;
}

/* Disclosure chevron on tappable rows. */
.chev {
  width: 17px;
  height: 17px;
  flex: none;
  color: var(--text-faint);
}

/* ---------- Layout helpers ---------- */

.stack { display: flex; flex-direction: column; }
.row   { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.grow  { flex: 1 1 auto; min-width: 0; }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }

.container {
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--s-4);
}

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.t-xs { font-size: var(--text-xs); }
.t-sm { font-size: var(--text-sm); }
.t-lg { font-size: var(--text-lg); }
.w-semi { font-weight: var(--weight-semi); }
.w-bold { font-weight: var(--weight-bold); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Section header ---------- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-2);
}
.section-head h2 {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ---------- Card ---------- */

.card {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card + .card { margin-top: var(--s-3); }
.card-pad { padding: var(--s-4); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3) var(--s-4);
  min-height: var(--tap-min);
  text-align: left;
}
.card-head h3 { font-size: var(--text-md); font-weight: var(--weight-semi); }
.card-head .chev { transition: transform var(--dur-base) var(--ease-out); }
.card-head[aria-expanded="true"] .chev { transform: rotate(90deg); }
.card-body { padding: 0 var(--s-4) var(--s-4); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--tap-min);
  padding: 0 var(--s-5);
  border-radius: var(--r-sm);
  font-size: var(--text-md);
  font-weight: var(--weight-semi);
  background: var(--surface-alt);
  color: var(--text);
  transition: transform var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.975); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn .ico { width: 18px; height: 18px; }

.btn-primary { background: var(--accent); color: var(--white); }
.btn-success { background: var(--ok);     color: var(--white); }
.btn-danger  { background: var(--danger); color: var(--white); }
.btn-ghost   { background: transparent;   color: var(--accent-text); }
.btn-outline {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 50px; font-size: var(--text-lg); border-radius: var(--r-md); }
.btn-sm { min-height: 34px; padding: 0 var(--s-3); font-size: var(--text-sm); border-radius: var(--r-xs); }
.btn-sm .ico { width: 15px; height: 15px; }
.btn-icon { width: var(--tap-min); padding: 0; border-radius: var(--r-full); }

/* Sticky primary action, pinned above the tab bar. */
.action-dock {
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
  display: flex;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4) calc(var(--s-3) + var(--sab));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

/* ---------- Pills / badges ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px var(--s-2);
  border-radius: var(--r-full);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill-danger  { background: var(--danger-soft); color: var(--danger-text); }
.pill-warn    { background: var(--warn-soft);   color: var(--warn-text); }
.pill-ok      { background: var(--ok-soft);     color: var(--ok-text); }
.pill-info    { background: var(--accent-soft); color: var(--accent-text); }
.pill-neutral { background: var(--surface-alt); color: var(--text-dim); }

.count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--surface-alt);
  color: var(--text-dim);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

/* ---------- Segmented control ---------- */

.segmented {
  display: flex;
  gap: var(--s-1);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 max(var(--s-3), var(--sar)) var(--s-2) max(var(--s-3), var(--sal));
  scroll-snap-type: x proximity;
}
.segmented::-webkit-scrollbar { display: none; }

.segment {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 32px;
  padding: 0 var(--s-3);
  border-radius: var(--r-full);
  background: rgb(255 255 255 / 14%);
  color: rgb(255 255 255 / 78%);
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  white-space: nowrap;
  scroll-snap-align: center;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.segment[aria-selected="true"] { background: var(--white); color: var(--blue-700); }
.segment .count { background: rgb(0 0 0 / 18%); color: inherit; }
.segment[aria-selected="true"] .count { background: var(--blue-100); color: var(--blue-700); }

/* Red Flags segment reads as urgent even when unselected. */
.segment[data-seg="high_priority"][aria-selected="false"] { color: #ffc4c8; }
.segment[data-seg="high_priority"][aria-selected="true"] { background: var(--white); color: var(--red-600); }
.segment[data-seg="high_priority"][aria-selected="true"] .count { background: var(--red-100); color: var(--red-600); }

/* ---------- Search ---------- */

.search {
  position: relative;
  padding: 0 max(var(--s-3), var(--sar)) var(--s-2) max(var(--s-3), var(--sal));
}
.search input {
  width: 100%;
  min-height: 36px;
  padding: 0 var(--s-3) 0 var(--s-8);
  border: 0;
  border-radius: var(--r-sm);
  background: rgb(255 255 255 / 16%);
  color: var(--white);
  /* 16px keeps iOS from zooming the viewport on focus. */
  font-size: 16px;
}
.search input::placeholder { color: rgb(255 255 255 / 60%); }
.search .search-icon {
  position: absolute;
  left: calc(max(var(--s-3), var(--sal)) + var(--s-3));
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: rgb(255 255 255 / 62%);
  pointer-events: none;
}

/* ---------- Form fields ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  color: var(--text-dim);
}
.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.field textarea { min-height: 120px; resize: vertical; line-height: var(--leading-normal); }
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field.invalid input,
.field.invalid textarea { border-color: var(--danger); }
.field .hint { font-size: var(--text-xs); color: var(--text-faint); }
.field .error { font-size: var(--text-xs); color: var(--danger-text); font-weight: var(--weight-medium); }
.error:empty { display: none; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: var(--tap-min);
  width: 100%;
  text-align: left;
}
.switch {
  flex: none;
  width: 50px;
  height: 30px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  position: relative;
  transition: background var(--dur-base) var(--ease-out);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: var(--r-full);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-base) var(--ease-spring);
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* ---------- List rows ---------- */

.rows {
  background: var(--surface);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.list-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 50px;
  padding: var(--s-2) var(--s-4);
  text-align: left;
  color: var(--text);
  background: var(--surface);
  transition: background var(--dur-fast) var(--ease-out);
}
.list-row + .list-row { box-shadow: inset 0 1px 0 var(--border); }
.list-row:active { background: var(--surface-sunk); }
.list-row .lead {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.list-row .lead .ico { width: 16px; height: 16px; }
.list-row .val { color: var(--text-dim); font-weight: var(--weight-semi); }

/* ---------- Empty & error states ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-12) var(--s-6);
  text-align: center;
  color: var(--text-dim);
}
.empty .ico { width: 40px; height: 40px; color: var(--border-strong); }
.empty h3 { font-size: var(--text-lg); font-weight: var(--weight-semi); color: var(--text); }
.empty p { font-size: var(--text-sm); max-width: 34ch; }

/* ---------- Banners ---------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}
.banner .ico { width: 18px; height: 18px; margin-top: 1px; }
.banner-danger { background: var(--danger-soft); color: var(--danger-text); }
.banner-warn   { background: var(--warn-soft);   color: var(--warn-text); }
.banner-info   { background: var(--accent-soft); color: var(--accent-text); }

/* Offline / pending-sync strip under the header. */
.netbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 4px var(--s-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  background: var(--warn);
  color: var(--gray-950);
}
.netbar .ico { width: 14px; height: 14px; }
.netbar[hidden] { display: none; }

/* ---------- Skeletons ----------
   Sized to match the real content so nothing shifts when data lands. */

.skel {
  background: var(--surface-alt);
  border-radius: var(--r-xs);
  position: relative;
  overflow: hidden;
}
.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 28%), transparent);
  animation: shimmer 1.4s infinite;
}
@media (prefers-reduced-motion: reduce) {
  .skel::after { animation: none; }
}
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}
.skel-line { height: 12px; }
.skel-line.short { width: 45%; }
.skel-line.med   { width: 70%; }

/* ---------- Pull to refresh ---------- */

.ptr {
  position: absolute;
  top: 0;
  left: 50%;
  translate: -50% 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--accent-text);
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-sticky);
}
.ptr .ico { width: 17px; height: 17px; }
.ptr.spinning .ico { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Scrim ---------- */

#scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-scrim);
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out);
}
#scrim.on { opacity: 1; pointer-events: auto; }

/* ---------- Bottom sheet ---------- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  max-height: 88dvh;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease-out);
  padding-bottom: var(--sab);
}
.sheet.on { transform: translateY(0); }
.sheet.dragging { transition: none; }

.sheet-grip {
  flex: none;
  padding: var(--s-2) 0 var(--s-1);
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}
.sheet-grip::before {
  content: "";
  width: 38px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--border-strong);
}
.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-4) var(--s-3);
}
.sheet-head h2 { font-size: var(--text-lg); font-weight: var(--weight-semi); }
.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--s-4) var(--s-5);
}

/* ---------- Toasts ---------- */

/* --tabbar-offset is toggled by shell.showTabs() so toasts sit just above the tab bar
   on the list, and just above the safe area on detail where the bar is hidden. */
#toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--sab) + var(--tabbar-offset, 0px) + var(--s-3));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: var(--s-2);
  padding-inline: var(--s-3);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  max-width: 420px;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: var(--gray-900);
  color: var(--gray-50);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  touch-action: pan-y;
  animation: toast-in var(--dur-slow) var(--ease-spring);
}
.toast.out { animation: toast-out var(--dur-base) var(--ease-out) forwards; }
.toast .ico { width: 19px; height: 19px; }
.toast .msg { flex: 1 1 auto; min-width: 0; }
.toast .act {
  flex: none;
  font-weight: var(--weight-bold);
  color: var(--blue-300);
  padding: var(--s-1) var(--s-2);
  margin: calc(var(--s-1) * -1) calc(var(--s-2) * -1);
}
.toast-success .ico { color: var(--green-500); }
.toast-error   .ico { color: #ff8b93; }
.toast-warn    .ico { color: var(--amber-500); }
.toast-info    .ico { color: var(--blue-300); }

@keyframes toast-in {
  from { transform: translateY(120%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateY(60%); opacity: 0; }
}
