/* =========================================================================
   Design tokens — 與教練後台共用配色系統
   ========================================================================= */
:root[data-theme="light"] {
  --bg:           #F4F7FB;
  --surface:     #FFFFFF;
  --surface-2:   #F8FAFC;
  --surface-3:   #EEF2F7;
  --border:      #E1E5E8;
  --border-strong: #CBD5E1;
  --text:        #1A2332;
  --text-muted:  #6B7280;
  --primary:     #1E66E0;
  --primary-700: #1850B5;
  --primary-50:  #E8F0FE;
  --accent:      #00B0FF;
  --success:     #10B981;
  --success-50:  #DCFCE7;
  --danger:      #EF4444;
  --danger-50:   #FEE2E2;
  --warning:     #F59E0B;
  --warning-50:  #FEF3C7;
  --shadow-sm:   0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:      0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg:   0 8px 32px rgba(15, 23, 42, 0.12);
}
:root[data-theme="dark"] {
  --bg:           #0F172A;
  --surface:     #1A2332;
  --surface-2:   #243044;
  --surface-3:   #2C3A52;
  --border:      #334155;
  --border-strong: #475569;
  --text:        #E2E8F0;
  --text-muted:  #94A3B8;
  --primary:     #3B82F6;
  --primary-700: #60A5FA;
  --primary-50:  #1E3A5F;
  --accent:      #38BDF8;
  --success:     #34D399;
  --success-50:  #064E3B;
  --danger:      #F87171;
  --danger-50:   #7F1D1D;
  --warning:     #FBBF24;
  --warning-50:  #78350F;
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow:      0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg:   0 8px 32px rgba(0, 0, 0, 0.6);
}
:root {
  --radius:      12px;
  --radius-sm:   8px;
  --radius-xs:   6px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", Roboto, Arial, sans-serif;
  transition: background 0.2s, color 0.2s;
  min-height: 100vh;
  font-size: 14px;
}

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-700); border-color: var(--primary-700); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: var(--radius-sm); }
.btn[disabled], .btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 6px 10px; cursor: pointer;
  font-size: 13px; transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }

/* =========================================================================
   Card / form / table 共用元件
   ========================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}
.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 12px; margin-bottom: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
label.form-label {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-control, select.form-control, textarea.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, select.form-control:focus, textarea.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-50);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th {
  background: var(--surface-2);
  font-weight: 600; color: var(--text-muted);
  font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* =========================================================================
   Badges & misc
   ========================================================================= */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge-primary { background: var(--primary-50); color: var(--primary-700); }
.badge-danger  { background: var(--danger-50);  color: var(--danger); }
.badge-muted   { background: var(--surface-3); color: var(--text-muted); }

.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; }

/* =========================================================================
   Tabs
   ========================================================================= */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 10px 16px;
  border: none; background: transparent;
  color: var(--text-muted);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* =========================================================================
   Modal
   ========================================================================= */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: none;
  align-items: flex-start; justify-content: center;
  padding: 32px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  margin: auto;
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}
.modal.lg { max-width: 760px; }
@keyframes modalIn { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-title { font-size: 16px; font-weight: 700; margin: 0; }
.modal-close {
  background: transparent; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 22px; padding: 0; line-height: 1; width: 28px; height: 28px;
}
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* =========================================================================
   Workout editor
   ========================================================================= */
.exercise-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}
.exercise-block-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.exercise-block-name { font-weight: 600; font-size: 14px; color: var(--text); }
.exercise-block-cat { font-size: 11px; color: var(--text-muted); margin-left: 6px; }
.sets-list { display: flex; flex-direction: column; gap: 6px; }
.set-row {
  display: grid;
  grid-template-columns: 32px 1fr 1fr 32px;
  gap: 8px;
  align-items: center;
}
.set-no { font-size: 12px; color: var(--text-muted); text-align: center; font-weight: 600; }
.set-row .form-control { padding: 6px 10px; font-size: 13px; }
.add-set-btn {
  margin-top: 8px;
  width: 100%;
  border-style: dashed;
  color: var(--text-muted);
}
.add-set-btn:hover { color: var(--primary); border-color: var(--primary); }

.ex-summary {
  margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}
.ex-summary:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.ex-name { font-weight: 600; }
.ex-sets-inline {
  color: var(--text-muted); margin-top: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

/* =========================================================================
   Toast
   ========================================================================= */
.toast {
  position: fixed; top: 16px; right: 16px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: 13px;
  z-index: 200;
  transform: translateX(420px);
  transition: transform 0.25s ease-out;
  max-width: 360px;
}
.toast.show { transform: translateX(0); }
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
.toast.info    { border-left: 4px solid var(--primary); }

/* =========================================================================
   Loader
   ========================================================================= */
.loader {
  border: 3px solid var(--surface-3);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  width: 28px; height: 28px;
  animation: spin 0.8s linear infinite;
  margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   LIFF mobile-first specific
   ========================================================================= */
.liff-body {
  background: var(--bg);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.liff-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
  padding-top: calc(10px + env(safe-area-inset-top, 0));
}
.liff-brand {
  font-weight: 700; font-size: 15px; color: var(--primary);
  display: flex; align-items: center; gap: 6px;
}
.liff-toolbar { display: flex; gap: 6px; }

.liff-state {
  padding: 32px 16px;
  max-width: 480px;
  margin: 0 auto;
}

.liff-main {
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: 32px;
}

.liff-profile {
  display: flex; align-items: center; gap: 14px;
  padding: 20px 16px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-700) 100%);
  color: white;
  margin-bottom: 12px;
}
.liff-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  background-size: cover; background-position: center;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.4);
}
.liff-profile-text { flex: 1; min-width: 0; }
.liff-greet {
  font-size: 14px; opacity: 0.9; margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.liff-remaining-big { display: flex; align-items: baseline; gap: 6px; }
.liff-remaining-num { font-size: 32px; font-weight: 700; line-height: 1; }
.liff-remaining-unit { font-size: 13px; opacity: 0.85; }

.liff-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 16px;
  margin-bottom: 12px;
}
.liff-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.liff-stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.liff-stat-value { font-size: 18px; font-weight: 700; color: var(--text); }

.liff-settings-link { margin: 24px 16px 0; }

#liff-tab-records, #liff-tab-purchases { margin-top: 12px; }
.liff-record {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  overflow: hidden;
}
.liff-record-summary {
  padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer;
}
.liff-record-detail {
  display: none;
  padding: 10px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.liff-record.open .liff-record-detail { display: block; }
.liff-record-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.liff-record-date { font-weight: 600; }

.lang-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lang-opt {
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.lang-opt.active {
  background: var(--primary-50);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 700;
}

@media (max-width: 600px) {
  .modal-backdrop { padding: 12px 8px; }
  .modal { border-radius: var(--radius); }
  .modal-body { max-height: 65vh; }
}

/* Debug panel */
.liff-debug-line {
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 12px;
  word-break: break-all;
  min-height: 16px;
}
.liff-debug-panel {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 60vh;
  overflow: auto;
}

/* Unbound */
.liff-unbound-steps {
  margin: 16px 0;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
}
.liff-unbound-steps > div { padding: 4px 0; }
.liff-unbound-info {
  margin: 16px 0 0;
  padding: 14px;
  background: var(--primary-50);
  border-radius: var(--radius-sm);
  text-align: center;
}
.liff-unbound-info-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.liff-unbound-info-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}
.liff-unbound-info-uid {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
  margin-bottom: 8px;
  padding: 4px 8px;
  background: var(--surface);
  border-radius: var(--radius-xs);
  display: inline-block;
}
