:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-soft: #64748b;
  --text-faint: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --accent: #0d9488;
  --accent-soft: #f0fdfa;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 4px 16px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 8px 40px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 14px; }

/* ============ Header ============ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  display: grid;
  place-items: center;
  letter-spacing: 0.5px;
}

.brand h1 { font-size: 19px; font-weight: 700; }
.tagline { margin: 1px 0 0; color: var(--text-soft); font-size: 12.5px; }

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

.client-input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 200px;
  background: var(--surface-2);
}
.client-input:focus { outline: 2px solid var(--primary-border); border-color: var(--primary); }

/* ============ Buttons ============ */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid transparent; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.full-width { width: 100%; }

.count-pill {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 99px;
  padding: 1px 8px;
  font-size: 12px;
  margin-left: 4px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 600;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.icon-btn {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--text-soft);
  padding: 2px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ============ Layout ============ */
.layout {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  padding: 24px;
  align-items: start;
}

/* ============ Sidebar ============ */
.sidebar {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.search-wrap input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
}
.search-wrap input:focus { outline: 2px solid var(--primary-border); border-color: var(--primary); }

.filter-section { margin-top: 20px; }
.filter-section h2 {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-soft);
  font-weight: 700;
  margin-bottom: 8px;
}
.filter-header { display: flex; justify-content: space-between; align-items: baseline; }
.filter-hint { font-size: 12px; color: var(--text-faint); margin: 2px 0 10px; }

.symptom-list { display: flex; flex-direction: column; gap: 6px; }

.symptom-item {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.symptom-item:hover { border-color: var(--primary-border); background: var(--primary-soft); }
.symptom-item.active { border-color: var(--primary); background: var(--primary-soft); }
.symptom-item input { margin-top: 2px; accent-color: var(--primary); }

.symptom-label { font-size: 13px; font-weight: 500; }
.symptom-dsm {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0 5px;
  margin-right: 5px;
  vertical-align: 1px;
}
.symptom-desc { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; display: block; }

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 99px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-soft);
  transition: all 0.15s;
}
.chip:hover { border-color: var(--primary-border); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

#domain-select, #sort-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text);
}

#reset-filters { margin-top: 20px; }

/* ============ Main / results ============ */
.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}
#results-summary { color: var(--text-soft); font-size: 13.5px; }
.sort-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); }
.sort-label select { width: auto; }

.domain-group { margin-bottom: 28px; }
.domain-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}
.domain-heading .domain-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
}

.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.goal-card.selected { border-color: var(--primary); }

.goal-top { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.goal-title { font-size: 15px; font-weight: 700; }

.badge-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.badge {
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  padding: 2px 7px;
  white-space: nowrap;
}
.badge-level-foundational { background: #ecfdf5; color: #047857; }
.badge-level-intermediate { background: #fffbeb; color: #b45309; }
.badge-level-advanced { background: #f5f3ff; color: #6d28d9; }
.badge-age { background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border); }
.badge-symptom { background: var(--primary-soft); color: var(--primary-dark); }

.add-btn {
  flex-shrink: 0;
  border: 1px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.15s;
}
.add-btn:hover { background: var(--primary-soft); }
.add-btn.added { background: var(--primary); color: #fff; }

.goal-ltg {
  margin: 12px 0 0;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 14px;
}
.goal-ltg .ltg-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 3px;
}

.objectives-toggle {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 13px;
  padding: 0;
  margin-top: 12px;
}
.objectives-toggle:hover { text-decoration: underline; }

.objectives-list { margin: 10px 0 0; padding: 0; list-style: none; }
.objectives-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-soft);
}
.objectives-list li:hover { background: var(--surface-2); }
.objectives-list input { margin-top: 3px; accent-color: var(--primary); flex-shrink: 0; }
.objectives-list li.checked { color: var(--text); }
.obj-num {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  margin-top: 2px;
}

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state .big { font-size: 36px; margin-bottom: 10px; }

mark { background: #fef08a; border-radius: 3px; padding: 0 1px; }

/* ============ Drawer ============ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 90;
}

.plan-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(560px, 100vw);
  background: var(--surface);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transition: transform 0.2s ease;
}
.plan-drawer.hidden, .drawer-overlay.hidden { display: none; }

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 { font-size: 17px; }

.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px; }

.plan-domain-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  margin: 18px 0 8px;
}
.plan-domain-heading:first-child { margin-top: 0; }

.plan-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--surface-2);
}
.plan-item-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.plan-item-title { font-weight: 700; font-size: 13.5px; }
.plan-item-ltg { font-size: 12.5px; color: var(--text-soft); margin: 6px 0 0; }
.plan-item-objs { margin: 8px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--text-soft); }
.plan-item-objs li { margin-bottom: 4px; }

.remove-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  padding: 0;
  flex-shrink: 0;
}
.remove-btn:hover { text-decoration: underline; }

.drawer-footer {
  display: flex;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.drawer-footer .btn { flex: 1; min-width: 90px; }

.plan-empty { text-align: center; color: var(--text-faint); padding: 48px 16px; }

/* ============ Footer & toast ============ */
.app-footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px 24px 32px;
  color: var(--text-faint);
  font-size: 12px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  border-radius: 99px;
  padding: 10px 22px;
  font-size: 13.5px;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow-lg);
}
.toast.hidden { display: none; }

/* ============ Auth / header ============ */
.hidden { display: none !important; }

.auth-area { display: flex; align-items: center; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 14px;
}
.user-name { font-weight: 600; font-size: 13px; }

.role-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 4px;
  padding: 1px 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.offline-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  border: 1px dashed var(--border);
  border-radius: 99px;
  padding: 6px 12px;
}

.pill-dark { background: var(--primary-soft); color: var(--primary-dark); }

/* ============ Modals ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 150;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
}
.modal-wide { max-width: 720px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; }

.modal-body { padding: 20px 22px; overflow-y: auto; }

.tab-row { display: flex; gap: 6px; margin-bottom: 18px; }
.tab {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-soft);
}
.tab.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }

/* ============ Forms ============ */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field > span { font-size: 12.5px; font-weight: 600; color: var(--text); }
.form-field small { font-weight: 400; color: var(--text-faint); }

.form-field input[type="text"],
.form-field input[type="password"],
.form-field select,
.form-field textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  background: var(--surface-2);
  font-size: 13.5px;
  resize: vertical;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: 2px solid var(--primary-border);
  border-color: var(--primary);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 14px;
}
.checkbox-item {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  font-size: 12.5px;
  padding: 3px 0;
  cursor: pointer;
}
.checkbox-item input { margin-top: 2px; accent-color: var(--primary); }

.obj-row { display: flex; gap: 6px; margin-bottom: 8px; align-items: flex-start; }
.obj-row textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface-2);
  font-size: 13px;
  resize: vertical;
}
.obj-remove { font-size: 18px; }

.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin: 0;
}
.form-error.info { background: var(--primary-soft); color: var(--primary-dark); }

.form-note { font-size: 12px; color: var(--text-faint); margin: 14px 0 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.classify-box {
  border: 1px solid var(--primary-border);
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.classify-box h3 { font-size: 13px; margin-bottom: 6px; }
.classify-rec { font-size: 12.5px; color: var(--primary-dark); margin: 0 0 10px; }
.radio-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
  padding: 4px 0;
  cursor: pointer;
}
.radio-row input { margin-top: 3px; accent-color: var(--primary); }

/* ============ Goal card extras ============ */
.goal-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; flex-shrink: 0; }

.suggest-btn {
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  padding: 0;
}
.suggest-btn:hover { color: var(--primary); text-decoration: underline; }

.goal-card.pending { border-style: dashed; border-color: #f59e0b; }
.pending-note { font-size: 12px; font-weight: 600; color: #b45309; }

.badge-community { background: var(--accent-soft); color: var(--accent); }
.badge-modified { background: #fdf4ff; color: #a21caf; }
.badge-pending { background: #fffbeb; color: #b45309; border: 1px dashed #fcd34d; }

/* ============ Review cards ============ */
.review-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  background: var(--surface-2);
}
.review-card h3 { font-size: 14.5px; margin: 8px 0 4px; }
.review-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.review-author { font-size: 12px; color: var(--text-faint); }
.review-detail { font-size: 12.5px; color: var(--text-soft); margin: 4px 0; }

.diff-box {
  background: #fdf4ff;
  border: 1px solid #f0abfc;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  margin: 10px 0;
}
.diff-box ul { margin: 6px 0 0; padding-left: 18px; }

.review-controls { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.review-note {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  background: var(--surface);
}

/* ============ Plan metadata ============ */
.plan-meta {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 0;
  margin-bottom: 16px;
}
.plan-meta summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  padding: 11px 14px;
  user-select: none;
}
.plan-meta[open] summary { border-bottom: 1px solid var(--border); }
.plan-meta .meta-grid { padding: 12px 14px 4px; }
.plan-meta .filter-hint { padding: 0 14px 12px; margin: 4px 0 0; }
.plan-meta input { background: var(--surface); }

/* ============ Coverage ============ */
.coverage {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid;
}
.coverage-ok { background: #ecfdf5; border-color: #a7f3d0; }
.coverage-gaps { background: #fffbeb; border-color: #fde68a; }

.coverage-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 8px;
}
.coverage-head span { font-size: 12px; color: var(--text-soft); }

.coverage-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.cov-chip {
  border-radius: 99px;
  border: 1px solid;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  background: var(--surface);
}
.cov-chip.ok { color: #047857; border-color: #a7f3d0; cursor: default; }
.cov-chip.miss { color: #b45309; border-color: #fcd34d; }
.cov-chip.miss:hover { background: #fef3c7; }

.coverage-hint { font-size: 11.5px; color: var(--text-soft); margin: 8px 0 0; }

/* ============ Plan item customization ============ */
.plan-item-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }

.priority-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11.5px;
  padding: 3px 5px;
  background: var(--surface);
  color: var(--text-soft);
}

.plan-item.prio-high { border-left: 3px solid var(--danger); }
.plan-item.prio-medium { border-left: 3px solid #f59e0b; }
.plan-item.prio-low { border-left: 3px solid var(--text-faint); }

.customized-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: 1px;
}

.plan-item-meta { font-size: 12px; color: var(--text-soft); margin: 6px 0 0; }

.plan-edit {
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--primary-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.plan-edit textarea, .plan-edit input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: 12.5px;
  background: var(--surface-2);
  resize: vertical;
  font-family: inherit;
}
.plan-edit-grid { grid-template-columns: 1fr 1fr 1fr; }

.symptom-count {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0 6px;
  vertical-align: 1px;
}

/* ============ Saved plans ============ */
.saved-plans {
  padding: 0;
  margin-bottom: 16px;
}
.saved-plan-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 6px;
}
.saved-plan-row.current { border-color: var(--primary); }
.saved-plan-meta { display: block; font-size: 11.5px; color: var(--text-faint); }
.saved-plan-actions { display: flex; gap: 12px; align-items: center; flex-shrink: 0; }

/* ============ Print ============ */
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; padding: 0; }
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
}
