/* ── Reset & Variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --accent: #f0c040;
  --accent-glow: rgba(240, 192, 64, 0.3);
  --teal: #14b8a6;
  --teal-glow: rgba(20, 184, 166, 0.35);
  --red: #f85149;
  --text: #e6edf3;
  --muted: #8b949e;
  --radius: 12px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Layout ── */
.app {
  display: flex;
  flex-direction: column;
  max-width: 900px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px;
  gap: 16px;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.app-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 12px;
}

.team-logo {
  width: 48px;
  height: 48px;
  fill: var(--accent);
}

.sync-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sync-controls input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  width: 260px;
  transition: border-color 0.2s;
}

.sync-controls input:focus {
  border-color: var(--accent);
}

.sync-status-global {
  text-align: right;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
  margin-top: -12px;
  padding-right: 8px;
}

.btn-primary {
  background: var(--accent);
  color: #111;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.8; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--border); }

/* ── Main Content ── */
.app-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cards-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

@media (max-width: 600px) {
  .cards-container {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h2 {
  font-size: 1.1rem;
  color: var(--teal);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.input-group label {
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input-group input, .input-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%;
}

.input-group input:focus:not([readonly]), .input-group select:focus:not([disabled]) {
  border-color: var(--accent);
}

.input-group input[readonly], .input-group select[disabled] {
  background: var(--surface);
  color: var(--muted);
  cursor: default;
}

.split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sub-result {
  margin-top: 10px;
  padding: 12px;
  background: var(--surface2);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
}

.highlight-dots strong {
  color: var(--accent);
}

/* ── Result Panel ── */
.result-panel {
  background: var(--surface);
  border: 2px solid var(--teal);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  box-shadow: 0 0 20px var(--teal-glow);
}

.result-panel h2 {
  color: var(--teal);
  margin-bottom: 16px;
  font-size: 1.4rem;
}

.target-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 20px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-box span {
  font-size: 0.9rem;
  color: var(--muted);
}

.stat-box strong {
  font-size: 1.3rem;
  color: var(--text);
}

.target-split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.final-target {
  background: #111815;
  border: 1px solid #2ea043;
  padding: 16px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.final-target .target-label {
  font-size: 1rem;
  color: #3fb950;
  font-weight: bold;
}

.final-target .target-weight {
  font-size: 2.2rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 10px rgba(63, 185, 80, 0.5);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}

.final-target .target-weight .unit {
  font-size: 1.2rem;
  font-weight: 700;
  opacity: 0.8;
}

.target-sub-info {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 4px;
}

.target-sub-info strong {
  color: var(--text);
  font-weight: 700;
}

.target-sub-info .divider {
  color: var(--border);
}

.final-target.fail-target {
  background: #1a1010;
  border-color: #d73a49;
}

.final-target.fail-target .target-label {
  color: #ff7b72;
}

.final-target.fail-target .target-weight {
  text-shadow: 0 0 10px rgba(248, 81, 73, 0.5);
}

.final-target.inactive {
  background: var(--surface2);
  border-color: var(--border);
  opacity: 0.4;
  filter: grayscale(100%);
}

.target-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-box h2 {
  color: var(--text);
}

.hint-text {
  font-size: 0.9rem;
  color: var(--muted);
}

.modal-box input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 6px;
  font-size: 1rem;
  outline: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.sync-status {
  font-size: 0.85rem;
  color: var(--accent);
  text-align: center;
  min-height: 1.2em;
}

/* ── Performance Summary ── */
.performance-summary {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
  margin-top: 8px;
}

.performance-summary .lift-table {
  background: transparent;
  padding: 0;
  margin-bottom: 0;
  border-radius: 0;
}

.performance-summary .sub-result {
  background: var(--surface);
  border: 1px solid var(--border);
  margin-top: 0;
}

/* ── Lifts Table ── */
.lift-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface2);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.lift-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 1fr 45px;
  gap: 6px;
  align-items: center;
}

.lift-row.header {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 4px;
}

.lift-row.header span:first-child { text-align: left; }
.lift-row.header span:last-child { text-align: right; }

.lift-name {
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--muted);
}

.attempt-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 6px 4px;
  font-size: 0.85rem;
  text-align: center;
  outline: none;
  transition: all 0.2s;
  /* Hide arrows */
  -moz-appearance: textfield;
}

.attempt-input::-webkit-outer-spin-button,
.attempt-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.attempt-input:focus:not([readonly]) {
  border-color: var(--accent);
}

.attempt-input[readonly] {
  cursor: default;
}

.attempt-input.good {
  background: rgba(46, 160, 67, 0.15);
  border-color: #2ea043;
  color: #3fb950;
  font-weight: bold;
}

.attempt-input.bad {
  background: rgba(248, 81, 73, 0.15);
  border-color: #f85149;
  color: #ff7b72;
  text-decoration: line-through;
}

.lift-row strong {
  text-align: right;
  color: var(--accent);
  font-size: 1rem;
}

/* ── Footer ── */
.app-footer {
  margin-top: 16px;
  padding: 16px;
  text-align: center;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.footer-logo {
  height: 20px;
  width: auto;
  object-fit: contain;
}

.footer-content strong {
  color: var(--text);
  font-weight: 700;
}

.footer-content a {
  color: var(--teal);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-content a:hover {
  color: #70d5cb;
  text-decoration: underline;
}}