/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f5f7fa;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #2d3748;
  --muted:      #718096;
  --primary:    #4a7fcb;
  --primary-h:  #3b6bb5;
  --accent:     #68d391;
  --danger:     #fc8181;
  --warn:       #f6ad55;
  --radius:     12px;
  --shadow:     0 2px 8px rgba(0,0,0,0.08);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Header ===== */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.main-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.nav-link {
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-link.active { background: #e8f0fb; color: var(--primary); font-weight: 600; }

.user-area {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  white-space: nowrap;
}
.username { font-size: 0.88rem; color: var(--muted); }

/* ===== Main Content ===== */
.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.page-header { margin-bottom: 1.25rem; }
.page-header h2 { font-size: 1.4rem; font-weight: 700; }

/* ===== Flash Messages ===== */
.flash-container { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.flash-success { background: #c6f6d5; color: #276749; }
.flash-error   { background: #fed7d7; color: #9b2335; }
.flash-warning { background: #fefcbf; color: #744210; }
.flash-info    { background: #bee3f8; color: #2a4365; }

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover { background: var(--primary-h); text-decoration: none; color: #fff; }

.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e0; text-decoration: none; }

.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); text-decoration: none; }

.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.btn-full { width: 100%; margin-top: 0.75rem; }

/* ===== Forms ===== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.form-group label { font-size: 0.88rem; font-weight: 500; color: var(--text); }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--surface);
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,127,203,0.15);
}

.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-group.flex-grow { flex: 1; min-width: 140px; }
.form-group.form-group-btn { flex-shrink: 0; }

.optional { color: var(--muted); font-weight: 400; }

.btn-row {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* ===== Login ===== */
.center-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 4rem);
  padding: 2rem 1rem;
}
.login-card { width: 100%; max-width: 400px; text-align: center; }
.login-card .card-title { font-size: 1.6rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.95rem; }
.login-form { text-align: left; }

/* ===== Machine List ===== */
.machine-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.machine-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  gap: 0.75rem;
}
.machine-item.selected {
  border-color: var(--primary);
  background: #e8f0fb;
}
.machine-info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.machine-name { font-weight: 600; font-size: 0.95rem; }
.machine-desc { font-size: 0.8rem; color: var(--muted); }

/* Selectable machine list */
.machine-list.selectable .machine-item { padding: 0; }
.machine-link {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.6rem 0.8rem;
  flex: 1;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}
.machine-link:hover { text-decoration: none; }

/* ===== Two-column layout ===== */
.two-col {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  align-items: start;
}

/* ===== Tracking ===== */
.quick-add-form { margin-bottom: 0.75rem; }

.workout-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.workout-table th, .workout-table td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.workout-table th { font-weight: 600; color: var(--muted); font-size: 0.82rem; }
.workout-table tbody tr:last-child td { border-bottom: none; }

.placeholder-card { opacity: 0.6; }
.empty-state { color: var(--muted); font-size: 0.92rem; text-align: center; padding: 0.75rem 0; }

/* ===== Review ===== */
.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}
.chart-card { margin-bottom: 0; }
.chart-wrap { position: relative; height: 220px; }
.chart-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem; }

/* ===== Today's Workout ===== */
.todays-card {
  background: #d4edda;
  border-color: #a8d5b5;
}
.todays-card .card-title { color: #1e5631; }
.todays-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.todays-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.92rem;
}
.todays-machine { font-weight: 600; flex: 1; }
.todays-weight  { color: #1e5631; font-weight: 700; }
.todays-time    { color: #4a7a5a; font-size: 0.82rem; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .header-inner { gap: 0.75rem; }
  .username { display: none; }
  .nav-link { padding: 0.4rem 0.6rem; }

  .two-col {
    grid-template-columns: 1fr;
  }

  .form-row { flex-direction: column; }
  .form-group.flex-grow { min-width: unset; }

  .review-grid { grid-template-columns: 1fr; }
}
