/* =========================================================
   GYM LOG - MODERN DARK THEME STYLES (MOBILE-FIRST)
   ========================================================= */

:root {
  --bg-main: #0a0f1d;
  --bg-card: #131b2e;
  --bg-card-secondary: #1a243d;
  --bg-input: #0e1626;
  --border-color: #233150;
  --border-active: #10b981;
  
  --primary: #10b981;       /* Emerald Gym Green */
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --secondary: #06b6d4;     /* Cyan accent */
  --accent-gold: #f59e0b;   /* Gold for records / PR */
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.2);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --nav-height: 68px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-family);
  line-height: 1.5;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 20px) + 20px);
  min-height: 100vh;
  overflow-x: hidden;
}

.app-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 16px;
}

/* --- HEADER --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 16px 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 1.8rem;
  background: var(--primary-glow);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-badge {
  background: var(--bg-card-secondary);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--primary-glow);
}

/* --- CARDS & SECTIONS --- */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.section-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.card-subtitle {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
}

/* --- TABS --- */
.tab-view {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.tab-view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- FORM CONTROLS --- */
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input, .form-textarea {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-select {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-size: 0.82rem; /* Caratteri ridotti per massima leggibilità su smartphone */
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  text-overflow: ellipsis;
}

.form-select optgroup {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--primary);
  background-color: var(--bg-card);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-select option {
  font-size: 0.82rem;
  color: var(--text-main);
  background-color: var(--bg-input);
  padding: 4px 6px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-textarea {
  resize: vertical;
}

/* --- QUICK CHIPS --- */
.quick-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.chip-btn {
  background: var(--bg-card-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn.active, .chip-btn:hover {
  background: var(--primary);
  color: #000;
  border-color: var(--primary);
  font-weight: 700;
}

.chip-btn-sm {
  background: var(--bg-card-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
}

.chip-btn-sm:active, .chip-btn-sm.active {
  background: var(--primary);
  color: #000;
  border-color: var(--primary);
  font-weight: 700;
}

/* --- EXERCISE CARD (DYNAMIC) --- */
.exercise-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  position: relative;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  border-left: 4px solid var(--primary);
}

.exercise-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 8px;
}

.exercise-order-badge {
  background: var(--primary);
  color: #000;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 12px;
  margin-right: 6px;
}

.btn-remove-exercise {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.last-perf-badge {
  background: rgba(6, 182, 212, 0.12);
  border: 1px dashed var(--secondary);
  color: var(--secondary);
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- SETS TABLE --- */
.sets-table {
  width: 100%;
  margin-bottom: 12px;
}

.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 36px 26px;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
  background: var(--bg-card-secondary);
  padding: 6px 8px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-copy-set {
  background: var(--primary-glow);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  font-weight: 800;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}

.btn-copy-set:active {
  background: var(--primary);
  color: #000;
  transform: scale(0.92);
}

.set-number {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

.set-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.set-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 8px 24px 8px 8px;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  outline: none;
}

.set-input:focus {
  border-color: var(--primary);
}

.unit-label {
  position: absolute;
  right: 6px;
  font-size: 0.68rem;
  color: var(--text-dim);
  font-weight: 700;
  pointer-events: none;
}

.btn-remove-set {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  text-align: center;
  transition: color 0.15s;
}

.btn-remove-set:hover {
  color: var(--danger);
}

.btn-add-set {
  background: var(--bg-card-secondary);
  border: 1px dashed var(--border-color);
  color: var(--primary);
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
  transition: all 0.2s;
}

.btn-add-set:active {
  background: var(--primary-glow);
  border-color: var(--primary);
}

/* --- BUTTONS & ACTIONS --- */
.add-exercise-wrapper {
  margin-bottom: 16px;
  animation: fadeIn 0.2s ease-out;
}

.btn-add-exercise {
  background: var(--bg-card);
  border: 2px dashed var(--border-color);
  color: var(--text-main);
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-add-exercise:hover, .btn-add-exercise:active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--bg-card-secondary);
}

.btn-save-workout {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #000;
  border: none;
  width: 100%;
  padding: 16px;
  border-radius: var(--radius-lg);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--primary-glow);
  transition: transform 0.1s, box-shadow 0.2s;
  letter-spacing: 0.5px;
}

.btn-save-workout:active {
  transform: scale(0.98);
}

.btn-submit-action {
  background: var(--primary);
  color: #000;
  border: none;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}

.btn-refresh {
  background: var(--bg-card-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* --- PR / RECORD CARD --- */
.pr-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.05));
  border: 1px solid var(--accent-gold);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.pr-card.hidden {
  display: none;
}

.pr-icon {
  font-size: 2rem;
}

.pr-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pr-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: #fff;
  line-height: 1.1;
}

.pr-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- CHART WRAPPER --- */
.chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 240px;
  margin-top: 10px;
}

/* --- WORKOUTS HISTORY LIST --- */
.history-item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
}

.history-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.history-date {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
}

.history-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}

.history-title-badge {
  display: inline-block;
  background: var(--bg-card-secondary);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.history-exercises-list {
  list-style: none;
  border-top: 1px solid var(--border-color);
  padding-top: 6px;
  margin-top: 8px;
}

/* Divisore gruppi muscolari evidente nello storico */
.history-group-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 8px;
}

.history-group-divider:first-child {
  margin-top: 4px;
}

.history-group-tag {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #fbbf24; /* Giallo ambra evidente e leggibile */
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.history-group-line {
  flex: 1;
  height: 1.5px;
  background: linear-gradient(90deg, #fbbf24 0%, rgba(251, 191, 36, 0.5) 60%, rgba(251, 191, 36, 0.1) 100%);
  border-radius: 2px;
}

.history-group-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history-ex-item {
  margin-bottom: 6px;
  font-size: 0.85rem;
  padding-left: 4px;
}

.history-ex-name {
  font-weight: 700;
  color: var(--text-main);
}

.history-ex-sets {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: 8px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-action-icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-card-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-action-icon svg {
  flex-shrink: 0;
}

.btn-action-icon.edit:hover, .btn-action-icon.edit:active {
  background: rgba(6, 182, 212, 0.18);
  border-color: var(--secondary);
  color: #38bdf8;
}

.btn-action-icon.delete {
  padding: 5px 8px;
}

.btn-action-icon.delete:hover, .btn-action-icon.delete:active {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}

.edit-banner {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(16, 185, 129, 0.15));
  border: 1px solid var(--secondary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  animation: fadeIn 0.3s ease-out;
}

.edit-banner.hidden {
  display: none;
}

.edit-banner-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.edit-banner-icon {
  font-size: 1.5rem;
}

.edit-banner-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-cancel-edit {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* --- CATALOG LIST --- */
.catalog-category-group {
  margin-bottom: 16px;
}

.cat-header {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
  margin-bottom: 8px;
}

.catalog-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-card-secondary);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

/* --- BOTTOM NAVIGATION BAR --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
}

.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px 16px;
  transition: color 0.15s ease;
  font-family: inherit;
}

.nav-icon {
  font-size: 1.3rem;
  margin-bottom: 2px;
}

.nav-label {
  font-size: 0.72rem;
  font-weight: 600;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active .nav-icon {
  transform: scale(1.1);
  transition: transform 0.15s ease;
}

/* --- UTILITIES & TOAST --- */
.hidden { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.d-flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.empty-hint {
  text-align: center;
  color: var(--text-dim);
  padding: 24px 0;
  font-size: 0.9rem;
}

.loading-spinner {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.9rem;
}

.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease-out;
  border-left: 4px solid var(--primary);
}

.toast.error {
  border-left-color: var(--danger);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- APP LOCK SCREEN OVERLAY (PIN 2506) --- */
.app-lock-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-main);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.25s ease-out;
}

.app-lock-overlay.unlocked {
  display: none !important;
}

.lock-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 30px 24px 24px;
  width: 100%;
  max-width: 330px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.lock-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.lock-brand .brand-icon {
  width: 48px;
  height: 48px;
  font-size: 1.7rem;
}

.lock-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pin-dots-container {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  background: transparent;
  transition: all 0.2s ease;
}

.pin-dot.filled {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
  transform: scale(1.1);
}

.pin-error-msg {
  font-size: 0.8rem;
  color: var(--danger);
  min-height: 20px;
  margin-bottom: 14px;
  font-weight: 600;
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.key-btn {
  background: var(--bg-card-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 1.35rem;
  font-weight: 700;
  padding: 13px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.key-btn:active {
  background: var(--primary-glow);
  border-color: var(--primary);
  transform: scale(0.96);
}

.key-btn.key-action {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.remember-device-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
}

.remember-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.pin-dots-container.shake {
  animation: shake 0.35s ease-in-out;
}

.btn-lock-header {
  background: var(--bg-card-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  margin-left: 6px;
}

.btn-lock-header:hover {
  border-color: var(--primary);
  color: var(--primary);
}
