:root {
  --bg: #eef1f6;
  --bg-soft: #f5f7fb;
  --card-bg: #ffffff;
  --card-bg-soft: #f6f8fb;
  --border: #dde3ec;
  --text: #2b3446;
  --text-muted: #7c8698;
  --primary: #5b7fa6;
  --primary-dark: #43607e;
  --primary-light: #e7edf5;
  --accent: #8fa8c2;
  --success: #6b9b7c;
  --success-bg: #e8f1ea;
  --success-text: #4f7d61;
  --error: #b96679;
  --error-bg: #f8ebee;
  --error-text: #97485c;
  --badge-bg: var(--error-bg);
  --badge-text: var(--error-text);
  --badge-done-bg: var(--success-bg);
  --badge-done-text: var(--success-text);
  --shadow-sm: 0 1px 2px rgba(43, 52, 70, 0.05), 0 1px 1px rgba(43, 52, 70, 0.04);
  --shadow-md: 0 8px 24px rgba(43, 52, 70, 0.08), 0 2px 6px rgba(43, 52, 70, 0.05);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, #f2f5fa 0%, transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, #eef2f8 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; }

.view {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 72px;
}

h1, h2, h3, h4 { color: var(--text); letter-spacing: 0.01em; }
h2 { margin-top: 0; font-weight: 700; }
h3 { font-weight: 700; }

.hint { color: var(--text-muted); font-size: 0.9em; }

.topnav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 1px 0 rgba(43, 52, 70, 0.06), 0 4px 16px rgba(43, 52, 70, 0.04);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 800;
  margin-right: 8px;
  color: var(--primary-dark);
  letter-spacing: 0.02em;
}

.nav-links { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }

.nav-link {
  padding: 7px 12px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.92em;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.nav-link:hover:not(.active) { background: var(--primary-light); }

.nav-user { font-size: 0.85em; color: var(--text-muted); }

.link-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--text);
  transition: border-color 0.15s ease, color 0.15s ease;
}
.link-btn:hover { border-color: var(--primary); color: var(--primary-dark); }

.back-link { display: inline-block; margin-bottom: 14px; color: var(--primary-dark); text-decoration: none; font-weight: 600; }
.back-link:hover { text-decoration: underline; }

/* Login */
.login-card {
  max-width: 380px;
  margin: 14vh auto 0;
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  text-align: center;
}
.login-card h1 { color: var(--primary-dark); }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; text-align: left; }

/* Forms */
label { font-weight: 600; font-size: 0.9em; display: block; margin-bottom: 4px; color: var(--text); }

input, select, textarea, button {
  font-family: inherit;
  font-size: 1em;
}

input[type="text"], input[type="tel"], input[type="number"], input[type="date"],
input[type="time"], input[type="file"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

textarea { resize: vertical; }

button[type="submit"], .canned-add-form button, .schedule-add-form button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
button[type="submit"]:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
button[type="submit"]:active { transform: translateY(0); }

.card-form {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 18px;
}
.card-form section { display: flex; flex-direction: column; gap: 5px; }

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 10px 0 16px;
}
.inline-form input, .inline-form select { width: auto; flex: 1; min-width: 120px; }

.msg { min-height: 1.2em; font-size: 0.9em; margin: 4px 0 0; }
.msg.success { color: var(--success-text); }
.msg.error, p.error { color: var(--error-text); }

/* Body diagram soreness picker */
.body-diagrams {
  display: flex;
  gap: 28px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 10px 0;
  padding: 16px;
  background: var(--card-bg-soft);
  border-radius: var(--radius);
}
.body-diagram { display: flex; flex-direction: column; align-items: center; }
.body-svg { width: 170px; height: auto; }
.body-hotspot {
  fill: rgba(255, 255, 255, 0.55);
  stroke: #ffffff;
  stroke-width: 1.6;
  stroke-dasharray: 3 2;
  cursor: pointer;
  transition: fill 0.15s ease, stroke 0.15s ease;
}
.body-hotspot:hover { fill: rgba(255, 255, 255, 0.85); }
.body-hotspot.selected {
  fill: var(--primary);
  stroke: var(--primary-dark);
  stroke-dasharray: none;
}
.body-diagram-label {
  margin: 8px 0 0;
  font-size: 0.82em;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.other-part-btn {
  background: var(--card-bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.9em;
  cursor: pointer;
  margin: 4px 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.other-part-btn.selected { background: var(--primary); color: #fff; border-color: var(--primary-dark); }

.soreness-details { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.soreness-detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--card-bg-soft);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}
.soreness-detail-label { font-weight: 700; min-width: 48px; }
.soreness-detail-severity { width: auto; }
.soreness-detail-note { flex: 1; min-width: 160px; }

.scale-row { display: flex; flex-wrap: wrap; gap: 12px; }
.scale-option { font-weight: 400; display: flex; align-items: center; gap: 4px; }

.canned-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.canned-btn {
  background: var(--card-bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.canned-btn:hover { background: var(--primary-light); border-color: var(--primary); }

/* Food category chips */
.food-category-row { display: flex; flex-wrap: wrap; gap: 8px; }
.food-category-chip {
  background: var(--card-bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.88em;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.food-category-chip.selected { background: var(--primary); color: #fff; border-color: var(--primary-dark); font-weight: 700; }
.food-category-tag {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.78em;
  font-weight: 700;
  margin: 0 4px 4px 0;
}

/* Photo upload */
.photo-upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.photo-preview {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.photo-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.remove-photo-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8em;
  cursor: pointer;
}

.ai-placeholder-btn {
  background: var(--card-bg-soft);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  color: var(--text-muted);
  font-size: 0.85em;
  cursor: not-allowed;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
}
.ai-placeholder-btn .badge-soon {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.78em;
  font-weight: 700;
}

/* History / checkin entries */
.day-group { margin-bottom: 22px; }
.checkin-entry {
  display: flex;
  gap: 14px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.entry-time {
  flex: 0 0 56px;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 0.9em;
}
.entry-body { flex: 1; }
.entry-body p { margin: 4px 0; }

.diet-entry {
  display: flex;
  gap: 14px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.diet-entry .entry-time { flex: 0 0 56px; font-weight: 700; color: var(--primary-dark); font-size: 0.9em; }
.diet-entry .entry-body p { margin: 4px 0; }

.replies { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 10px; }
.reply { background: var(--card-bg-soft); border-radius: var(--radius-sm); padding: 9px 12px; margin-bottom: 6px; }
.reply-teacher { font-weight: 700; font-size: 0.85em; color: var(--primary-dark); }
.reply-time { color: var(--text-muted); font-size: 0.8em; margin-left: 8px; }
.reply p { margin: 4px 0 0; }

.reply-form { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.reply-form textarea { width: 100%; }
.reply-form button { align-self: flex-start; }

/* Dashboard */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  margin-bottom: 18px;
  font-size: 0.9em;
}
.filter-row label { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.filter-row input, .filter-row select { width: auto; }

.dashboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 13px 16px;
  margin-bottom: 9px;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s ease, transform 0.1s ease;
}
.dashboard-row:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.dashboard-row.unreplied { border-left: 4px solid var(--error); }
.row-student { font-weight: 700; min-width: 80px; }
.row-date { color: var(--text-muted); }
.row-count { color: var(--text-muted); font-size: 0.85em; }
.badge {
  margin-left: auto;
  background: var(--badge-bg);
  color: var(--badge-text);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.8em;
  font-weight: 700;
}
.badge.done { background: var(--badge-done-bg); color: var(--badge-done-text); }

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 10px;
  font-size: 0.92em;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table th { background: var(--card-bg-soft); font-weight: 700; color: var(--text-muted); font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--card-bg-soft); }
.data-table a { color: var(--primary-dark); text-decoration: none; font-weight: 600; }
.data-table a:hover { text-decoration: underline; }

/* Profile sections */
.profile-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 18px;
}
.profile-section h3 { margin-top: 0; }

.program-card {
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 14px;
  background: var(--card-bg-soft);
}
.program-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.program-head h4 { margin: 0; }

.note-item {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.note-item:last-child { border-bottom: none; }

.canned-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 640px) {
  .canned-columns { grid-template-columns: 1fr; }
}

.canned-list { list-style: none; padding: 0; margin: 0; }
.canned-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--card-bg-soft);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 6px;
}

button.toggle-active-btn, button.delete-goal-btn, button.delete-program-btn,
button.delete-schedule-btn, button.delete-measurement-btn, button.delete-note-btn,
button.delete-canned-btn, button.remove-soreness-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.85em;
  transition: border-color 0.15s ease, color 0.15s ease;
}
button.toggle-active-btn:hover, button.delete-goal-btn:hover, button.delete-program-btn:hover,
button.delete-schedule-btn:hover, button.delete-measurement-btn:hover, button.delete-note-btn:hover,
button.delete-canned-btn:hover, button.remove-soreness-btn:hover {
  border-color: var(--error);
  color: var(--error-text);
}
