/* ===================================================
   SarangNanum CM AI - Main Stylesheet
   =================================================== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #06b6d4;
  --info-light: #ecfeff;
  --sidebar-bg: #1e293b;
  --sidebar-hover: #334155;
  --sidebar-active: #2563eb;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #2563eb;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.15);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --sidebar-width: 260px;
  --header-height: 64px;
  --transition: .2s ease;
}

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

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

body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; }

/* ===== LAYOUT ===== */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  min-width: 0;
  max-width: 100%;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--transition);
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-brand .brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.sidebar-brand .brand-icon {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand .brand-name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.sidebar-brand .brand-sub {
  font-size: 11px;
  color: var(--sidebar-text);
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #475569;
  padding: 12px 20px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0;
  transition: all var(--transition);
  position: relative;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #cbd5e1;
}

.nav-item.active {
  background: rgba(37,99,235,.15);
  color: var(--sidebar-text-active);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.nav-item .nav-icon {
  width: 20px; text-align: center;
  font-size: 14px;
  opacity: .8;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user .user-avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: 11px; color: var(--sidebar-text); }

/* ===== MAIN CONTENT ===== */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  max-width: 100%;
}

/* ===== TOP HEADER ===== */
.top-header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  min-width: 0;
}

.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.breadcrumb-sep { color: var(--text-light); }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
  font-size: 14px;
}

.header-btn:hover { background: var(--bg); color: var(--primary); border-color: var(--primary); }

/* ===== PAGE CONTENT ===== */
.page-content {
  padding: 24px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}

/* ===== FLASH MESSAGE ===== */
.flash-message {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px;
  font-weight: 500;
}

.flash-message.success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.flash-message.error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.flash-message.warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.flash-message.info { background: var(--info-light); color: #164e63; border: 1px solid #a5f3fc; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: visible;
  min-width: 0;
  max-width: 100%;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: #fafbfc;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex; align-items: center; gap: 8px;
}

.card-title i { color: var(--primary); }

.card-body {
  padding: 20px;
  min-width: 0;
  max-width: 100%;
}
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfc; }

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.blue { background: #eff6ff; color: var(--primary); }
.stat-icon.green { background: #ecfdf5; color: var(--success); }
.stat-icon.orange { background: #fffbeb; color: var(--warning); }
.stat-icon.red { background: #fef2f2; color: var(--danger); }
.stat-icon.purple { background: #f5f3ff; color: #7c3aed; }
.stat-icon.cyan { background: #ecfeff; color: var(--info); }

.stat-info .stat-value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-info .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-info .stat-change { font-size: 11px; margin-top: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ===== GRID ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover:not(:disabled) { background: #059669; color: #fff; }

.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover:not(:disabled) { background: #d97706; color: #fff; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #dc2626; color: #fff; }

.btn-secondary { background: var(--secondary); color: #fff; border-color: var(--secondary); }
.btn-secondary:hover:not(:disabled) { background: #475569; color: #fff; }

.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary); color: #fff; }

.btn-outline-secondary { background: transparent; color: var(--secondary); border-color: var(--border); }
.btn-outline-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-light { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-light:hover:not(:disabled) { background: #e2e8f0; }

.btn-ai {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border-color: transparent;
}
.btn-ai:hover:not(:disabled) { background: linear-gradient(135deg, #5a6fd6, #6a3f96); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-xs { padding: 4px 9px; font-size: 12px; }
.btn-icon { padding: 8px; aspect-ratio: 1; }
.btn-block { width: 100%; justify-content: center; }
.btn-outline-primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover:not(:disabled) { background: var(--primary); color: #fff; }
.btn-info { background: var(--info); color: #fff; border-color: var(--info); }
.btn-info:hover:not(:disabled) { background: #0891b2; color: #fff; }
code { background: #f1f5f9; padding: 2px 7px; border-radius: 4px; font-family: monospace; font-size: 13px; color: var(--primary); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}

.badge-high { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-medium { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.badge-low { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-primary { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.badge-secondary { background: #f8fafc; color: #475569; border: 1px solid #e2e8f0; }
.badge-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.badge-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-info { background: #ecfeff; color: #164e63; border: 1px solid #a5f3fc; }
.badge-active { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-closed { background: #f8fafc; color: #475569; border: 1px solid #e2e8f0; }
.badge-pending { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  line-height: 1.5;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form-control:disabled, .form-control[readonly] {
  background: #f8fafc;
  color: var(--text-muted);
  cursor: not-allowed;
}

.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-valid { border-color: var(--success); }

textarea.form-control { resize: vertical; min-height: 90px; }

select.form-control { cursor: pointer; }

.form-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

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

.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; flex-shrink: 0; }

.form-check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.form-check input[type="checkbox"], .form-check input[type="radio"] {
  width: 16px; height: 16px; margin-top: 2px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}
.form-check-label { font-size: 13.5px; color: var(--text); cursor: pointer; line-height: 1.5; }
.form-check-label small { color: var(--text-muted); display: block; font-size: 12px; }

/* ===== RISK INDICATOR ITEMS ===== */
.risk-indicator-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.risk-item {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex; align-items: flex-start; gap: 10px;
  cursor: pointer;
  transition: all var(--transition);
  background: #fff;
}

.risk-item:hover { border-color: var(--primary); background: var(--primary-light); }
.risk-item.checked { border-color: var(--danger); background: #fff5f5; }

.risk-item input { margin-top: 2px; accent-color: var(--danger); }

.risk-item-content { flex: 1; }
.risk-item-title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.risk-item-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ===== TABLES ===== */
.table-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

table { width: 100%; border-collapse: collapse; }

thead { background: #f8fafc; }

th {
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 13px 16px;
  font-size: 13.5px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: #f8fafc; }

.table-actions { display: flex; align-items: center; gap: 6px; }

/* ===== TABS ===== */
.tabs-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  border-bottom: 2px solid var(--border);
  gap: 0;
  margin-bottom: 20px;
  overflow: visible;
}

.tab-btn {
  padding: 11px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: inherit;
  display: flex; align-items: center; gap: 6px;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.show { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(.95);
  transition: transform var(--transition);
}

.modal-overlay.show .modal { transform: scale(1); }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1000px; }

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

.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  border: none; background: none; cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--danger); }

.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* 지역 자원 등록/수정: 폼이 flex 자식이라 본문만 스크롤·푸터(저장) 고정 */
.resource-editor-modal {
  min-height: 0;
}

.resource-editor-modal > .modal-header {
  flex-shrink: 0;
}

.resource-editor-modal > form#resourceEditorForm {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.resource-editor-modal > form#resourceEditorForm .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.resource-editor-modal > .modal-footer {
  flex-shrink: 0;
  background: var(--bg-card);
}

/* ===== 상담 기록 — 본문 탭(직접 입력 / 녹음·텍스트 변환) ===== */
.counseling-body-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  background: var(--bg, #f8fafc);
}
.counseling-body-wrap__head {
  margin-bottom: 14px;
}
.counseling-body-tabs {
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}
.counseling-body-panels {
  padding-top: 16px;
  background: #fff;
  margin: 0 -20px -18px;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 18px;
  border-radius: 0 0 var(--radius) var(--radius);
}
.counseling-body-panel .counseling-audio-section {
  margin: 0;
}
.counseling-audio-section__title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

/* ===== 상담 녹음 클립 ===== */
.counseling-audio-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.counseling-audio-item {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
.counseling-audio-item:last-child {
  border-bottom: none;
}
.counseling-audio-item__row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.counseling-audio-item__no {
  font-weight: 700;
  color: var(--primary);
  min-width: 1.5em;
  flex-shrink: 0;
  line-height: 1.2;
  align-self: flex-start;
  padding-top: 8px;
}
.cm-counsel-audio-native {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
.cm-counsel-player {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 100%;
}
.cm-counsel-player__ui {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.cm-counsel-player__play {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cm-counsel-player__track {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cm-counsel-player__seek {
  width: 100%;
  height: 6px;
  cursor: pointer;
  accent-color: var(--primary, #4a90d9);
}
.cm-counsel-player__seek:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.cm-counsel-player__times {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 4px;
  align-items: center;
}
.cm-counsel-player__sep {
  opacity: 0.6;
}
.cm-counsel-player__fname {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.cm-counsel-player__st {
  font-weight: 500;
  color: var(--text-muted);
}
.counseling-audio-item__actions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  align-self: flex-start;
  padding-top: 4px;
  justify-content: flex-end;
  max-width: 100%;
}
.counseling-audio-transcripts {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.counseling-audio-transcripts__title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--text, #1e293b);
}
.counseling-audio-transcripts__empty {
  margin: 0;
}
.counseling-tx-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
  margin-bottom: 12px;
  overflow: hidden;
}
.counseling-tx-block__head {
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  background: var(--bg, #f1f5f9);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.counseling-tx-block__body {
  padding: 10px 12px;
}
.counseling-tx-block__pre {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  max-height: 280px;
  overflow-y: auto;
}
.counseling-tx-block__err {
  padding: 0 12px 10px;
}
.counseling-tx-block--highlight {
  outline: 3px solid rgba(74, 144, 217, 0.65);
  outline-offset: 2px;
  border-radius: 10px;
  transition: outline-color 0.25s ease, box-shadow 0.25s ease;
  box-shadow: 0 4px 20px rgba(74, 144, 217, 0.2);
}
.counseling-audio-merge-hint {
  max-width: 52rem;
}
@media (max-width: 768px) {
  .counseling-audio-item__row {
    flex-wrap: wrap;
  }
  .counseling-audio-item__actions {
    width: 100%;
    justify-content: flex-end;
    padding-left: 2rem;
    padding-top: 8px;
  }
}
#counselingRecIndicator.counseling-rec--active {
  color: #dc2626;
  font-weight: 600;
}

/* 내담자 상세 — 상담 기록: 내용 요약 한 줄(말줄임) */
.cm-counseling-sessions-table {
  table-layout: fixed;
  width: 100%;
}
.cm-counseling-sessions-table .cm-counsel-col-summary,
.cm-counseling-sessions-table .cm-counsel-summary-cell {
  width: 34%;
  min-width: 140px;
}
.cm-counseling-sessions-table .cm-counsel-summary-cell {
  vertical-align: middle;
  overflow: hidden;
}
.cm-counsel-summary-line {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* ===== 내담자 상세 — 상담기록 탭 ===== */
.counseling-tab-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.counseling-tab-card__head-text {
  flex: 1;
  min-width: min(100%, 280px);
}

.counseling-tab-card__title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
}

.counseling-tab-card__title i {
  color: var(--primary);
  font-size: 1.1em;
}

.counseling-tab-card__count {
  display: inline-block;
  padding: 2px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-light);
  border-radius: 999px;
  vertical-align: middle;
}

.counseling-tab-card__hint {
  margin-top: 6px;
  max-width: 40rem;
}

.counseling-tab-card__cta {
  flex-shrink: 0;
  align-self: center;
}

.counseling-tab-card__body {
  padding-top: 8px;
}

.counseling-tab-empty {
  text-align: center;
  padding: 36px 20px 40px;
  max-width: 420px;
  margin: 0 auto;
}

.counseling-tab-empty__icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--primary-light), #e0e7ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--primary);
}

.counseling-tab-empty__title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.counseling-tab-empty__text {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 0;
}

.counseling-session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.counseling-session-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  border-left: 4px solid var(--primary);
}

.counseling-session-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow);
}

.counseling-session-card__row--top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.counseling-session-card__lead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 14px;
}

.counseling-session-card__session-no {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.counseling-session-card__datetime {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.counseling-type-badge {
  display: inline-block;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  white-space: nowrap;
}

.counseling-type-badge--initial {
  background: #dbeafe;
  color: #1d4ed8;
}

.counseling-type-badge--default {
  background: #e0f2fe;
  color: #0369a1;
}

.counseling-type-badge--crisis {
  background: var(--danger-light);
  color: #b91c1c;
}

.counseling-type-badge--closing {
  background: #f1f5f9;
  color: #475569;
}

.counseling-session-card__meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 20px;
  margin: 0 0 14px;
  padding: 12px 14px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.counseling-session-card__meta-item {
  margin: 0;
}

.counseling-session-card__meta-item dt {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-light);
  margin-bottom: 4px;
}

.counseling-session-card__meta-item dt i {
  margin-right: 6px;
  opacity: 0.85;
}

.counseling-session-card__meta-item dd {
  margin: 0;
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.counseling-session-card__excerpt-wrap {
  margin-bottom: 14px;
}

.counseling-session-card__excerpt-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.counseling-session-card__excerpt {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.counseling-session-card__no-content {
  font-size: 13px;
  margin: 0 0 14px;
}

.counseling-session-card__no-content i {
  margin-right: 6px;
  opacity: 0.7;
}

.counseling-session-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

@media (max-width: 480px) {
  .counseling-session-card {
    padding: 14px;
  }
  .counseling-session-card__meta {
    grid-template-columns: 1fr;
  }
}

/* ===== AI RESULT BOX ===== */
.ai-result-box {
  background: linear-gradient(135deg, #f0f4ff, #f5f3ff);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
  position: relative;
}

.ai-result-box__title {
  font-size: 15px;
  font-weight: 700;
  color: #4c1d95;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #c7d2fe;
}

.ai-analysis-body {
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
  line-height: 1.45;
  white-space: normal;
}

/* .ai-text(1.9·pre-wrap)보다 우선 — AI 분석 본문만 촘촘하게 */
.ai-result-box .ai-text.ai-analysis-body {
  line-height: 1.45;
  font-size: 13.5px;
  white-space: normal; /* .ai-text의 pre-wrap이 나중에 선언되어 덮어쓰므로 여기서 명시. nl2br() 잔여 \n이 빈 줄로 보이던 문제 방지 */
}

.cm-hidden-ai-field {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  resize: none;
}

.ai-result-box .ai-analysis-section-label {
  font-size: 13px;
  font-weight: 700;
  color: #4338ca;
  margin: 0 0 0.45em;
  line-height: 1.3;
  display: block;
}

.ai-result-box .ai-analysis-section-label:first-of-type {
  margin-top: 0;
}

/* 이전 본문과 다음 [섹션] 사이: 빈 줄 한 줄 분량(제목↔본문은 위 margin-bottom만으로 촘촘히) */
.ai-result-box .ai-analysis-section-label:not(:first-of-type) {
  margin-top: 1.15em;
}

.ai-result-box .ai-analysis-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.45em;
  line-height: 1.3;
  display: block;
}

.ai-result-box .ai-analysis-heading:not(:first-of-type) {
  margin-top: 1em;
}

/* AI 분석 본문 — 번호 목록 (div 기반, 번호 재시작 없음) */
.ai-result-box .ai-ol-wrap {
  margin: 0.3em 0 0.6em;
}
.ai-result-box .ai-ol-item {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  margin: 0.18em 0;
  line-height: 1.5;
}
.ai-result-box .ai-ol-num {
  min-width: 1.6em;
  flex-shrink: 0;
  color: #4338ca;
  font-weight: 700;
  text-align: right;
}
.ai-result-box .ai-ol-body {
  flex: 1;
}

/* AI 분석 본문 — 불릿 목록 (div 기반) */
.ai-result-box .ai-ul-wrap {
  margin: 0.25em 0 0.6em 0.5em;
}
.ai-result-box .ai-ul-item {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  margin: 0.15em 0;
  line-height: 1.5;
}
.ai-result-box .ai-ul-item::before {
  content: '•';
  color: #4338ca;
  font-weight: 700;
  flex-shrink: 0;
}
.ai-result-box .ai-ul-body {
  flex: 1;
}

/* AI 분석 본문 — 상담기법별 질문 하위 번호 목록 */
.ai-result-box .ai-sub-wrap {
  margin: 0.2em 0 0.5em 1rem;
}
.ai-result-box .ai-sub-item {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  margin: 0.15em 0;
  line-height: 1.5;
}
.ai-result-box .ai-sub-num {
  min-width: 1.4em;
  flex-shrink: 0;
  color: #6366f1;
  font-weight: 600;
  text-align: right;
}
.ai-result-box .ai-sub-body {
  flex: 1;
}

/* 하위 호환 — 이전 ol/ul/li 스타일 (DB에 저장된 기존 분석 결과) */
.ai-result-box .ai-analysis-ol {
  margin: 0.35em 0 0.65em;
  padding-left: 1.35em;
  list-style-type: decimal;
}
.ai-result-box .ai-analysis-ol > li { margin: 0.12em 0; padding-left: 0.2em; }
.ai-result-box .ai-analysis-subquestions {
  margin: 0.25em 0 0.7em 1rem;
  padding-left: 1.35em;
  list-style-type: lower-alpha;
}
.ai-result-box .ai-analysis-subquestions > li { margin: 0.12em 0; }
.ai-result-box .ai-analysis-bullet-list {
  margin: 0.25em 0 0.75em 1rem;
  padding-left: 1.25rem;
  list-style: disc;
}
.ai-result-box .ai-analysis-bullet-list > li { margin: 0.12em 0; }
.ai-result-box .ai-analysis-technique-head {
  font-weight: 600;
  color: var(--text);
  margin: 0.75em 0 0.2em;
  line-height: 1.35;
}
.ai-result-box .ai-analysis-section-label + .ai-analysis-technique-head {
  margin-top: 0.35em;
}
.ai-result-box .ai-analysis-technique-num {
  color: #4338ca;
  font-weight: 700;
  margin-right: 0.35em;
}

.ai-result-content {
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
}

/* ===== LOADING ===== */
.loading-spinner {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13.5px; color: var(--text-muted);
}

.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  min-width: 260px;
  pointer-events: auto;
  animation: slideUp .25s ease;
  border-left: 4px solid var(--primary);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ===== PAGINATION ===== */
.pagination {
  display: flex; align-items: center; gap: 4px;
  justify-content: center;
  margin-top: 20px;
}

.page-btn {
  min-width: 34px; height: 34px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  font-family: inherit;
  padding: 0 8px;
}

.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ===== SEARCH BAR ===== */
.search-bar {
  position: relative;
  flex: 1;
}

.search-bar input {
  width: 100%;
  padding: 9px 12px 9px 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color var(--transition);
}

.search-bar input:focus { border-color: var(--primary); }
.search-bar .search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 14px;
}

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header-left h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.page-header-left p {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

.page-header-right { display: flex; gap: 10px; flex-shrink: 0; }

/* ===== CLIENT HEADER ===== */
.client-header-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex; align-items: center; gap: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.client-avatar-lg {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.client-header-info { flex: 1; }
.client-header-info .client-name { font-size: 20px; font-weight: 700; }
.client-header-info .client-meta { display: flex; align-items: center; gap: 12px; margin-top: 6px; flex-wrap: wrap; }
.client-meta-item { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.client-header-actions { display: flex; gap: 8px; }

/* ===== RISK LEVEL BAR ===== */
.risk-bar { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.risk-bar-fill { height: 100%; border-radius: 4px; transition: width .5s ease; }
.risk-bar-fill.high { background: var(--danger); }
.risk-bar-fill.medium { background: var(--warning); }
.risk-bar-fill.low { background: var(--success); }

/* ===== RESOURCE CARDS ===== */
.resource-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}

.resource-card:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-1px); }

.resource-card .resource-category {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--primary); margin-bottom: 6px;
}

.resource-card .resource-name { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.resource-card .resource-info { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.resource-card .resource-desc { font-size: 13px; color: var(--text); margin-top: 10px; line-height: 1.6; }
.resource-card .resource-footer {
  margin-top: auto;
  flex-shrink: 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.resources-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

@media (min-width: 1100px) {
  .resources-stats-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.resources-view-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.resources-filter-panel {
  display: flex;
  flex-direction: column;
}

.resources-filter-search-row .resources-filter-submit-btn {
  flex-shrink: 0;
  align-self: center;
}

.resources-filter-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.resources-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 16px;
  align-items: stretch;
  margin-bottom: 24px;
}

.resource-card--inactive {
  opacity: 0.92;
  border-style: dashed;
}

.resource-card__badge-inactive {
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 8px;
}

.resource-footer--wrap {
  flex-wrap: wrap;
  align-items: center;
}

.resource-footer--stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

/* 4칸 동일 너비 + (선택) 웹 아이콘 열 — CSS Grid·최소 열 너비로 글자 잘림 방지 */
.resource-footer__actions-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(5.75rem, 1fr));
  gap: 8px;
  align-items: stretch;
  width: 100%;
}

.resource-footer__actions-row--with-web {
  grid-template-columns: repeat(4, minmax(5.75rem, 1fr)) min-content;
}

.resource-footer__actions-row > .resource-footer__action-btn,
.resource-footer__actions-row > a.resource-footer__action-btn {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  white-space: nowrap;
  overflow: visible;
}

.resource-footer__actions-row .resource-footer__action-form.resource-inline-form {
  display: flex;
  margin: 0;
  min-width: 0;
  width: 100%;
}

.resource-footer__action-form .resource-footer__action-btn {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: visible;
  justify-content: center;
}

.resource-footer__action-spacer {
  min-height: 1px;
}

.resource-footer__referral {
  width: 100%;
  justify-content: center;
}

.resource-footer__web-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  padding-left: 10px;
  padding-right: 10px;
  box-sizing: border-box;
}

.resource-inline-form {
  display: inline;
}

.resource-inline-form button {
  vertical-align: middle;
}

/* ===== GENOGRAM CANVAS ===== */
.genogram-wrapper {
  display: flex; gap: 16px;
}

/* 사이드바 레이아웃(래퍼 안)에서만 세로 툴바 — 가계도 페이지 카드 툴바에는 적용하지 않음 */
.genogram-wrapper .genogram-toolbar {
  width: 160px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.genogram-tool-btn {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all var(--transition);
  font-family: inherit;
  text-align: left;
}

.genogram-wrapper .genogram-tool-btn {
  width: 100%;
}

.genogram-tool-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.genogram-tool-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.genogram-tool-section {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin-top: 10px; margin-bottom: 2px;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
}

.genogram-canvas-wrap {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  position: relative;
  min-height: 500px;
}

#genogramCanvas:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

#genogramCanvas {
  display: block;
  cursor: crosshair;
  background:
    linear-gradient(rgba(200,200,200,.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200,200,200,.2) 1px, transparent 1px);
  background-size: 30px 30px;
}

.genogram-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 12px 16px;
  background: #fafbfc;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.legend-item { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.legend-male { width: 14px; height: 14px; background: #3b82f6; border-radius: 2px; }
.legend-female { width: 14px; height: 14px; background: #ec4899; border-radius: 50%; }
.legend-deceased { width: 14px; height: 14px; background: #94a3b8; border-radius: 2px; position: relative; }
.legend-line { width: 24px; height: 3px; }
.legend-line.marriage { background: #1e293b; }
.legend-line.conflict { background: var(--danger); border-top: 2px dashed var(--danger); height: 0; }
.legend-line.close { background: var(--success); height: 4px; }
.legend-line.child { background: #64748b; }

/* ===== NEEDS ASSESSMENT ===== */
.need-domain-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
  transition: border-color var(--transition);
}

.need-domain-card.checked { border-color: var(--primary); }

.need-domain-header {
  padding: 12px 16px;
  background: #f8fafc;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
}

.need-domain-header input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}

.need-domain-title {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}

.need-domain-icon { font-size: 18px; }

.need-domain-body {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: none;
  background: #fff;
}

.need-domain-body.open { display: block; }

/* ===== DOCUMENT VIEWER ===== */
.doc-viewer {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
  font-size: 14px;
  line-height: 1.9;
  white-space: pre-wrap;
}

.doc-viewer h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; border-bottom: 2px solid var(--primary); padding-bottom: 8px; }
.doc-viewer h3 { font-size: 15px; font-weight: 700; margin: 16px 0 8px; color: var(--primary); }

/* ===== STEP FORM ===== */
.step-nav {
  display: flex;
  align-items: center;
  margin-bottom: 28px;
  gap: 0;
}

.step-item {
  flex: 1;
  display: flex;
  align-items: center;
}

.step-circle {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition);
}

.step-item.done .step-circle { background: var(--success); color: #fff; }
.step-item.active .step-circle { background: var(--primary); color: #fff; box-shadow: 0 0 0 4px rgba(37,99,235,.2); }

.step-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-left: 8px; white-space: nowrap; }
.step-item.active .step-label { color: var(--primary); }
.step-item.done .step-label { color: var(--success); }

.step-line { flex: 1; height: 2px; background: var(--border); margin: 0 4px; }
.step-item.done + .step-item .step-line,
.step-line.done { background: var(--success); }

/* ===== SECTION DIVIDER ===== */
.section-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.section-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 16px;
}

.section-title i { color: var(--primary); }

/* ===== INFO DETAIL ===== */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.info-item .info-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 4px; }
.info-item .info-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  overflow-wrap: anywhere;
  word-break: keep-all;
  white-space: normal;
}

/* 내담자 상세 상단 */
.client-view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 4px;
  box-shadow: var(--shadow-sm);
}
.client-view-identity {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  min-width: 0;
  flex: 1;
}
.client-avatar {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.client-avatar.male {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}
.client-avatar.female {
  background: linear-gradient(135deg, #db2777, #be185d);
}
.client-view-title-block { min-width: 0; flex: 1; }
.client-view-name-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 10px;
}
.client-view-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.client-view-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.client-view-meta {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  font-size: 13px;
  color: var(--text-muted);
}
.client-view-meta li {
  display: flex;
  align-items: center;
  gap: 8px;
}
.client-view-meta i {
  width: 1.1em;
  color: var(--primary);
  opacity: 0.85;
}
.client-view-meta strong {
  color: var(--text);
  font-weight: 600;
}
.client-view-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.client-view-tabs a.tab-btn {
  text-decoration: none;
  color: inherit;
}
.client-view-tabs a.tab-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 기본정보 탭: 구역 나눔 */
.client-detail-card__header {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.client-detail-card__title {
  margin: 0;
  font-size: 1.1rem;
}
.client-detail-card__hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.client-detail-card__body {
  padding-top: 8px;
}
.detail-section {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}
.detail-section:first-of-type {
  padding-top: 4px;
}
.detail-section:last-child {
  border-bottom: none;
  padding-bottom: 4px;
}
.detail-section__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.detail-section__title i {
  color: var(--primary);
  opacity: 0.9;
  width: 1.1em;
}
.detail-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 2px 10px;
  border-radius: 999px;
}
.info-grid--view {
  gap: 16px 20px;
}
.info-item.info-full {
  grid-column: 1 / -1;
}
.info-value-sub {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
}
.info-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.info-link:hover {
  text-decoration: underline;
}
.info-block {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}
.info-block__line + .info-block__line {
  margin-top: 6px;
}
.detail-empty {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}
.notes-callout {
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: #78350f;
}
.table-responsive-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}
.table-responsive-wrap .table {
  margin: 0;
  width: max-content;
  min-width: 100%;
}
.table--compact th,
.table--compact td {
  padding: 10px 14px;
  font-size: 13px;
}
.cell-muted {
  color: var(--text-muted);
  max-width: 220px;
}
@media (max-width: 768px) {
  .info-grid--view {
    grid-template-columns: 1fr;
  }
  .client-view-header {
    padding: 16px;
  }
  .client-view-name {
    font-size: 1.25rem;
  }
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state i { font-size: 48px; opacity: .3; margin-bottom: 16px; display: block; }
.empty-state h3 { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 13.5px; }

/* ===== FILTERS ===== */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-chip {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-muted);
  transition: all var(--transition);
  font-family: inherit;
}
.filter-chip:hover { border-color: var(--primary); color: var(--primary); }
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 50%, #1e3a5f 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(37,99,235,.3), transparent);
  top: -100px; right: -100px;
  border-radius: 50%;
}

.login-page::after {
  content: '';
  position: absolute;
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(124,58,237,.2), transparent);
  bottom: -50px; left: -50px;
  border-radius: 50%;
}

.login-card {
  background: rgba(255,255,255,.98);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  position: relative; z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: #fff;
  margin: 0 auto 14px;
  box-shadow: 0 4px 20px rgba(37,99,235,.4);
}

.login-logo h1 { font-size: 20px; font-weight: 800; color: var(--text); }
.login-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ===== DASHBOARD ===== */
.dashboard-grid { display: flex; flex-direction: column; gap: 20px; }
.dashboard-row { display: flex; gap: 20px; flex-wrap: wrap; }
.dashboard-row > * { flex: 1; min-width: 250px; }

.welcome-banner {
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 24px 28px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 4px 20px rgba(37,99,235,.3);
}
.welcome-banner h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.welcome-banner p { font-size: 14px; opacity: .85; }
.welcome-banner .date-display { font-weight: 700; }
.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.welcome-actions .btn { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.4); color: #fff; }
.welcome-actions .btn:hover { background: rgba(255,255,255,.35); color: #fff; }

/* Stat icons alternate names */
.stat-icon.stat-blue, .stat-icon.stat-primary { background: #eff6ff; color: var(--primary); }
.stat-icon.stat-green, .stat-icon.stat-success { background: #ecfdf5; color: var(--success); }
.stat-icon.stat-orange, .stat-icon.stat-warning { background: #fffbeb; color: var(--warning); }
.stat-icon.stat-red, .stat-icon.stat-danger { background: #fef2f2; color: var(--danger); }
.stat-icon.stat-purple, .stat-icon.stat-cyan { background: #f5f3ff; color: #7c3aed; }
.stat-number { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }

/* Risk bar chart */
.risk-chart { display: flex; flex-direction: column; gap: 14px; }
.risk-bar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.risk-bar-label { display: flex; align-items: center; gap: 8px; min-width: 120px; font-size: 13px; flex-shrink: 0; }
.risk-bar-track {
  flex: 1;
  min-width: 0;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
}
.risk-bar-fill { height: 100%; border-radius: 5px; transition: width .6s ease; }
.risk-bar-fill.bg-danger { background: var(--danger); }
.risk-bar-fill.bg-warning { background: var(--warning); }
.risk-bar-fill.bg-success { background: var(--success); }
.risk-bar-pct { font-size: 12px; color: var(--text-muted); min-width: 36px; text-align: right; }
.risk-total { text-align: right; font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* Quick actions — 기본 세로, 좁은 2열 대시보드에서 마지막 홀수 개일 때만 전체폭 */
.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quick-action-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition);
  background: var(--bg);
}
.quick-action-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.quick-action-btn i { width: 20px; text-align: center; color: var(--primary); font-size: 16px; }

/* ===== COMPATIBILITY CLASSES (Bootstrap-like) ===== */
/* Alert */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger, .alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--info-light); color: #164e63; border: 1px solid #a5f3fc; }

/* Spacing */
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 4px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-3 { margin-bottom: 16px !important; }
.mb-4 { margin-bottom: 24px !important; }
.mb-5 { margin-bottom: 32px !important; }
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 4px !important; }
.mt-2 { margin-top: 8px !important; }
.mt-3 { margin-top: 16px !important; }
.mt-4 { margin-top: 24px !important; }
.mt-5 { margin-top: 32px !important; }
.ms-auto { margin-left: auto !important; }
.ms-2 { margin-left: 8px !important; }
.me-1 { margin-right: 4px !important; }
.me-2 { margin-right: 8px !important; }
.p-0 { padding: 0 !important; }
.py-2 { padding-top: 8px !important; padding-bottom: 8px !important; }
.px-3 { padding-left: 16px !important; padding-right: 16px !important; }

/* Display / Flex */
.d-flex { display: flex !important; }
.d-inline { display: inline !important; }
.d-none { display: none !important; }
.d-block { display: block !important; }
.align-items-center { align-items: center !important; }
.justify-content-between { justify-content: space-between !important; }
.gap-2 { gap: 8px !important; }
.gap-3 { gap: 16px !important; }
.flex-wrap { flex-wrap: wrap !important; }
.flex-column { flex-direction: column !important; }

/* Typography */
.small, small { font-size: 12px !important; }
.fw-bold { font-weight: 700 !important; }
.fw-600 { font-weight: 600 !important; }
.text-start { text-align: left !important; }
.text-end { text-align: right !important; }

/* Tabs (alternate class name) */
.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  border-bottom: 2px solid var(--border);
  gap: 0;
  margin-bottom: 20px;
  overflow: visible;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Form grid */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-2 .form-group-full { grid-column: 1 / -1; }

/* 이름·생년월일·성별·전화번호 한 줄 (좁은 화면에서는 자동 줄바꿈) */
.form-grid-2 > .form-row-4 {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.form-row-4 .form-group {
  margin-bottom: 0;
}
@media (max-width: 1024px) {
  .form-grid-2 > .form-row-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .form-grid-2 > .form-row-4 {
    grid-template-columns: 1fr;
  }
}

/* 가족 구성원: 관계·이름·생년월일·성별·연락처 한 줄 */
.form-grid-2 > .form-row-5 {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.form-row-5 .form-group {
  margin-bottom: 0;
}
@media (max-width: 1200px) {
  .form-grid-2 > .form-row-5 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 768px) {
  .form-grid-2 > .form-row-5 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .form-grid-2 > .form-row-5 {
    grid-template-columns: 1fr;
  }
}

/* 접수일 1 · 발굴경로 1 · 발굴경로 상세 2 */
.form-grid-2 > .form-row-intake {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: 16px;
  margin-bottom: 18px;
  align-items: start;
}
.form-row-intake .form-group {
  margin-bottom: 0;
}
@media (max-width: 900px) {
  .form-grid-2 > .form-row-intake {
    grid-template-columns: 1fr 1fr;
  }
  .form-row-intake .intake-route-detail-cell {
    grid-column: 1 / -1;
  }
}
@media (max-width: 560px) {
  .form-grid-2 > .form-row-intake {
    grid-template-columns: 1fr;
  }
  .form-row-intake .intake-route-detail-cell {
    grid-column: auto;
  }
}
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.tab-nav-btns {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.tab-nav-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}
.tab-nav-bar .tab-nav-btns-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}
.tab-nav-bar .tab-nav-cancel {
  flex-shrink: 0;
}

/* 새 내담자: 가족 카드 · 긴급연락처 행 */
.client-repeatable-rows {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card-like-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}
.family-member-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.family-member-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.form-grid-emergency {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr auto;
  gap: 16px;
  align-items: start;
}
.form-grid-emergency .emergency-row-actions {
  display: flex;
  align-items: flex-end;
  padding-bottom: 2px;
}
@media (max-width: 900px) {
  .form-grid-emergency {
    grid-template-columns: 1fr 1fr;
  }
  .form-grid-emergency .emergency-row-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}
@media (max-width: 560px) {
  .form-grid-emergency {
    grid-template-columns: 1fr;
  }
}

/* 위험도 스크리닝: 한 줄 3개 */
.risk-screening-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.risk-screening-grid-3 .risk-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  margin: 0;
  width: 100%;
}
.risk-screening-grid-3 .risk-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.risk-screening-grid-3 .risk-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.45;
}
@media (max-width: 992px) {
  .risk-screening-grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .risk-screening-grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Risk screening result box */
.risk-result-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 16px;
  margin-bottom: 4px;
}
.risk-score-display {
  display: flex;
  align-items: center;
  gap: 16px;
}
.score-circle {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--primary-light);
  border: 3px solid var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  color: var(--primary);
  line-height: 1;
  flex-shrink: 0;
}
.score-circle small { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.score-circle.medium { border-color: var(--warning); color: var(--warning); background: #fffbeb; }
.score-circle.high   { border-color: var(--danger);  color: var(--danger);  background: #fff5f5; }
.score-circle.low    { border-color: var(--success); color: var(--success); background: #f0fdf4; }
.risk-level-text { font-size: 18px; font-weight: 700; color: var(--text); }

/* ----- 내담자 상세 · 위험도 탭 ----- */
.risk-view-card .card-body {
  padding: 22px 24px 26px;
}
.risk-view-card-header {
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.risk-view-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.risk-view-layout {
  display: grid;
  grid-template-columns: minmax(260px, 300px) 1fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 992px) {
  .risk-view-layout {
    grid-template-columns: 1fr;
  }
}
.risk-view-sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.risk-view-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 20px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(145deg, #fff 0%, #f8fafc 100%);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--border);
}
.risk-view-hero--low { border-left-color: var(--success); }
.risk-view-hero--medium { border-left-color: var(--warning); }
.risk-view-hero--high { border-left-color: var(--danger); }
.score-circle--view {
  width: 88px;
  height: 88px;
  font-size: 28px;
  border-width: 4px;
}
.score-circle--view small {
  font-size: 12px;
  margin-top: 2px;
}
.score-circle-num {
  line-height: 1;
}
.risk-view-hero-text {
  min-width: 0;
  flex: 1;
}
.risk-view-level-label {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.risk-view-level-value {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}
.risk-view-hero--low .risk-view-level-value { color: #15803d; }
.risk-view-hero--medium .risk-view-level-value { color: #b45309; }
.risk-view-hero--high .risk-view-level-value { color: #b91c1c; }
.risk-view-hero-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.45;
}
.risk-view-meter {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
}
.risk-view-meter-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.risk-view-meter-count {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.risk-view-meter-track {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.risk-view-meter-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}
.risk-view-meter-fill--low { background: linear-gradient(90deg, #4ade80, #22c55e); }
.risk-view-meter-fill--medium { background: linear-gradient(90deg, #fcd34d, #f59e0b); }
.risk-view-meter-fill--high { background: linear-gradient(90deg, #fb7185, #ef4444); }
.risk-view-meta {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border);
  font-size: 13px;
}
.risk-view-meta-row {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.risk-view-meta-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.risk-view-meta-row:first-child {
  padding-top: 0;
}
.risk-view-meta dt {
  margin: 0;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}
.risk-view-meta dd {
  margin: 0;
  text-align: right;
  color: var(--text);
  font-weight: 500;
}
.risk-view-section-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.risk-view-section-lead {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}
.risk-screening-grid--view {
  gap: 14px;
}
.risk-item--readonly {
  cursor: default;
  pointer-events: none;
  user-select: text;
}
.risk-item--readonly .risk-readonly-inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
}
.risk-screening-grid--view .risk-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 17px;
  background: #f1f5f9;
  color: #64748b;
}
.risk-item--readonly.checked .risk-icon {
  background: #fff1f2;
  color: #e11d48;
}
.risk-item--readonly.risk-item--off {
  opacity: 0.88;
  border-color: #e2e8f0;
  background: #fafbfc;
}
.risk-item--readonly.risk-item--off .risk-desc {
  color: #94a3b8;
}
.risk-readonly-body {
  flex: 1;
  min-width: 0;
}
.risk-pill {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.risk-pill--on {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}
.risk-pill--off {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #e2e8f0;
}
.risk-view-empty .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Korean postcode (Daum) address block */
.address-kr-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.address-kr-zip {
  max-width: 140px;
  flex: 0 0 auto;
  background: #f8fafc;
  cursor: default;
}
.address-kr-road {
  margin-bottom: 10px;
  width: 100%;
  background: #f8fafc;
  cursor: default;
}
.address-kr-road:not([readonly]) {
  background: #fff;
  cursor: text;
}
.address-kr-detail {
  width: 100%;
}
.address-kr-hint {
  margin-top: 8px;
  margin-bottom: 0;
}
.form-group input:not([type=checkbox]):not([type=radio]),
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  line-height: 1.5;
}
.form-group input:not([type=checkbox]):not([type=radio]):focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-group label.required { color: var(--text); }
.form-group label.required::after {
  content: ' *';
  color: var(--danger);
  font-weight: 700;
}
.form-group .required { color: var(--danger); }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 12px 14px; text-align: left; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--border); background: #f8fafc; }
.table td { padding: 12px 14px; font-size: 13.5px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table-striped tbody tr:nth-child(even) { background: #f8fafc; }
.table-hover tbody tr:hover { background: #f1f5f9; }
.table-sm th, .table-sm td { padding: 8px 12px; }

/* Genogram toolbar — 카드 안 가로 툴바 */
.genogram-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  align-items: stretch;
}
.genogram-toolbar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  min-height: 40px;
}
.genogram-toolbar__row--actions {
  justify-content: flex-end;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}
.genogram-toolbar__chunk {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-right: 14px;
  margin-right: 4px;
  border-right: 1px solid var(--border);
}
.genogram-toolbar__chunk:last-of-type {
  border-right: none;
  padding-right: 0;
  margin-right: 0;
}
.genogram-toolbar__chunk--grow {
  flex: 1;
  min-width: 200px;
}
.genogram-toolbar__label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  margin-right: 2px;
}
.genogram-toolbar .genogram-rel-select {
  min-width: min(220px, 100%);
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-card);
  color: var(--text);
}

@media (max-width: 768px) {
  .genogram-toolbar__chunk,
  .genogram-toolbar__chunk--grow {
    flex: 1 1 100%;
    border-right: none;
    padding-right: 0;
    margin-right: 0;
  }
  .genogram-toolbar__row--actions .tool-btn {
    flex: 1;
    justify-content: center;
  }
}

/* 가계도: 툴바 sticky 가 page-content overflow-x: clip 에 막히지 않도록 */
.page-content:has(> .genogram-page) {
  overflow-x: visible;
}

/* 가계도 페이지: 도구 모음을 스크롤해도 상단(앱 헤더 바로 아래)에 고정 */
.genogram-page .genogram-toolbar-sticky {
  position: sticky;
  top: var(--header-height);
  z-index: 40;
  background: var(--bg-card);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
}

@media print {
  .genogram-page .genogram-toolbar-sticky {
    position: static;
    box-shadow: none;
  }
}
.tool-group { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.tool-label { font-size: 12px; font-weight: 700; color: var(--text-muted); white-space: nowrap; }
.tool-btn {
  padding: 0 14px;
  min-height: 36px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition);
  font-family: inherit;
  text-align: center;
  white-space: nowrap;
}
.tool-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.tool-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tool-btn-danger.active, .tool-btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.tool-btn-success { border-color: var(--success); color: var(--success); }
.tool-btn-success:hover, .tool-btn-success.active { background: var(--success); color: #fff; }
.tool-btn-warning { border-color: var(--warning); color: var(--warning); }
.tool-btn-warning:hover, .tool-btn-warning.active { background: var(--warning); color: #fff; }

/* Canvas container */
.canvas-container { position: relative; overflow: auto; }
.canvas-hint { position: absolute; bottom: 10px; right: 12px; font-size: 12px; color: var(--text-light); background: rgba(255,255,255,.8); padding: 4px 10px; border-radius: 999px; pointer-events: none; }

/* Modal (alternate style using display:flex) */
.modal-overlay[style*="display:flex"],
.modal-overlay[style*="display: flex"] {
  opacity: 1;
  pointer-events: auto;
}
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-box.modal-lg { max-width: 800px; }

/* Legend */
.genogram-legend { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; font-size: 13px; }
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.leg-line { font-size: 16px; letter-spacing: 2px; }

/* AI text */
.ai-text { font-size: 14px; line-height: 1.9; white-space: pre-wrap; color: var(--text); }

/* AI 분석 마크다운 렌더 (담당자용) */
.cm-ai-md {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  word-break: break-word;
}
.cm-ai-md > *:first-child { margin-top: 0; }
.cm-ai-md > *:last-child { margin-bottom: 0; }
.cm-ai-md h1, .cm-ai-md h2, .cm-ai-md h3, .cm-ai-md h4 {
  margin: 1.1em 0 0.45em;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}
.cm-ai-md h1 { font-size: 1.35rem; border-bottom: 1px solid var(--border); padding-bottom: 0.35em; }
.cm-ai-md h2 { font-size: 1.2rem; }
.cm-ai-md h3 { font-size: 1.08rem; color: var(--primary); }
.cm-ai-md h4 { font-size: 1rem; }
.cm-ai-md p { margin: 0.65em 0; }
.cm-ai-md ul, .cm-ai-md ol { margin: 0.6em 0; padding-left: 1.35em; }
.cm-ai-md li { margin: 0.25em 0; }
.cm-ai-md blockquote {
  margin: 0.75em 0;
  padding: 0.65em 1em;
  border-left: 4px solid var(--primary);
  background: var(--primary-light);
  color: var(--text);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.cm-ai-md code {
  font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.9em;
  padding: 0.15em 0.4em;
  background: var(--bg-secondary);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.cm-ai-md pre {
  margin: 0.75em 0;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.cm-ai-md pre code { padding: 0; border: none; background: transparent; font-size: inherit; }
.cm-ai-md table { width: 100%; border-collapse: collapse; margin: 0.75em 0; font-size: 13px; }
.cm-ai-md th, .cm-ai-md td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.cm-ai-md th { background: var(--bg-secondary); font-weight: 600; }
.cm-ai-md hr { border: none; border-top: 1px solid var(--border); margin: 1.25em 0; }
.cm-ai-md a { color: var(--primary); text-decoration: underline; }
.cm-ai-md a:hover { color: var(--primary-dark); }

#aiModalContent.cm-ai-md {
  max-height: min(60vh, 520px);
  overflow-y: auto;
  padding-right: 4px;
}

/* 내담자 상세 · 가계도 탭: AI 본문 줄간·단일 줄바꿈 과다 완화 (ai-result-content 미사용) */
.cm-ai-md.cm-ai-md--genogram-tab {
  font-size: 13px;
  line-height: 1.5;
  white-space: normal;
}
.cm-ai-md.cm-ai-md--genogram-tab > *:first-child { margin-top: 0; }
.cm-ai-md.cm-ai-md--genogram-tab > *:last-child { margin-bottom: 0; }
.cm-ai-md.cm-ai-md--genogram-tab h1,
.cm-ai-md.cm-ai-md--genogram-tab h2,
.cm-ai-md.cm-ai-md--genogram-tab h3,
.cm-ai-md.cm-ai-md--genogram-tab h4 {
  margin: 0.65em 0 0.3em;
  line-height: 1.35;
}
.cm-ai-md.cm-ai-md--genogram-tab h1:first-child,
.cm-ai-md.cm-ai-md--genogram-tab h2:first-child,
.cm-ai-md.cm-ai-md--genogram-tab h3:first-child { margin-top: 0; }
.cm-ai-md.cm-ai-md--genogram-tab p { margin: 0.35em 0; line-height: 1.5; }
.cm-ai-md.cm-ai-md--genogram-tab ul,
.cm-ai-md.cm-ai-md--genogram-tab ol { margin: 0.35em 0; padding-left: 1.2em; }
.cm-ai-md.cm-ai-md--genogram-tab li { margin: 0.1em 0; line-height: 1.45; }
.cm-ai-md.cm-ai-md--genogram-tab br + br { display: none; }
.cm-ai-md.cm-ai-md--genogram-tab blockquote { margin: 0.45em 0; padding: 0.45em 0.85em; }

/* AI 욕구 우선순위 (needs 페이지·내담자 탭) */
.cm-ai-md.cm-ai-md--needs h1,
.cm-ai-md.cm-ai-md--needs h2,
.cm-ai-md.cm-ai-md--needs h3,
.cm-ai-md.cm-ai-md--needs h4 {
  margin-top: 0.75em;
  margin-bottom: 0.35em;
  line-height: 1.35;
}
.cm-ai-md.cm-ai-md--needs h1:first-child,
.cm-ai-md.cm-ai-md--needs h2:first-child,
.cm-ai-md.cm-ai-md--needs h3:first-child { margin-top: 0; }
.cm-ai-md.cm-ai-md--needs p { margin: 0.4em 0; line-height: 1.55; }
.cm-ai-md.cm-ai-md--needs ul,
.cm-ai-md.cm-ai-md--needs ol { margin: 0.4em 0; padding-left: 1.25em; }
.cm-ai-md.cm-ai-md--needs li { margin: 0.2em 0; line-height: 1.5; }

/* 서비스 계획 — AI 미리보기 */
.ai-result-box--plan .ai-plan-render {
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 14px 16px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-top: 4px;
}

.cm-ai-md.cm-ai-md--plan {
  font-size: 14px;
  line-height: 1.55;
}

.cm-ai-md.cm-ai-md--plan h1,
.cm-ai-md.cm-ai-md--plan h2,
.cm-ai-md.cm-ai-md--plan h3,
.cm-ai-md.cm-ai-md--plan h4 {
  margin-top: 0.75em;
  margin-bottom: 0.4em;
  line-height: 1.35;
}

.cm-ai-md.cm-ai-md--plan h1:first-child,
.cm-ai-md.cm-ai-md--plan h2:first-child,
.cm-ai-md.cm-ai-md--plan h3:first-child { margin-top: 0; }

.cm-ai-md.cm-ai-md--plan p { margin: 0.45em 0; }

.cm-ai-md.cm-ai-md--plan ul,
.cm-ai-md.cm-ai-md--plan ol { margin: 0.45em 0; padding-left: 1.3em; }

.cm-ai-md.cm-ai-md--plan li { margin: 0.2em 0; }

.cm-ai-md.cm-ai-md--plan table { font-size: 13px; }

/* 서비스 계획: 계획서 본문 단일 편집기(contenteditable) */
.plan-ai-editor-card__title {
  font-size: 15px;
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
}

.plan-ai-wysiwyg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.plan-ai-wysiwyg-toolbar .btn-xs {
  padding: 4px 8px;
  font-size: 12px;
  min-width: 2rem;
}

.plan-ai-toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 1.25rem;
  margin: 0 2px;
  background: var(--border);
  vertical-align: middle;
}

.plan-ai-toolbar-color {
  width: 2rem;
  height: 1.85rem;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  vertical-align: middle;
}

.plan-ai-wysiwyg {
  min-height: min(50vh, 420px);
  max-height: min(70vh, 640px);
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--bg-card);
  outline: none;
}

.plan-ai-wysiwyg:focus {
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.plan-ai-wysiwyg[contenteditable="true"]:empty::before {
  content: attr(data-placeholder);
  color: var(--text-light);
  pointer-events: none;
}

.plan-ai-generated-plan-field {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
}

/* 서비스 계획 — 서비스 목록 표 */
.service-plan-table--modern .service-plan-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.service-plan-grid-table {
  margin-bottom: 0;
  /* auto: 열별로 가장 넓은 셀 기준으로 맞추어 글자 잘림 완화, 같은 열은 동일 너비 */
  table-layout: auto;
  width: 100%;
}

.service-plan-grid-table thead th {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
  background: #f8fafc;
}

.service-plan-grid-table .form-control-sm {
  font-size: 13px;
}

/* 빈도·기간 = 담당 열(9rem)의 2/3 → 6rem */
.service-plan-col-name { min-width: 26rem; }
.service-plan-col-provider { min-width: 14rem; }
.service-plan-col-sm { min-width: 9rem; }
.service-plan-col-compact { min-width: 6rem; }
.service-plan-col-input .form-control-sm {
  width: 100%;
  min-width: 6rem;
  box-sizing: border-box;
}
.service-plan-col-compact.service-plan-col-input .form-control-sm {
  min-width: 4rem;
}
.service-plan-name-cell .form-control-sm {
  width: 100%;
  min-width: 20rem;
  box-sizing: border-box;
}
.service-plan-col-action {
  width: 1%;
  min-width: 2.75rem;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.service-plan-provider-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  min-width: 0;
}

.service-plan-provider-inline .svc-resource-select {
  flex: 1 1 auto;
  min-width: 7rem;
  width: auto;
  max-width: none;
  font-size: 12px;
}

.service-plan-add-resource-btns {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.service-plan-row-actions .btn {
  min-width: 2.25rem;
}

.service-plan-add-resource-btns .btn-xs {
  font-size: 11px;
}

@media (max-width: 900px) {
  .service-plan-col-name { min-width: 22rem; }
  .service-plan-col-provider { min-width: 11rem; }
  .service-plan-col-sm { min-width: 7.5rem; }
  .service-plan-col-compact { min-width: 5rem; }
  .service-plan-col-compact.service-plan-col-input .form-control-sm { min-width: 3.25rem; }
  .service-plan-name-cell .form-control-sm { min-width: 16rem; }
  .service-plan-provider-inline {
    flex-wrap: wrap;
  }
  .service-plan-provider-inline .svc-resource-select {
    flex: 1 1 100%;
    min-width: 0;
  }
}

.needs-ai-persist-field {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

.needs-ai__intro { font-size: 13px; line-height: 1.6; max-width: 42rem; }

.needs-ai__preview-wrap {
  margin-top: 16px;
  padding: 16px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.needs-ai__preview-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
}

.needs-ai__preview-title i { color: var(--primary); margin-right: 6px; }

.needs-ai__badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--primary-light);
  border-radius: 999px;
  vertical-align: middle;
}

.needs-ai__preview-body { min-height: 0; }

.needs-view-ai-raw {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.needs-ai-view__title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.needs-ai-view__title i { color: var(--warning); margin-right: 8px; }

.needs-ai-view__body { padding-top: 4px; }

/* 과거 욕구사정 이력 (needs.php · 내담자 탭) */
.needs-history-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.needs-history-card__count {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 12px;
  border-radius: 999px;
}

.needs-history-card__lead {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.needs-history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.needs-history-details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  overflow: hidden;
}

.needs-history-details[open] {
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.needs-history-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
}

.needs-history-summary::-webkit-details-marker {
  display: none;
}

.needs-history-summary::after {
  content: '\f078';
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
  display: inline-block;
  transition: transform 0.2s ease;
}

.needs-history-details[open] > .needs-history-summary::after {
  transform: rotate(180deg);
}

.needs-history-summary__main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.needs-history-summary__date {
  color: var(--text);
}

.needs-history-summary__saved {
  font-size: 13px;
  color: var(--text-muted);
}

.needs-history-summary__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.needs-history-summary__pill {
  display: inline-block;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
}

.needs-history-summary__pill--current {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.needs-history-summary__who {
  font-size: 13px;
  color: var(--text-muted);
}

.needs-history-summary__who i {
  margin-right: 4px;
}

.needs-history-details__body {
  padding: 0 14px 16px;
  border-top: 1px solid var(--border);
}

.needs-history-snapshot__subttl {
  font-size: 14px;
  font-weight: 700;
  margin: 14px 0 8px;
  color: var(--text);
}

.needs-history-snapshot__subttl:first-child {
  margin-top: 12px;
}

.needs-history-snapshot__subttl i {
  margin-right: 6px;
  color: var(--primary);
}

.needs-history-snapshot__overall {
  margin-bottom: 8px;
}

.needs-history-snapshot__overall-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.needs-grid--snapshot {
  margin-bottom: 8px;
}

.needs-history-snapshot__ai {
  margin-top: 8px;
}

.needs-history-ai-raw--hide {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  overflow: hidden !important;
}

.needs-view-past__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.needs-view-past__head h4 {
  font-size: 1rem;
}

.needs-view-past__head h4 i {
  color: var(--primary);
  margin-right: 8px;
}

.needs-history-details--compact {
  margin-bottom: 10px;
}

.needs-history-details--compact:last-child {
  margin-bottom: 0;
}

/* 내담자 상세 — 서비스 계획 탭 */
.client-plan-tab__lead {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.client-plan-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.client-plan-details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.client-plan-details[open] {
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.client-plan-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
}

.client-plan-summary::-webkit-details-marker {
  display: none;
}

.client-plan-summary::after {
  content: '\f078';
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
  display: inline-block;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.client-plan-details[open] > .client-plan-summary::after {
  transform: rotate(180deg);
}

.client-plan-summary__main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.client-plan-summary__date {
  font-weight: 600;
  color: var(--text);
}

.client-plan-summary__preview {
  flex: 1 1 200px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* 내담자 보기 · 자원연계: 서비스 계획에서 온 행의 계획↔연계 토글 */
button.client-plan-referral-status-btn {
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  line-height: 1.2;
  vertical-align: middle;
}
button.client-plan-referral-status-btn:hover {
  filter: brightness(0.92);
}

.client-plan-details__body {
  padding: 0 14px 16px;
  border-top: 1px solid var(--border);
  max-width: 100%;
  min-width: 0;
}

.client-plan-details__body .table-responsive {
  max-width: 100%;
}

.client-plan-section-title {
  font-size: 14px;
  font-weight: 700;
  margin: 14px 0 8px;
  color: var(--text);
}

.client-plan-section-title:first-child {
  margin-top: 12px;
}

.client-plan-section-title i {
  margin-right: 6px;
  color: var(--primary);
}

.client-plan-block {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.client-plan-svc-table {
  margin-bottom: 0;
  font-size: 13px;
}

.client-plan-svc-table th,
.client-plan-svc-table td {
  vertical-align: top;
}

.client-plan-ai-raw--hide {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  overflow: hidden !important;
}

.client-plan-ai-wrap .cm-ai-md--plan {
  padding-top: 4px;
}

/* 상담 기록: 읽기 전용 상세 */
.counseling-session-view__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.counseling-session-view__header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.counseling-session-view__meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px 20px;
  padding: 14px 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.counseling-session-view__meta-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.counseling-session-view__meta-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.counseling-session-view__meta-value {
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
}

.counseling-session-view__section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 18px 0 10px;
  color: var(--text);
}

.counseling-session-view__section-title:first-of-type {
  margin-top: 0;
}

.counseling-session-view__section-title i {
  margin-right: 8px;
  color: var(--primary);
}

.counseling-session-view__section-title--ai i {
  color: var(--warning);
}

/* 상담 기록 — AI 문서 탭(에디터) */
#aiDocsTabs .tab-content {
  position: relative;
}

.counsel-doc-html-store {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.counsel-doc-editor {
  min-height: 280px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  background: var(--card-bg, #fff);
  font-size: 14px;
  line-height: 1.55;
  outline: none;
}

.counsel-doc-editor:focus {
  border-color: var(--primary, #2563eb);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.counsel-doc-editor h3 {
  font-size: 1.05rem;
  margin: 0.75em 0 0.4em;
}

.counsel-doc-editor h4 {
  font-size: 0.95rem;
  margin: 0.65em 0 0.35em;
}

.counsel-doc-editor p {
  margin: 0.35em 0;
}

.counsel-doc-editor ul,
.counsel-doc-editor ol {
  margin: 0.4em 0 0.6em 1.25em;
}

.counseling-session-view__audio-item-body {
  flex: 1;
  min-width: 0;
}

.counseling-session-view__audio-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  padding: 0 14px;
  background: var(--card-bg, #fff);
}

.counseling-session-view__audio-player {
  display: block;
  width: 100%;
  max-width: 560px;
  height: 40px;
}

.counseling-session-view__audio-transcript-body {
  font-size: 14px;
  line-height: 1.55;
  padding: 10px 12px;
  background: var(--bg-subtle, #f8fafc);
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}

.counseling-session-view__text-block {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  padding: 12px 14px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.counseling-session-view__doc-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
}

.counseling-session-view__doc-card:last-child {
  margin-bottom: 0;
}

.counseling-session-view__doc-card-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.counseling-session-view__doc-card-head strong {
  font-size: 14px;
}

.counseling-session-view__doc-card-sub {
  font-size: 12px;
}

.counseling-session-doc-ai-raw--hide {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  overflow: hidden !important;
}

.cm-ai-md--counseling-doc {
  padding-top: 4px;
}

.counseling-record-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.counseling-list-actions-cell {
  white-space: nowrap;
}

.counseling-list-actions-cell .btn + .btn {
  margin-left: 4px;
}

.genogram-preview-canvas-wrap {
  width: 100%;
  overflow-x: auto;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: 0;
}
.genogram-preview-canvas-wrap canvas.genogram-preview-canvas--readonly {
  display: block;
  max-width: 100%;
  height: auto;
  vertical-align: top;
  pointer-events: none;
  user-select: none;
}

/* Dropdown */
.dropdown-item { padding: 10px 14px; cursor: pointer; font-size: 13.5px; transition: background var(--transition); border-bottom: 1px solid var(--border); }
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--primary-light); color: var(--primary); }

/* btn-outline-danger, btn-outline-success etc. */
.btn-outline-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }
.btn-outline-success { background: transparent; color: var(--success); border-color: var(--success); }
.btn-outline-success:hover { background: var(--success); color: #fff; }
.btn-outline-warning { background: transparent; color: var(--warning); border-color: var(--warning); }
.btn-outline-warning:hover { background: var(--warning); color: #fff; }
.btn-outline-info { background: transparent; color: var(--info); border-color: var(--info); }

/* Row/Col fallback */
.row { display: flex; flex-wrap: wrap; gap: 16px; }
.col { flex: 1; min-width: 0; }
.col-auto { flex: 0 0 auto; }

/* form-control-sm */
.form-control-sm { padding: 6px 10px !important; font-size: 13px !important; }

/* ===== TABLE RESPONSIVE UTILITY ===== */
.table-responsive {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.table-responsive > .table {
  width: max-content;
  min-width: 100%;
  margin-bottom: 0;
}
.table td,
.table th {
  overflow-wrap: anywhere;
  word-break: keep-all;
  vertical-align: middle;
}
.cm-counsel-summary-cell .cm-counsel-summary-line {
  word-break: normal;
  overflow-wrap: normal;
}
.counseling-cell-nowrap {
  white-space: nowrap;
}
.counseling-cell-softwrap {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: keep-all;
  max-width: 10rem;
}
.counseling-list-summary {
  max-width: 14rem;
  font-size: 12.5px;
  line-height: 1.45;
  white-space: normal;
}
.flex-shrink-0 {
  flex-shrink: 0;
}

/* ===== SIDEBAR OVERLAY (mobile) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
  cursor: pointer;
}
.sidebar-overlay.show { display: block; }

/* ===== PRINT STYLES ===== */
@media print {
  .sidebar, .top-header, .btn, .toast-container, .modal-overlay { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  body { background: #fff; }
}

/* ===== RESPONSIVE — 태블릿 ===== */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ===== RESPONSIVE — 모바일 (768px 이하) ===== */
@media (max-width: 768px) {
  /* ── 레이아웃 ── */
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
    transition: transform .25s ease, box-shadow .25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.28);
  }
  .main-wrapper { margin-left: 0; }
  .page-content { padding: 12px; }
  .top-header { padding: 0 12px; gap: 8px; }
  .page-title {
    font-size: 15px;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* 헤더 우측 사용자명 텍스트 숨김 (공간 절약) */
  .header-right > span { display: none; }

  /* ── 카드 ── */
  .card-header { flex-wrap: wrap; gap: 8px; }
  .card-body { padding: 14px; }

  /* ── 테이블: card-body.p-0 안의 테이블 가로 스크롤 ── */
  .card-body.p-0 {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* 스크롤 영역 안 표 최소 너비 (페이지 전체 가로 스크롤 방지) */
  .card-body.p-0 > table,
  .card-body.p-0 > .table,
  .card-body.p-0 > .table-responsive > .table,
  .table-responsive > table,
  .table-responsive > .table {
    min-width: 540px;
  }

  /* 카드형 표: thead 열 제목을 data-label로 쓰는 경우(.cm-table-cards-mode는 table-cards.js가 부여) */
  .table-responsive.cm-table-cards-mode,
  .table-responsive-wrap.cm-table-cards-mode {
    overflow-x: visible !important;
  }
  .cm-table-cards-mode > table,
  .cm-table-cards-mode > .table {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: separate;
    border-spacing: 0;
  }
  .cm-table-cards-mode thead {
    display: none !important;
  }
  .cm-table-cards-mode tbody,
  .cm-table-cards-mode tbody tr {
    display: block;
    width: 100%;
  }
  .cm-table-cards-mode tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
  }
  .cm-table-cards-mode tbody tr:last-child {
    margin-bottom: 0;
  }
  .cm-table-cards-mode tbody td {
    display: block;
    width: 100% !important;
    padding: 8px 0 !important;
    border: none !important;
    border-bottom: 1px solid var(--border) !important;
    text-align: left !important;
    box-sizing: border-box;
  }
  .cm-table-cards-mode tbody td:last-child {
    border-bottom: none !important;
  }
  .cm-table-cards-mode tbody td::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
    letter-spacing: 0.02em;
  }
  .cm-table-cards-mode table.table-hover tbody tr:hover {
    background: #f1f5f9;
  }
  .cm-table-cards-mode tfoot {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
  }
  .cm-table-cards-mode tfoot tr {
    display: block;
    width: 100%;
  }
  .cm-table-cards-mode tfoot td {
    display: block;
    border: none !important;
    padding: 6px 0 !important;
    text-align: left !important;
  }

  /* ── 폼 ── */
  .form-row,
  .form-row-3 { grid-template-columns: 1fr; }
  .form-row-4 { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  /* iOS에서 자동 줌 방지: font-size 16px 이상 */
  .form-control,
  select.form-control,
  textarea.form-control,
  .input-group .form-control { font-size: 16px !important; }
  .form-control { min-height: 44px; }
  select.form-control { min-height: 44px; }

  /* ── 버튼 터치 타겟 ── */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 36px; }
  .btn-xs { min-height: 30px; font-size: 12px; }

  /* ── 페이지 헤더 / 액션 바 ── */
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .page-actions .search-form { min-width: 0 !important; width: 100%; max-width: 100%; }
  .page-actions > .btn { justify-content: center; width: 100%; }
  .page-actions--clients > .btn,
  .page-actions--clients > a.btn {
    width: 100%;
    justify-content: center;
  }
  .counseling-list-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .counseling-list-toolbar .counseling-list-filter {
    width: 100%;
    min-width: 0;
  }
  .counseling-list-toolbar .counseling-list-filter select {
    width: 100%;
    max-width: 100%;
  }
  .counseling-list-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }
  .counseling-list-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* ── 필터 탭 가로 스크롤 ── */
  .filter-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    scrollbar-width: thin;
    gap: 4px;
  }
  .filter-tab { flex-shrink: 0; padding: 6px 12px; }
  .filter-tabs .total-count { flex-shrink: 0; }

  /* ── 탭 내비게이션 가로 스크롤 ── */
  .tabs-nav,
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tab-btn { flex-shrink: 0; min-height: 44px; }

  /* ── 통계 카드 ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }

  /* ── 대시보드 ── */
  .dashboard-row { flex-direction: column; }
  .dashboard-row > * { min-width: 0; }
  .welcome-banner { padding: 16px; flex-direction: column; align-items: flex-start; gap: 12px; }
  .welcome-banner h2 { font-size: 17px; }
  .welcome-actions { width: 100%; }
  .welcome-actions .btn { flex: 1; justify-content: center; font-size: 12.5px; padding: 8px 10px; }

  /* 빠른 실행: 2열 + 항목이 홀수 개면 마지막 버튼 전체폭 */
  .quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .quick-actions .quick-action-btn:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  .quick-action-btn { padding: 10px; font-size: 12.5px; }

  /* ── 정보 그리드 ── */
  .info-grid { grid-template-columns: 1fr; }
  .info-grid--view { grid-template-columns: 1fr; }

  /* ── 내담자 상세 헤더 ── */
  .client-view-header { flex-direction: column; gap: 12px; }
  .client-view-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .client-view-actions .btn { flex: 1 1 auto; justify-content: center; min-width: 70px; }
  .client-view-identity { flex-direction: column; gap: 12px; align-items: flex-start; }
  .client-view-meta { flex-wrap: wrap; gap: 6px 14px; }

  /* ── 모달 ── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 88vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin: 0;
  }
  .modal-body { padding: 16px; }
  .modal-header,
  .modal-footer { padding: 14px 16px; }
  .modal-footer { flex-wrap: wrap; gap: 8px; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* ── 가계도 ── */
  .genogram-wrapper { flex-direction: column; }
  .genogram-wrapper .genogram-toolbar { width: 100%; flex-direction: row; flex-wrap: wrap; }

  /* ── 페이지네이션 ── */
  .pagination-wrap { justify-content: center; flex-wrap: wrap; gap: 4px; }

  /* ── 상담 녹음 ── */
  .counseling-audio-item__row { flex-wrap: wrap; }

  .cell-muted {
    max-width: none;
  }

  /* ── 위험도 그리드 ── */
  .risk-indicator-grid { grid-template-columns: 1fr; }
  .risk-screening-grid-3 { grid-template-columns: 1fr; }
  .risk-view-layout { grid-template-columns: 1fr; }
}

/* ===== RESPONSIVE — 소형 폰 (480px 이하) ===== */
@media (max-width: 480px) {
  .page-content { padding: 8px; }
  .card-body { padding: 12px; }
  .card-header { padding: 11px 12px; }

  /* 통계 카드 — 한 열로 읽기 쉽게 */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .stat-card { padding: 12px 10px; gap: 10px; }
  .stat-icon { width: 40px; height: 40px; font-size: 16px; }
  .stat-number { font-size: 20px; }
  .stat-label { font-size: 11px; }

  /* 대시보드 웰컴 */
  .welcome-banner { padding: 12px; }
  .welcome-banner h2 { font-size: 14px; }
  .welcome-banner p { font-size: 12px; }
  .welcome-actions .btn { font-size: 11.5px; padding: 6px 8px; }

  /* 빠른 실행: 매우 좁은 화면은 1열 */
  .quick-actions {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .quick-actions .quick-action-btn:last-child:nth-child(odd) {
    grid-column: auto;
  }
  .quick-action-btn { padding: 8px; font-size: 12px; gap: 8px; }
  .quick-action-btn i { font-size: 14px; }

  /* 액션 버튼 전체폭 */
  .page-actions > .btn { width: 100%; }

  /* 테이블 폰트 축소 */
  .table th { font-size: 11px; padding: 8px 10px; }
  .table td { font-size: 12.5px; padding: 8px 10px; }
  .card-body.p-0 > table,
  .card-body.p-0 > .table,
  .card-body.p-0 > .table-responsive > .table,
  .table-responsive > table,
  .table-responsive > .table {
    min-width: 460px;
  }

  /* 위험도 바 레이블 너비 조정 */
  .risk-bar-label { min-width: 80px; font-size: 12px; }
  .risk-bar-pct { font-size: 11px; min-width: 28px; }

  /* 페이지네이션 */
  .page-btn { padding: 5px 9px; font-size: 12px; }
  .pagination-wrap { gap: 3px; }
}

/* ===== MISC ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.text-warning { color: var(--warning); }
.font-bold { font-weight: 700; }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.flex-1 { flex: 1; }
.w-100 { width: 100%; }
.hidden { display: none !important; }

/* ===== CLIENTS PAGE ===== */
.page-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.search-form {
  flex: 1;
  min-width: min(280px, 100%);
}

.search-bar {
  position: relative;
  display: flex;
  gap: 8px;
  flex: 1;
}

.search-bar input {
  flex: 1;
  padding-left: 38px;
  border-radius: var(--radius-sm);
}

.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.clients-search-group {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  width: 100%;
  gap: 8px;
}
.clients-search-bar {
  flex: 1 1 220px;
  min-width: 0;
}
.clients-search-bar input {
  width: 100%;
}
.clients-search-submit {
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  padding-left: 16px;
  padding-right: 16px;
}
@media (max-width: 480px) {
  .clients-search-submit {
    flex: 1 1 100%;
  }
}

.filter-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  padding-bottom: 2px; /* For active tab bottom border */
}

.filter-tab {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid transparent; /* To prevent jump on hover/active */
}

.filter-tab:hover { color: var(--primary); background: var(--primary-light); }
.filter-tab.active {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

.filter-tabs .total-count {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* ===== NEEDS ASSESSMENT (assessment/needs.php + view tab) ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.needs-page {
  max-width: 1100px;
  margin: 0 auto;
}

.needs-page__hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.needs-page__title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.needs-page__title i { color: var(--primary); margin-right: 8px; }

.needs-page__lead {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.65;
  max-width: 52rem;
}

.needs-page__back {
  flex-shrink: 0;
  align-self: center;
}

.needs-intro {
  background: linear-gradient(135deg, var(--primary-light) 0%, #f8fafc 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.needs-intro__title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.needs-intro__title i { color: var(--primary); margin-right: 8px; }

.needs-intro__list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text);
  font-size: 14px;
  line-height: 1.75;
}

.needs-intro__list li { margin-bottom: 8px; }
.needs-intro__list li:last-child { margin-bottom: 0; }

.needs-form-card {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.needs-form-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.needs-form-card__client {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
}

.needs-meta-row {
  display: grid;
  grid-template-columns: 1fr minmax(160px, 220px);
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 640px) {
  .needs-meta-row { grid-template-columns: 1fr; }
}

.needs-existing-note {
  font-size: 13px;
  margin-bottom: 20px;
  padding: 10px 14px;
  background: var(--warning-light);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.needs-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0;
}

.needs-section-hint {
  font-size: 13px;
  margin: -4px 0 16px;
}

.needs-domains-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.needs-domain-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.needs-domain-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.needs-domain-card--active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.15);
  background: linear-gradient(180deg, #fff 0%, var(--primary-light) 100%);
}

.needs-domain-card__label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.needs-domain-card__cb {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--primary);
}

.needs-domain-card__icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.needs-domain-card__name {
  font-size: 15px;
}

.needs-domain-card__hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 10px 0 0 30px;
  padding-left: 22px;
}

.needs-domain-card__detail {
  margin-top: 12px;
}

.needs-domain-card__textarea {
  font-size: 13px;
  line-height: 1.55;
  resize: vertical;
  min-height: 72px;
}

.needs-overall--inner {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
}

.needs-overall__lead {
  font-size: 13px;
  line-height: 1.6;
}

.needs-ai--section {
  border: 1px dashed #f59e0b;
  background: var(--warning-light);
  border-radius: var(--radius);
}

.needs-ai__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.needs-ai__result {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.needs-ai__content {
  font-size: 14px;
  line-height: 1.65;
}

.needs-ai__prior-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.needs-form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.needs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.needs-domain {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #f8fafc;
  font-size: 13px;
}

.needs-domain.active {
  border-color: #fecaca;
  background: var(--danger-light);
}

.needs-domain-label {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.needs-detail {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.needs-detail--empty {
  font-style: italic;
}

.needs-view-summary {
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
}

.needs-view-summary__title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}

.needs-view-summary__title i { margin-right: 8px; color: var(--primary); }

.needs-view-summary__body {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}
