/* Lift Tracker — iPhone-first, dark, large targets, safe areas */
:root {
  --bg: #0b0d10;
  --bg-elev: #14181d;
  --bg-card: #1b2026;
  --bg-card-hover: #222830;
  --line: #2c333c;
  --line-strong: #3a434e;
  --text: #f3f0e8;
  --muted: #9aa3ad;
  --faint: #6d767f;
  --accent: #e8b86d;
  --accent-ink: #1a140c;
  --accent-dim: #3a2f1c;
  --ready: #c6e89a;
  --ready-bg: #1b2a14;
  --ready-ink: #d7f0b0;
  --danger: #e8948c;
  --danger-bg: #2a1614;
  --chip: #262c34;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --radius-sm: 12px;
  --header-h: 56px;
  --tab-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --touch: 48px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100%;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
img { display: block; max-width: 100%; }
a { color: var(--accent); }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-h);
  padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--line);
}
.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-header .sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 1px;
}
.icon-btn {
  min-width: var(--touch);
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 0 12px;
  gap: 6px;
}
.icon-btn:active { background: var(--bg-card); }

#view {
  flex: 1;
  padding: 12px 16px 24px;
}

.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #101318;
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--tab-h) + var(--safe-bottom));
}
.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  min-height: var(--tab-h);
}
.tab-btn svg { width: 22px; height: 22px; }
.tab-btn.active { color: var(--accent); }
.tab-btn:active { background: var(--bg-elev); }

/* Cards */
.card-list { display: flex; flex-direction: column; gap: 12px; }
.machine-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.machine-card .card-main {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  padding: 12px;
  text-align: left;
  width: 100%;
  color: inherit;
}
.machine-card .thumb {
  width: 88px;
  height: 88px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--bg-elev);
}
.machine-card .name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}
.machine-card .maker {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 8px;
}
.machine-card .meta {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: baseline;
}
.machine-card .weight { color: var(--text); }
.machine-card .when { color: var(--muted); font-weight: 500; font-size: 13px; }
.machine-card .sets-line { color: var(--text); font-weight: 600; width: 100%; }
.empty-val { color: var(--faint); font-weight: 500; }
.badge-ready {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--ready-bg);
  color: var(--ready-ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.card-actions {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
}
.btn {
  min-height: var(--touch);
  padding: 0 16px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  flex: 1;
}
.btn-primary:active { filter: brightness(0.95); }
.btn-secondary {
  background: var(--chip);
  color: var(--text);
  border-color: var(--line);
}
.btn-secondary:active { background: var(--bg-card-hover); }
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #4a2a26;
}
.btn-ghost { color: var(--muted); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

/* Forms */
.field { margin-bottom: 14px; }
.field label, .label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
input[type="text"], input[type="number"], input[type="date"], input[type="search"],
select, textarea {
  width: 100%;
  min-height: var(--touch);
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 16px; /* prevent iOS zoom */
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
}
textarea { min-height: 88px; resize: vertical; }
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%239aa3ad' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.hint { font-size: 13px; color: var(--faint); margin-top: 6px; }

.stepper {
  display: grid;
  grid-template-columns: var(--touch) 1fr var(--touch);
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
}
.stepper button {
  min-width: var(--touch);
  min-height: var(--touch);
  font-size: 22px;
  font-weight: 500;
  color: var(--accent);
}
.stepper button:active { background: var(--accent-dim); }
.stepper input {
  border: 0;
  background: transparent;
  text-align: center;
  min-height: var(--touch);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 20px;
  padding: 0;
  border-radius: 0;
}
.stepper input:focus { outline: none; }
.unit-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
}
.unit-toggle button {
  min-height: var(--touch);
  font-weight: 700;
  color: var(--muted);
}
.unit-toggle button.on {
  background: var(--accent);
  color: var(--accent-ink);
}

.set-row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.set-row .set-label {
  font-weight: 650;
  color: var(--muted);
  font-size: 14px;
}
.set-row .remove-set {
  min-width: var(--touch);
  min-height: var(--touch);
  color: var(--danger);
  font-size: 20px;
}

.suggestions, .model-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.chip:active, .chip.on {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Detail */
.hero {
  margin: -12px -16px 16px;
  position: relative;
  background: var(--bg-elev);
}
.hero img {
  width: 100%;
  height: 156px;
  object-fit: cover;
}
.hero .back {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(11, 13, 16, 0.7);
  backdrop-filter: blur(8px);
  color: var(--text);
  border-radius: 12px;
}
.detail-title { font-size: 24px; font-weight: 750; letter-spacing: -0.03em; margin: 0 0 4px; }
.detail-sub { color: var(--muted); margin: 0 0 4px; }
.detail-mus { color: var(--accent); font-size: 14px; font-weight: 600; margin: 0 0 16px; }
.section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 8px;
}

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}
.history-item .hi-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.history-item .hi-date { font-weight: 700; }
.history-item .hi-weight { font-weight: 700; color: var(--accent); }
.history-item .hi-sets { margin-top: 4px; color: var(--text); }
.history-item .hi-note { margin-top: 6px; color: var(--muted); font-size: 14px; }
.history-item .hi-actions { display: flex; gap: 8px; margin-top: 8px; }
.history-item .hi-actions .btn { min-height: 40px; flex: 0; padding: 0 12px; font-size: 14px; }

/* Date groups (free weights) */
.date-group { margin-bottom: 18px; }
.date-group h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

/* Sheet / modal */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay.center { align-items: center; padding: 24px; }
.sheet {
  width: 100%;
  max-height: min(92dvh, 780px);
  overflow: auto;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow);
}
.sheet .grab {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--line-strong); margin: 4px auto 12px;
}
.sheet h2, .modal h2 { margin: 0 0 14px; font-size: 20px; }
.modal {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal p { color: var(--muted); margin: 0 0 16px; }

/* Photo picker */
.photo-preview {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 12px;
  background: var(--bg-elev);
  margin-bottom: 8px;
}
.file-btn input { display: none; }

/* Empty / status */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 8px; }

.unit-note { font-size: 11px; color: var(--faint); font-weight: 500; }

.target-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.catalog-results {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 8px;
  background: var(--bg-elev);
}
.catalog-item {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  display: block;
}
.catalog-item:last-child { border-bottom: 0; }
.catalog-item:active, .catalog-item.on { background: var(--accent-dim); }
.catalog-item .ci-name { font-weight: 700; }
.catalog-item .ci-meta { font-size: 13px; color: var(--muted); }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0,0,0,0);
}

.toast {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px);
  z-index: 60;
  background: var(--bg-card);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.hero .back { display: none; }
.history-item { scroll-margin-bottom: 88px; }


.menu {
  position: absolute;
  right: 12px;
  top: calc(var(--safe-top) + 52px);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 40;
  min-width: 200px;
}
.menu button {
  width: 100%;
  text-align: left;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  font-weight: 600;
}
.menu button:active { background: var(--bg-elev); }

.unknown-tag {
  font-size: 11px;
  color: var(--faint);
  font-weight: 500;
}
