@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Newsreader:ital,wght@0,400;0,500;1,400&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg: #F3EEE4;
  --bg-alt: #FFFDFC;
  --bg-card: #FFFFFF;
  --accent: #2E6F66;
  --accent-hover: #255c54;
  --accent-light: #3d9088;
  --accent-muted: #e4f0ee;
  --accent-muted-dark: #c5deda;
  --text: #1c1c1c;
  --text-2: #555;
  --text-3: #888;
  --border: #e2d9cc;
  --border-light: #ede7dd;
  --red: #c0392b;
  --red-muted: #fdf0ee;
  --green: #1e7d45;
  --green-muted: #e8f5ed;
  --yellow: #b45309;
  --yellow-muted: #fef9ed;
  --r: 14px;
  --r-sm: 8px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(46,111,102,.07);
  --shadow: 0 4px 16px rgba(46,111,102,.09);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.1);
  --sans: 'Manrope', system-ui, sans-serif;
  --serif: 'Newsreader', Georgia, serif;
  --nav-h: 64px;
  --tab-h: 68px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Typography ─────────────────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.2rem; font-weight: 700; line-height: 1.3; }
h3 { font-size: 1rem; font-weight: 600; line-height: 1.4; }
p { line-height: 1.6; }
.serif { font-family: var(--serif); }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.page { min-height: 100dvh; display: flex; flex-direction: column; }
.container { width: 100%; max-width: 520px; margin: 0 auto; padding: 0 16px; }
.container-wide { width: 100%; max-width: 1000px; margin: 0 auto; padding: 0 20px; }
.content { flex: 1; padding: 24px 0 calc(var(--tab-h) + 16px); }
.content-coach { flex: 1; padding: 24px 0 40px; }
.section { margin-bottom: 28px; }
.section-title {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Top Nav ─────────────────────────────────────────────────────────────────── */
.topnav {
  height: var(--nav-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topnav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topnav-logo {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: .9rem;
  flex-shrink: 0;
}
.topnav-name { font-weight: 700; font-size: 1rem; }
.topnav-sub { font-size: .75rem; color: var(--text-3); }
.topnav-actions { display: flex; align-items: center; gap: 8px; }

/* ── Bottom Tab Bar ──────────────────────────────────────────────────────────── */
.tabnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: stretch;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}
.tabnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-3);
  font-size: .7rem;
  font-weight: 500;
  text-decoration: none;
  transition: color .15s;
  padding: 8px 4px;
}
.tabnav-item svg { width: 22px; height: 22px; }
.tabnav-item.active { color: var(--accent); }
.tabnav-item.active svg path, .tabnav-item.active svg circle, .tabnav-item.active svg rect { stroke: var(--accent); }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}
.card-sm { padding: 14px; }
.card-link { transition: box-shadow .15s, transform .15s; }
.card-link:hover { box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--r-sm);
  font-size: .9rem;
  font-weight: 600;
  border: none;
  transition: background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--accent-muted); color: var(--accent); }
.btn-secondary:hover:not(:disabled) { background: var(--accent-muted-dark); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--red-muted); color: var(--red); border: 1px solid #f5c6c2; }
.btn-danger:hover:not(:disabled) { background: #f9e0de; }
.btn-sm { padding: 6px 14px; font-size: .8rem; border-radius: 6px; }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: var(--r); }
.btn-full { width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; }
.btn-icon-sm { width: 28px; height: 28px; padding: 0; border-radius: 50%; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
label { font-size: .85rem; font-weight: 600; color: var(--text-2); }
.input, input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: .9rem;
  color: var(--text);
  background: var(--bg-alt);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  appearance: none;
}
.input:focus, input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46,111,102,.12);
}
textarea { min-height: 100px; resize: vertical; }
.input-error { border-color: var(--red) !important; }
.error-msg { font-size: .8rem; color: var(--red); margin-top: 4px; }
.form-hint { font-size: .78rem; color: var(--text-3); }

.day-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.day-chip {
  padding: 5px 10px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: .78rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s;
}
.day-chip.selected { background: var(--accent); color: #fff; border-color: var(--accent); }

.freq-tabs { display: flex; border: 1.5px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.freq-tab {
  flex: 1;
  padding: 8px 4px;
  font-size: .78rem;
  font-weight: 600;
  text-align: center;
  border: none;
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s;
  border-right: 1px solid var(--border);
}
.freq-tab:last-child { border-right: none; }
.freq-tab.active { background: var(--accent); color: #fff; }

/* ── Rating Stars ────────────────────────────────────────────────────────────── */
.star-row { display: flex; gap: 6px; }
.star {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all .15s;
  line-height: 1;
}
.star.filled { background: var(--accent); border-color: var(--accent); color: #fff; }
.star-sm { width: 28px; height: 28px; font-size: 1rem; }

/* ── Habit Check Card ────────────────────────────────────────────────────────── */
.habit-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--r);
  border: 1.5px solid var(--border-light);
  transition: border-color .15s;
}
.habit-item.done { opacity: .72; }
.habit-item.done .habit-check { background: var(--accent); border-color: var(--accent); }
.habit-check {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s;
  margin-top: 1px;
}
.habit-check:hover:not(:disabled) { border-color: var(--accent); }
.habit-check svg { width: 18px; height: 18px; color: white; opacity: 0; transition: opacity .15s; }
.habit-item.done .habit-check svg { opacity: 1; }
.habit-info { flex: 1; min-width: 0; }
.habit-title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.habit-badge { font-size: .7rem; color: var(--text-3); }

/* ── Badges / Pills ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--green-muted); color: var(--green); }
.badge-teal { background: var(--accent-muted); color: var(--accent); }
.badge-yellow { background: var(--yellow-muted); color: var(--yellow); }
.badge-gray { background: var(--bg); color: var(--text-3); border: 1px solid var(--border); }
.badge-red { background: var(--red-muted); color: var(--red); }

/* ── Progress Bar ─────────────────────────────────────────────────────────────── */
.progress-bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s ease; }

/* ── Modal / Sheet ───────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.overlay.open { opacity: 1; pointer-events: all; }

.sheet {
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  background: var(--bg-card);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0));
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
  max-height: 90dvh;
  overflow-y: auto;
}
.overlay.open .sheet { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 20px;
}
.sheet-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; text-align: center; }

.modal-center {
  align-items: center;
  justify-content: center;
}
.modal-box {
  width: calc(100% - 32px);
  max-width: 480px;
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: 28px 24px;
  transform: scale(.94) translateY(16px);
  transition: transform .25s cubic-bezier(.32,.72,0,1);
  max-height: 92dvh;
  overflow-y: auto;
}
.overlay.open .modal-box { transform: scale(1) translateY(0); }

/* ── Page Header ─────────────────────────────────────────────────────────────── */
.page-header { padding: 20px 0 16px; }
.page-header h1 { font-family: var(--serif); }

/* ── Client Card (Coach Dashboard) ──────────────────────────────────────────── */
.client-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--r);
  border: 1.5px solid var(--border-light);
  text-decoration: none;
  color: var(--text);
  transition: box-shadow .15s, transform .15s;
}
.client-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
.client-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-muted);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.client-info { flex: 1; min-width: 0; }
.client-name { font-weight: 700; font-size: .95rem; }
.client-stats { display: flex; gap: 12px; margin-top: 6px; }
.client-stat { font-size: .75rem; color: var(--text-3); }
.client-stat strong { color: var(--text); font-weight: 600; }
.client-rate { font-size: 1.1rem; font-weight: 700; color: var(--accent); }

/* ── Stat Row ─────────────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-card {
  background: var(--bg-card);
  border-radius: var(--r);
  padding: 16px 12px;
  text-align: center;
  border: 1px solid var(--border-light);
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); line-height: 1; }
.stat-label { font-size: .72rem; color: var(--text-3); margin-top: 4px; font-weight: 500; }

/* ── Reflection Card ─────────────────────────────────────────────────────────── */
.reflection-card { padding: 18px; }
.reflection-week { font-size: .75rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.reflection-mood { display: flex; gap: 4px; margin-bottom: 10px; }
.mood-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.mood-dot.filled { background: var(--accent); }
.reflection-text { font-family: var(--serif); font-size: .95rem; line-height: 1.65; color: var(--text-2); }

/* ── Goal Item ───────────────────────────────────────────────────────────────── */
.goal-item { padding: 16px; }
.goal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.goal-title { font-weight: 600; font-size: .95rem; }
.goal-desc { font-size: .85rem; color: var(--text-2); line-height: 1.5; }

/* ── Empty State ─────────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-title { font-weight: 600; font-size: 1rem; color: var(--text-2); margin-bottom: 6px; }
.empty-sub { font-size: .85rem; }

/* ── Loading ─────────────────────────────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.loading-center { display: flex; align-items: center; justify-content: center; padding: 64px 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--border-light) 25%, #fff 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--r);
  font-size: .85rem;
  font-weight: 500;
  z-index: 500;
  opacity: 0;
  transition: all .25s;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-overflow: ellipsis;
  overflow: hidden;
}
.toast.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--red); }
.toast.toast-success { background: var(--green); }
.toast-no-tab { bottom: 32px; }

/* ── Auth Page ───────────────────────────────────────────────────────────────── */
.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
}
.auth-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-light);
}
.auth-logo {
  width: 56px; height: 56px;
  background: var(--accent);
  border-radius: 16px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.3rem;
}
.auth-title { text-align: center; font-family: var(--serif); font-size: 1.5rem; margin-bottom: 6px; }
.auth-sub { text-align: center; font-size: .85rem; color: var(--text-3); margin-bottom: 28px; }

/* ── Streak Flame ────────────────────────────────────────────────────────────── */
.streak { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; font-weight: 600; color: var(--yellow); }

/* ── Back Link ───────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-2);
  text-decoration: none;
  padding: 8px 0;
}
.back-link:hover { color: var(--accent); text-decoration: none; }

/* ── Habit Manage Row (Coach Client Detail) ──────────────────────────────────── */
.habit-manage {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--r);
  border: 1.5px solid var(--border-light);
}
.habit-manage-info { flex: 1; min-width: 0; }
.habit-manage-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Divider ──────────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border-light); margin: 20px 0; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .container { padding: 0 24px; }
  .container-wide { padding: 0 32px; }
  .auth-page { padding: 40px 24px; }
  h1 { font-size: 1.75rem; }
}
@media (min-width: 960px) {
  .client-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
