/* The pieces every page is made of. Sized for a thumb first: nothing you tap is
 * smaller than 44px on a phone, and inputs are 16px so iOS does not zoom. */

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, filter 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--accent); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent-grad); color: var(--on-accent); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.quiet { border-color: transparent; color: var(--text-dim); }
.btn.quiet:hover { background: rgba(148, 163, 184, 0.08); color: var(--text); }
.btn.danger { color: var(--bad); border-color: rgba(255, 122, 138, 0.35); }
.btn.danger:hover { background: var(--bad-wash); border-color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #2a0409; border-color: transparent; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
@media (max-width: 899px) {
  .btn { min-height: var(--tap); }
  .btn.small { min-height: 36px; }
  .icon-btn { width: var(--tap); height: var(--tap); }
}

/* ------------------------------------------------------------------- blocks */
.page-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--gap-3);
  margin-bottom: var(--gap-4);
}
.page-head h1 { font-size: 20px; }
.page-head .sub { color: var(--text-faint); font-size: 13px; }
.page-head .grow { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--gap-4);
  margin-bottom: var(--gap-4);
}
.card-head { display: flex; align-items: center; gap: var(--gap-3); margin-bottom: var(--gap-3); flex-wrap: wrap; }
.card-head h2 { font-size: 15px; }
.card-head .grow { flex: 1; }
@media (max-width: 899px) { .card { padding: var(--gap-3); border-radius: var(--radius); } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--gap-3); margin-bottom: var(--gap-4); }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--gap-3) var(--gap-4);
  text-align: left;
  color: inherit;
  font: inherit;
}
button.tile { cursor: pointer; }
button.tile:hover { border-color: var(--line-strong); }
.tile-label { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.tile-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-value .second { display: block; font-size: 13px; color: var(--text-dim); font-weight: 600; }
.tile-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.tile.hot { border-color: var(--warn); }
.tile.hot .tile-value { color: var(--warn); }
@media (max-width: 899px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap-2); }
  .tile-value { font-size: 20px; }
}

.empty { padding: var(--gap-5) var(--gap-3); text-align: center; color: var(--text-faint); }
.hint { font-size: 12.5px; color: var(--text-dim); }
.hint.good { color: var(--good); }
.hint.warn { color: var(--warn); }
.hint.bad { color: var(--bad); }
.muted { color: var(--text-faint); }
.key { font-family: var(--mono); color: var(--accent-soft); font-size: 12px; white-space: nowrap; }

/* ------------------------------------------------------------ chips + badges */
.chips {
  display: flex;
  gap: var(--gap-2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  margin-bottom: var(--gap-3);
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  border-radius: 999px;
  padding: 0 13px;
  min-height: 32px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent-wash); border-color: var(--accent); color: var(--text); }
@media (max-width: 899px) { .chip { min-height: 38px; } }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-dim);
}
.badge.good { background: var(--good-wash); color: var(--good); }
.badge.warn { background: var(--warn-wash); color: var(--warn); }
.badge.bad { background: var(--bad-wash); color: var(--bad); }
.badge.accent { background: var(--accent-wash); color: var(--accent-soft); }

/* -------------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.field small { color: var(--text-faint); font-size: 11.5px; }
.input, .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line-strong);
  background: var(--input);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.field textarea { min-height: 84px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.input:disabled, .field input:disabled, .field select:disabled { opacity: 0.5; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap-3); }
.form .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.search { position: relative; }
.search input { padding-left: 36px !important; }
.search svg { position: absolute; left: 11px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.note-box {
  padding: 10px 12px;
  border-radius: var(--radius-s);
  border: 1px dashed var(--line-strong);
  color: var(--text-dim);
  font-size: 13px;
}
.note-box.good { border-color: rgba(110, 231, 163, 0.45); color: var(--good); }
.note-box.warn { border-color: rgba(252, 211, 77, 0.45); color: var(--warn); }
@media (max-width: 899px) {
  .input, .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea {
    font-size: 16px;
    min-height: var(--tap);
  }
  .form { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------- lists: table/cards */
.list-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.list-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.list-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr:hover { background: rgba(79, 159, 255, 0.05); }
.list-table td.right, .list-table th.right { text-align: right; }
.list-table td .line2 { display: block; font-size: 12px; color: var(--text-faint); margin-top: 2px; }

.list-cards { display: none; flex-direction: column; gap: var(--gap-2); }
.item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.item:active { background: var(--surface-2); }
.item-top { display: flex; align-items: flex-start; gap: var(--gap-2); }
.item-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.item-sub { margin-top: 3px; color: var(--text-dim); font-size: 13px; overflow-wrap: anywhere; }
.item-meta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12.5px; color: var(--text-faint); }
.item-meta b { color: var(--text-dim); font-weight: 600; }

@media (max-width: 899px) {
  .list-table { display: none; }
  .list-cards { display: flex; }
  .card.list-card { background: transparent; border: 0; padding: 0; }
}

.pager { display: flex; align-items: center; justify-content: center; gap: var(--gap-3); margin-top: var(--gap-3); flex-wrap: wrap; }
.pager .hint { min-width: 110px; text-align: center; }

/* ------------------------------------------------------------------- sheets */
.sheet-host { position: relative; z-index: 60; }
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 14, 0.62);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.18s;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  outline: none;
  /* A dialog in the middle of a wide screen. */
  left: 50%;
  top: 50%;
  width: min(560px, calc(100vw - 32px));
  max-height: min(86vh, 900px);
  border-radius: var(--radius-l);
  transform: translate(-50%, -48%) scale(0.98);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.sheet.open { transform: translate(-50%, -50%); opacity: 1; }
.sheet.wide { width: min(760px, calc(100vw - 32px)); }
/* A panel down the right-hand side, so the list stays in view beside it. */
.sheet.side {
  left: auto;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(520px, 100vw);
  max-height: none;
  border-radius: var(--radius-l) 0 0 var(--radius-l);
  transform: translateX(24px);
}
.sheet.side.open { transform: none; }
.sheet-handle { display: none; }
.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: var(--gap-3);
  padding: var(--gap-4) var(--gap-4) var(--gap-3);
  border-bottom: 1px solid var(--line);
}
.sheet-title { flex: 1; min-width: 0; }
.sheet-title h2 { font-size: 17px; overflow-wrap: anywhere; }
.sheet-title .sub { margin-top: 3px; color: var(--text-dim); font-size: 13px; overflow-wrap: anywhere; }
.sheet-body { padding: var(--gap-4); overflow-y: auto; overscroll-behavior: contain; flex: 1; }
.sheet-foot {
  display: flex;
  gap: var(--gap-2);
  justify-content: flex-end;
  padding: var(--gap-3) var(--gap-4);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.sheet-foot .grow { flex: 1; }
.sheet-status { padding: 0 var(--gap-4) var(--gap-3); }
.sheet-status:empty { display: none; }

/* A phone: the same sheet comes up from the bottom and can be swiped away. */
@media (max-width: 899px) {
  .sheet, .sheet.wide, .sheet.side {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    transform: translateY(100%);
    opacity: 1;
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .sheet.open, .sheet.side.open { transform: translateY(0); }
  .sheet.dragging { transition: none; }
  .sheet-handle { display: block; padding: 8px 0 0; touch-action: none; cursor: grab; }
  .sheet-handle::before { content: ''; display: block; width: 42px; height: 5px; margin: 0 auto; border-radius: 3px; background: var(--line-strong); }
  .sheet-head { padding-top: var(--gap-2); touch-action: none; }
  .sheet-body { padding: var(--gap-3) var(--gap-4); }
  .sheet-foot { padding: var(--gap-3) var(--gap-4) calc(var(--gap-3) + env(safe-area-inset-bottom)); }
  .sheet-foot { flex-wrap: nowrap; }
  .sheet-foot .btn { flex: 1; min-width: 0; white-space: normal; text-align: center; line-height: 1.25; padding-top: 6px; padding-bottom: 6px; }
  .sheet-foot .btn.quiet { flex: 0 0 auto; }
  .sheet-foot .grow { display: none; }
}

/* ---------------------------------------------------------- inside a sheet */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 0; font-size: 14px; }
.facts dt { color: var(--text-faint); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.section-title {
  margin: var(--gap-5) 0 var(--gap-2);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.section-title:first-child { margin-top: 0; }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap-2); }
.action-grid .btn { justify-content: flex-start; }
.rows { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .line2 { display: block; color: var(--text-faint); font-size: 12px; }
.quick { display: flex; flex-wrap: wrap; gap: var(--gap-2); margin-bottom: var(--gap-3); }

/* ------------------------------------------------------------------- toasts */
.toasts {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: calc(var(--gap-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--gap-2);
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
@media (max-width: 899px) { .toasts { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); } }
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: toast-in 0.18s ease;
}
.toast.good { border-color: rgba(110, 231, 163, 0.5); }
.toast.bad { border-color: rgba(255, 122, 138, 0.5); }
.toast .grow { flex: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.skeleton {
  height: 60px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
  margin-bottom: var(--gap-2);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
