/* Shared components. Uses tokens.css only. */

/* ---------- App header and nav ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.app-header .container {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: calc(var(--space) * 3);
}

.nav {
  display: flex;
  gap: calc(var(--space) * 0.5);
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  padding: var(--space) calc(var(--space) * 1.5);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: color var(--transition), background var(--transition);
}

.nav a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-2);
}

.header-user {
  display: flex;
  align-items: center;
  gap: calc(var(--space) * 1.5);
  margin-left: auto;
}

/* Phones: wordmark and sign-out on the first row, nav scrolls on its own row below. */
@media (max-width: 640px) {
  .app-header .container {
    flex-wrap: wrap;
    height: auto;
    row-gap: calc(var(--space) * 0.5);
    padding-block: var(--space);
  }

  .nav {
    order: 3;
    flex-basis: 100%;
    margin-inline: calc(var(--space) * -1.5);
  }

  .header-user .chip {
    display: none;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space);
  min-height: 44px;
  padding: 0 calc(var(--space) * 2.5);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--text-md);
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 85%, white);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}

.btn-sm {
  min-height: 34px;
  padding: 0 calc(var(--space) * 1.5);
  font-size: var(--text-sm);
}

.btn-block {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--space) * 1.5);
}

/* Spinner shown inside a busy button */
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 700ms linear infinite;
}

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

/* ---------- Forms ---------- */
.form > * + * {
  margin-top: calc(var(--space) * 2);
}

.form .btn-block {
  margin-top: calc(var(--space) * 3);
}

.field {
  display: flex;
  flex-direction: column;
  gap: calc(var(--space) * 0.75);
}

.field-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space);
}

.field label {
  font-size: var(--text-sm);
  font-weight: 500;
}

.field-label-row a {
  font-size: var(--text-sm);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: calc(var(--space) * 1.25) calc(var(--space) * 1.5);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-md); /* 16px stops iOS zooming on focus */
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input::placeholder {
  color: color-mix(in srgb, var(--text-muted) 70%, transparent);
}

.input:hover {
  border-color: color-mix(in srgb, var(--text-muted) 50%, var(--border));
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

textarea.input {
  min-height: 96px;
  resize: vertical;
}

.input-wrap {
  position: relative;
}

.input-wrap .input {
  padding-right: 72px;
}

.input-wrap .input-action {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
}

.field-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.field-error {
  font-size: var(--text-sm);
  color: var(--danger);
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: calc(var(--space) * 3);
}

@media (max-width: 480px) {
  .card {
    padding: calc(var(--space) * 2.5);
  }
}

.card-title {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space);
}

.stat {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  line-height: 1.1;
}

/* Key / value rows, e.g. client ID */
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space) calc(var(--space) * 3);
  margin: 0;
}

.kv dt {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.kv dd {
  margin: 0;
}

/* ---------- Alerts (inline messages) ---------- */
.alert {
  --tone: var(--info);
  padding: calc(var(--space) * 1.5) calc(var(--space) * 2);
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--tone) 40%, transparent);
  background: color-mix(in srgb, var(--tone) 10%, transparent);
  color: var(--text);
  font-size: var(--text-sm);
}

.alert-success { --tone: var(--success); }
.alert-warning { --tone: var(--warning); }
.alert-danger { --tone: var(--danger); }

.alert p:last-child {
  margin-bottom: 0;
}

.alert .btn-row {
  margin-top: calc(var(--space) * 1.5);
}

.card .alert {
  margin-bottom: calc(var(--space) * 2);
}

/* ---------- Chips and status badges ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--space) * 0.75);
  padding: calc(var(--space) * 0.5) var(--space);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.badge {
  --tone: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: calc(var(--space) * 0.75);
  padding: calc(var(--space) * 0.375) calc(var(--space) * 1.25);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  color: var(--tone);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-neutral { --tone: var(--text-muted); }
.badge-info { --tone: var(--info); }
.badge-accent { --tone: var(--accent); }
.badge-success { --tone: var(--success); }
.badge-warning { --tone: var(--warning); }
.badge-danger { --tone: var(--danger); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th,
.table td {
  padding: calc(var(--space) * 1.5) calc(var(--space) * 2);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover td {
  background: var(--surface);
}

.table .num {
  text-align: right;
  font-family: var(--font-mono);
}

/* ---------- Status timeline ---------- */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  position: relative;
  padding: 0 0 calc(var(--space) * 2.5) calc(var(--space) * 3.5);
}

.timeline li::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 8px;
  bottom: -8px;
  width: 1px;
  background: var(--border);
}

.timeline li:last-child::before {
  display: none;
}

.timeline li::after {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
}

.timeline li.is-current::after {
  border-color: var(--accent);
  background: var(--accent);
}

.timeline-date {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.timeline-note {
  margin: calc(var(--space) * 0.5) 0 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ---------- Copy button ---------- */
.copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--space) * 1.5);
  padding: calc(var(--space) * 1.25) calc(var(--space) * 1.5);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.copy-row .mono {
  overflow-wrap: anywhere;
}

/* ---------- Loading, empty and error states ---------- */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space);
  padding: calc(var(--space) * 6) calc(var(--space) * 2);
  color: var(--text-muted);
}

.state-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  color: var(--text);
}

.state-error .state-title {
  color: var(--danger);
}

.state .btn {
  margin-top: var(--space);
}

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  min-height: 1em;
}

.skeleton-text { height: 14px; width: 60%; }
.skeleton-title { height: 28px; width: 40%; }
.skeleton-block { height: 120px; width: 100%; }

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(var(--space) * 3);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space);
  width: min(420px, calc(100% - var(--space) * 4));
  pointer-events: none;
}

.toast {
  --tone: var(--accent);
  pointer-events: auto;
  padding: calc(var(--space) * 1.5) calc(var(--space) * 2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 3px solid var(--tone);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  font-size: var(--text-sm);
  animation: toast-in 180ms ease-out;
}

.toast-success { --tone: var(--success); }
.toast-warning { --tone: var(--warning); }
.toast-danger { --tone: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.copy-row-text {
  display: flex;
  flex-direction: column;
  gap: calc(var(--space) * 0.25);
  min-width: 0;
}

.copy-row-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.copy-list > * + * {
  margin-top: var(--space);
}

/* ---------- Checkboxes ---------- */
.check {
  display: flex;
  align-items: flex-start;
  gap: calc(var(--space) * 1.5);
  cursor: pointer;
}

.check input {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.check-text {
  display: flex;
  flex-direction: column;
  gap: calc(var(--space) * 0.25);
}

/* ---------- Stat tiles (e.g. order counts) ---------- */
.tiles {
  display: grid;
  gap: calc(var(--space) * 1.5);
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}

.tile {
  display: flex;
  flex-direction: column;
  gap: calc(var(--space) * 1);
  padding: calc(var(--space) * 2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--transition);
}

a.tile:hover {
  border-color: var(--text-muted);
}

.tile-count {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  line-height: 1;
}

/* ---------- Order list rows (work on phones without sideways scrolling) ---------- */
.order-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.order-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: calc(var(--space) * 0.5) calc(var(--space) * 2);
  align-items: center;
  padding: calc(var(--space) * 1.5) calc(var(--space) * 2);
  color: var(--text);
  text-decoration: none;
  transition: background var(--transition);
}

.order-row:hover {
  background: var(--surface);
}

.order-row-main {
  min-width: 0;
}

.order-row-desc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-row-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.order-row-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: calc(var(--space) * 0.5);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ---------- Filters bar ---------- */
.filters {
  display: grid;
  gap: calc(var(--space) * 1.5);
  grid-template-columns: 1fr minmax(160px, 220px);
  margin-bottom: calc(var(--space) * 2);
}

@media (max-width: 480px) {
  .filters {
    grid-template-columns: 1fr;
  }
}

/* ---------- Two-column page layout (main + side) ---------- */
.layout-split {
  display: grid;
  gap: calc(var(--space) * 2);
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: start;
}

@media (max-width: 820px) {
  .layout-split {
    grid-template-columns: 1fr;
  }
}

/* ---------- Item photo ---------- */
.photo {
  display: block;
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---------- Misc ---------- */
.back-link {
  display: inline-block;
  margin-bottom: calc(var(--space) * 2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: calc(var(--space) * 2);
  font-size: var(--text-sm);
}

.summary-row + .summary-row {
  margin-top: var(--space);
}

.amount-positive {
  color: var(--success);
}

.card + .card,
.section + .section {
  margin-top: calc(var(--space) * 2);
}

.grid + .section {
  margin-top: calc(var(--space) * 4);
}

.section-title {
  margin-bottom: calc(var(--space) * 1.5);
}

.card-actions {
  margin-top: calc(var(--space) * 3);
}

.page-alert {
  margin-bottom: calc(var(--space) * 2);
}

/* Quick-pick buttons with a second line (e.g. "25 credits" / "$49.75") */
.btn.pick {
  flex-direction: column;
  gap: calc(var(--space) * 0.25);
  min-height: 60px;
  padding-block: var(--space);
}
