/* ─────────────────────────────────────────
   BrainQ10 神經發展評量系統 — 主樣式
   ───────────────────────────────────────── */

:root {
  --primary: #2c5f8e;
  --primary-dark: #1a3f60;
  --primary-light: #e8f0f8;
  --accent: #3a8fd4;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --orange: #e67e22;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #d5dce6;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(44,95,142,0.10);
  --shadow-hover: 0 6px 24px rgba(44,95,142,0.18);
  --font: 'Noto Sans TC', 'Microsoft JhengHei', '微軟正黑體', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ── */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.20);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.header-logo {
  width: 32px;
  height: 32px;
  background: rgba(255,255,255,0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.header-subtitle {
  font-size: 11px;
  opacity: 0.75;
  letter-spacing: 1px;
}

/* ── Main Layout ── */
.app-main { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }

/* ── View transitions ── */
.view { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Section titles ── */
.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before {
  content: '';
  display: block;
  width: 4px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
}

/* ── Cards ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* ── Home Page ── */
.home-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
  align-items: start;
}

@media (min-width: 861px) {
  .profile-panel { position: sticky; top: 76px; }
}

@media (max-width: 860px) {
  .home-layout { grid-template-columns: 1fr; }
  .scales-grid { grid-template-columns: 1fr; }
}

/* Profile Panel */
.profile-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.profile-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  padding: 18px 20px 14px;
}
.profile-header h2 { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.profile-header p  { font-size: 12px; opacity: 0.85; }

.profile-body { padding: 18px 20px; }

.profile-divider {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 16px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}

.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: #fafbfc;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237f8c8d' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Scale Grid */
.scales-panel {}
.scales-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* Scale Card */
.scale-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
}

.scale-card.enabled {
  border-color: var(--primary-light);
}
.scale-card.enabled:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.scale-card.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f8f9fa;
}

.scale-card.completed {
  border-color: var(--success);
  background: #f0faf4;
}

.scale-card-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}
.badge-adhd    { background: #eaf3ff; color: #2c5f8e; }
.badge-emotion { background: #fef9e7; color: #9a7200; }

.scale-card-name { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.scale-card-full { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.scale-card-desc { font-size: 13px; color: #555; line-height: 1.5; margin-bottom: 10px; flex-grow: 1; }

.scale-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: auto;
}
.meta-tag {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.scale-card-lock {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
  background: #f4f5f7;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  display: flex;
  align-items: flex-start;
  gap: 5px;
  line-height: 1.5;
}

.scale-card-done {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 22px;
  height: 22px;
  background: var(--success);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.scale-card-action {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-start {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}
.btn-start:hover { background: var(--primary-dark); }

.btn-redo {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}
.btn-redo:hover { background: var(--primary-light); }

/* Profile incomplete notice */
.profile-notice {
  background: #fffbf0;
  border: 1px solid #f0d080;
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  color: #7a5c00;
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.profile-notice-icon { font-size: 16px; flex-shrink: 0; }

/* ── Questionnaire View ── */
.q-header {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px 24px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.q-title-area h1 { font-size: 20px; font-weight: 700; color: var(--primary); }
.q-title-area p  { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.q-progress-area { min-width: 200px; text-align: right; }
.q-progress-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.progress-bar {
  height: 8px;
  background: var(--primary-light);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 4px;
  transition: width 0.3s ease;
}

.q-instructions {
  background: #f0f6ff;
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--primary-dark);
  margin-bottom: 20px;
}

.q-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  overflow: hidden;
}

.q-section-header {
  background: var(--primary-light);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.q-section-note {
  background: #fffbf0;
  padding: 8px 20px;
  font-size: 12px;
  color: #7a5c00;
  border-bottom: 1px solid #f0d080;
}

.q-item {
  padding: 16px 20px;
  border-bottom: 1px solid #f0f2f5;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  transition: background 0.1s;
}
.q-item:last-child { border-bottom: none; }
.q-item.answered { background: #fafffe; }
.q-item.flagged  { background: #fff8f8; }

.q-num {
  width: 28px;
  height: 28px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.q-item.answered .q-num {
  background: var(--success);
  color: #fff;
}

.q-text { font-size: 14px; line-height: 1.6; margin-bottom: 10px; }

.q-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Yes/No buttons (GDS-15) */
.q-options.yn .opt-btn {
  min-width: 70px;
}

/* 4-option layout */
.q-options.opt4 { gap: 6px; }

/* 5-option layout */
.q-options.opt5 { gap: 6px; }

.opt-btn {
  padding: 7px 14px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: #fafbfc;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.opt-btn:hover {
  border-color: var(--accent);
  background: var(--primary-light);
  color: var(--primary);
}
.opt-btn.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* Likert scale (ASRS, Vanderbilt) */
.q-options.likert {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 6px;
}
.q-options.likert .opt-btn {
  text-align: center;
  padding: 6px 8px;
  font-size: 12px;
}

/* Q footer */
.q-footer {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  bottom: 20px;
  box-shadow: 0 -2px 12px rgba(44,95,142,0.12);
}

.q-answered-count { font-size: 13px; color: var(--text-muted); }
.q-answered-count strong { color: var(--primary); }

.btn-submit {
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-submit:hover { background: #1e8449; transform: translateY(-1px); }
.btn-submit:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
  transform: none;
}

.btn-back {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 20px;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}
.btn-back:hover { border-color: var(--accent); color: var(--primary); background: var(--primary-light); }

/* ── Report View ── */
.report-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.report-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  padding: 28px 32px;
}
.report-brand {
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.7;
  margin-bottom: 8px;
  text-transform: uppercase;
}
.report-scale-name { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.report-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 16px;
  font-size: 13px;
}
.report-meta-item { opacity: 0.85; }
.report-meta-item strong { opacity: 1; font-weight: 600; }

.report-body { padding: 28px 32px; }

/* Summary box */
.report-summary {
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 24px;
  border: 2px solid;
}
.report-summary-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 6px;
}
.report-summary-result {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 4px;
}
.report-summary-score { font-size: 14px; opacity: 0.8; margin-bottom: 8px; }
.report-summary-note  { font-size: 13px; line-height: 1.6; }

/* Subscale table */
.report-section { margin-bottom: 28px; }
.report-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
}

.score-table { width: 100%; border-collapse: collapse; }
.score-table th {
  background: #f5f7fa;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.5px;
}
.score-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f2f5;
  font-size: 14px;
}
.score-table tr:last-child td { border-bottom: none; }
.score-table .score-bar-cell { width: 120px; }
.mini-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}
.mini-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* DSM badge */
.dsm-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}
.dsm-positive { background: #fde8e8; color: #c0392b; }
.dsm-negative { background: #e8f8ee; color: #1e8449; }

/* Alert flag */
.report-flag {
  background: #fde8e8;
  border: 1px solid #f5b7b1;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: #922b21;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* Bach result */
.bach-category { margin-bottom: 16px; }
.bach-category-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  padding: 4px 10px;
  background: var(--primary-light);
  border-radius: 4px;
  display: inline-block;
}
.bach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
  background: #f9f9f9;
  font-size: 13px;
}
.bach-item.significant { background: #fff7ed; border-left: 3px solid var(--warning); }
.bach-item.very-significant { background: #fef2f2; border-left: 3px solid var(--danger); }
.bach-score-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Report actions */
.report-actions {
  padding: 20px 32px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  background: #f8f9fb;
}

.btn-print {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-print:hover { background: var(--primary-dark); }

.btn-new-scale {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 8px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}
.btn-new-scale:hover { background: var(--primary-light); }

/* ── Misc ── */
.disclaimer {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 20px;
  line-height: 1.7;
}

/* ── Print Styles ── */
@media print {
  body { background: #fff; font-size: 13px; }
  .app-header, .q-footer, .report-actions, .profile-panel,
  .scales-panel, .btn-back, .profile-notice { display: none !important; }
  .app-main { padding: 0; max-width: 100%; }
  .report-container { box-shadow: none; border: none; }
  .report-header { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .report-summary { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .mini-bar-fill { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .report-body { padding: 16px; }
  .score-table { font-size: 12px; }
  a { text-decoration: none; color: inherit; }
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .app-main { padding: 16px 12px 40px; }
  .q-header { padding: 14px 16px; }
  .q-item { grid-template-columns: 1fr; }
  .q-num { display: none; }
  .report-header { padding: 20px; }
  .report-body  { padding: 16px; }
  .report-actions { padding: 16px; }
  .q-options.likert { grid-template-columns: repeat(3, 1fr); }
}
