/* ── 로컬 폰트 (CDN 없이 오프라인 환경 대응) ──────────────────── */
@font-face {
  font-family: 'Nanum Square';
  font-weight: 400;
  font-style: normal;
  src: url('/static/fonts/NanumSquare-R.woff2') format('woff2');
}
@font-face {
  font-family: 'Nanum Square';
  font-weight: 700;
  font-style: normal;
  src: url('/static/fonts/NanumSquare-B.woff2') format('woff2');
}
@font-face {
  font-family: 'Nanum Square';
  font-weight: 800;
  font-style: normal;
  src: url('/static/fonts/NanumSquare-EB.woff2') format('woff2');
}

  :root {
    --primary:       #540bff;
    --primary-light: #7c43ff;
    --accent:        #f0144e;
    --hero-grad:     linear-gradient(135deg, #d43f8d 0%, #540bff 50%, #0250c5 100%);
    --bg:            #ffffff;
    --bg-subtle:     #f8f8f7;
    --bg-nav:        #f5f5f5;
    --text:          #1d1d1d;
    --text-muted:    #807f7f;
    --border:        #d8d8d8;
    --border-light:  #ececec;
    --shadow-sm:     0 3px 6px rgba(0,0,0,0.10);
    --shadow-md:     0 3px 10px rgba(0,0,0,0.13);
    --nav-width:     240px;
    --radius-pill:   50px;
    --radius-card:   10px;
  }

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

  body {
    font-family: 'Nanum Square', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
  }

  /* 헤더 + 앱 본문을 세로로 쌓는 루트 래퍼 */
  .root-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  /* ── 왼쪽 네비게이션 사이드바 ── */
  .nav-sidebar {
    width: var(--nav-width);
    flex-shrink: 0;
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: width 0.22s ease, min-width 0.22s ease;
  }

  .nav-sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
  }

  .nav-sidebar.collapsed .nav-logo,
  .nav-sidebar.collapsed .nav-body,
  .nav-sidebar.collapsed .nav-footer {
    opacity: 0;
    pointer-events: none;
  }

  /* 사이드바 내부 닫기 버튼 (열렸을 때) */
  .nav-close-btn {
    width: 28px; height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: background 0.15s;
  }
  .nav-close-btn:hover { background: var(--bg-hover); color: var(--text); }

  /* 헤더 내부 열기 버튼 (닫혔을 때) */
  .nav-open-btn {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    display: none;
    align-items: center; justify-content: center;
    color: var(--text-muted);
    margin-right: 10px;
    transition: background 0.15s;
  }
  .nav-open-btn:hover { background: var(--bg-hover); color: var(--text); }
  body:not(.nav-open) .nav-open-btn { display: flex; }

  .nav-logo {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .nav-logo a {
    display: block;
    text-decoration: none;
  }

  .nav-logo img {
    width: 140px;
    height: auto;
    display: block;
  }

  .nav-body {
    flex-shrink: 0;
    padding: 12px 12px 0;
  }

  .nav-log-section {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 8px;
    min-height: 0;
  }

  .nav-log-divider {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    padding: 10px 8px 4px;
    border-top: 1px solid var(--border-light);
    margin-top: 4px;
  }

  .nav-section-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    padding: 8px 8px 4px;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    transition: background 0.12s, color 0.12s;
    margin-bottom: 2px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
  }

  .nav-item:hover { background: var(--bg-nav); color: var(--text); }

  .nav-item.active {
    background: #ede8ff;
    color: var(--primary);
    font-weight: 800;
  }

  .nav-item .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.6;
  }
  .nav-item.active .nav-icon { opacity: 1; }

  .nav-item .nav-badge {
    margin-left: auto;
    font-size: 10px;
    background: #e2e2e2;
    color: var(--text-muted);
    border-radius: 10px;
    padding: 1px 7px;
    font-weight: 700;
  }

  .nav-divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 10px 0;
  }

  .nav-footer {
    flex-shrink: 0;
    padding: 12px;
    border-top: 1px solid var(--border-light);
  }

  .btn-reset {
    width: 100%;
    padding: 10px;
    border: 1.5px solid var(--border);
    border-radius: 30px;
    background: transparent;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
  }

  .btn-reset:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: #fff5f7;
  }

  .version-text {
    font-size: 11px;
    color: #bebebe;
    text-align: center;
    margin-top: 8px;
  }

  /* ── 오른쪽 메인 영역 ── */
  .main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }

  /* ── 헤더 ── */
  header {
    flex-shrink: 0;
    background: var(--hero-grad);
    padding: 0 28px;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    position: relative;
    z-index: 100;
  }

  .header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 800;
    font-size: 17px;
  }

  .header-logo .logo-badge {
    background: rgba(255,255,255,0.22);
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 6px;
    padding: 2px 7px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
  }

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

  .header-desc {
    color: rgba(255,255,255,0.75);
    font-size: 12px;
  }

  .btn-disclaimer {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 20px;
    padding: 5px 12px;
    color: rgba(255,255,255,0.9);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.13s;
  }

  .btn-disclaimer:hover { background: rgba(255,255,255,0.25); }

  /* ── 페이지 컨테이너 ── */
  .page { display: none; flex: 1; flex-direction: column; overflow: hidden; }
  .page.active { display: flex; }

  /* ── 웰컴 (공통) ── */
  .welcome {
    text-align: left;
    padding: 80px 0 40px;
  }

  .welcome-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
  }

  .welcome-title {
    font-size: 36px;
    font-weight: 800;
    background: var(--hero-grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
  }

  .welcome-beta {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    background: #ede8ff;
    border-radius: 20px;
    padding: 3px 12px;
    display: inline-block;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    align-self: center;
  }

  .welcome p {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 2;
    margin-bottom: 0;
  }

  /* ── 말풍선 ── */
  .msg { display: flex; flex-direction: column; gap: 4px; }
  .msg.user { align-items: flex-end; }
  .msg.ai   { align-items: flex-start; }

  .msg-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 700;
    padding: 0 4px;
  }

  .bubble {
    max-width: 85%;
    padding: 12px 16px;
    line-height: 1.65;
    word-break: break-word;
    position: relative;
  }

  .msg.user .bubble {
    background: var(--primary);
    color: #fff;
    border-radius: 20px 20px 4px 20px;
    font-size: 14px;
  }

  .msg.ai .bubble {
    background: #fff;
    color: var(--text);
    border-radius: 4px 20px 20px 20px;
    border: 1px solid var(--border);
    margin-left: 12px;
    box-shadow: var(--shadow-sm);
    font-size: 14px;
  }

  /* ── 상태 칩 ── */
  .status-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: #f0ebff;
    border: 1px solid #c9b8ff;
    border-radius: 30px;
    font-size: 12px;
    color: var(--primary);
    font-weight: 700;
    margin-bottom: 8px;
  }

  .status-chip .dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--primary);
    animation: pulse 1s ease-in-out infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.35; transform: scale(0.65); }
  }

  /* ── 약품명 태그 ── */
  .drug-ref {
    color: var(--primary);
    font-weight: 700;
    border-bottom: 2px solid var(--primary);
    cursor: pointer;
    padding-bottom: 1px;
    transition: background 0.12s;
    position: relative;
  }

  .drug-ref:hover { background: #f0ebff; border-radius: 3px; }

  .drug-tooltip {
    display: none;
    position: fixed;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 10px 14px;
    min-width: 200px;
    max-width: 360px;
    width: max-content;
    box-shadow: var(--shadow-md);
    font-size: 12px;
    color: var(--text);
    font-weight: 400;
    z-index: 9999;
    line-height: 1.6;
    pointer-events: none;
    white-space: normal;
    word-break: keep-all;
  }

  .drug-tooltip .tt-name { font-weight: 800; font-size: 13px; margin-bottom: 4px; white-space: nowrap; }
  .drug-tooltip .tt-row { color: var(--text-muted); }
  .drug-tooltip .tt-row span { color: var(--text); font-weight: 700; }
  .drug-ref:hover .drug-tooltip { display: block; }

  /* ── 마크다운 ── */
  .bubble strong { font-weight: 800; }
  .bubble em { font-style: italic; }
  .bubble code {
    background: #f0ebff; border-radius: 4px;
    padding: 1px 5px; font-size: 12px;
    color: var(--primary); font-family: 'Courier New', monospace;
  }
  .bubble ul { padding-left: 18px; margin: 4px 0; }
  .bubble li { margin-bottom: 3px; list-style: none; }
  .bubble p { margin-bottom: 6px; }
  .md-li { margin: 2px 0 4px; padding-left: 0; }
  .bubble p:last-child { margin-bottom: 0; }
  .bubble h3, .bubble h4 { font-weight: 800; margin: 8px 0 4px; }
  .msg.user .bubble code { background: rgba(255,255,255,0.2); color: #fff; }

  /* ── 입력 ── */
  .input-area {
    flex-shrink: 0;
    padding: 14px 0 18px; /* 좌우 padding 제거 — inner wrap이 정렬 담당 */
    background: var(--bg);
    border-top: 1px solid var(--border-light);
  }

  .input-wrap {
    max-width: 1100px; /* feed-inner와 동일 */
    margin: 0 auto;
    padding: 0 14px; /* feed-inner와 동일 */
  }

  .input-box {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-sm);
    padding: 6px 6px 6px 20px;
    gap: 8px;
    transition: border-color 0.15s, box-shadow 0.15s;
  }

  .input-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(84,11,255,0.09), var(--shadow-sm);
  }

  textarea#userInput {
    flex: 1;
    border: none; outline: none; resize: none;
    font-family: inherit; font-size: 14px;
    color: var(--text); background: transparent;
    line-height: 1.5;
    min-height: 24px; max-height: 120px;
    padding: 6px 0;
  }

  textarea#userInput::placeholder, textarea#cdssInput::placeholder { color: #bebebe; font-size: 14px; }

  textarea#cdssInput {
    flex: 1;
    border: none; outline: none; resize: none;
    font-family: inherit; font-size: 14px;
    color: var(--text); background: transparent;
    line-height: 1.5;
    min-height: 24px; max-height: 120px;
    padding: 6px 0;
  }

  #sendBtn, #cdssSendBtn {
    flex-shrink: 0;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--primary);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, transform 0.1s;
  }

  #sendBtn:hover, #cdssSendBtn:hover { background: var(--primary-light); }
  #sendBtn:active, #cdssSendBtn:active { transform: scale(0.93); }
  #sendBtn:disabled, #cdssSendBtn:disabled { background: #d8d8d8; cursor: default; }
  #sendBtn svg, #cdssSendBtn svg { width: 17px; height: 17px; fill: #fff; }

  .input-hint {
    text-align: center;
    font-size: 11px;
    color: #bebebe;
    margin-top: 7px;
  }

  /* ── 우측 약품 사이드바 (반응형 flex) ── */
  .drug-sidebar {
    flex-shrink: 0;
    width: 0;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    transition: width 0.28s ease;
  }

  .drug-sidebar.open {
    width: 360px;
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0,0,0,0.08);
  }

  .dsb-header {
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
  }

  .dsb-drug-name {
    font-size: 16px; font-weight: 800;
    color: var(--text); flex: 1; padding-right: 8px;
    line-height: 1.3;
  }

  .dsb-close {
    flex-shrink: 0;
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 17px;
    transition: background 0.12s;
  }

  .dsb-close:hover { background: #f5f5f5; }

  .dsb-body {
    flex: 1; overflow-y: auto; padding: 0;
  }

  .dsb-body::-webkit-scrollbar { width: 3px; }
  .dsb-body::-webkit-scrollbar-thumb { background: #d8d8d8; border-radius: 3px; }

  .dsb-section { padding: 14px 18px; border-bottom: 1px solid var(--border-light); }
  .dsb-section:last-child { border-bottom: none; }

  .dsb-label {
    font-size: 11px; font-weight: 800;
    color: var(--text-muted); letter-spacing: 0.5px;
    text-transform: uppercase; margin-bottom: 5px;
  }

  .dsb-value { font-size: 13px; color: var(--text); line-height: 1.6; }
  .dsb-value.empty { color: #bebebe; font-style: italic; }

  .dsb-footer {
    flex-shrink: 0;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    background: var(--bg-subtle);
  }

  .btn-connectdi {
    display: flex; align-items: center;
    justify-content: center; gap: 8px;
    width: 100%; padding: 11px;
    background: var(--primary); color: #fff;
    border: none; border-radius: var(--radius-pill);
    font-family: inherit; font-size: 14px; font-weight: 800;
    cursor: pointer; text-decoration: none;
    transition: background 0.15s;
  }

  .btn-connectdi:hover { background: var(--primary-light); }
  .btn-connectdi svg { width: 14px; height: 14px; fill: #fff; }

  /* ── 마크다운 헤더 ── */
  .md-h3 {
    background: #fffbe6;
    border-left: 4px solid #f5c400;
    border-radius: 4px;
    padding: 7px 12px;
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
    margin: 14px 0 8px;
  }
  .md-h4 {
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
    margin: 14px 0 2px;
  }

  /* ── 위험 라벨 ── */
  .lbl { font-weight: 800; border-radius: 3px; padding: 0 3px; }
  .lbl-금기    { color: #c0003a; }
  .lbl-경고    { color: #d94000; }
  .lbl-주의    { color: #b07000; }
  .lbl-확인됨  { color: #1a7a3a; }
  .lbl-정보부족 { color: #555; }

  /* ── 에러 ── */
  .error-bubble {
    background: #fff5f7; border: 1px solid #ffccd9;
    border-radius: 8px; padding: 10px 14px;
    color: #c0003a; font-size: 13px; max-width: 75%;
  }

  /* ── 면책 고지 모달 ── */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
  }

  .modal-overlay.open { display: flex; }

  .modal-box {
    background: #fff;
    border-radius: 16px;
    width: 900px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  }

  .modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
  }

  .modal-title {
    font-size: 16px;
    font-weight: 800;
  }

  .modal-close {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
  }

  .modal-close:hover { background: #f5f5f5; }

  .modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text);
  }

  .modal-body h3 {
    font-size: 14px;
    font-weight: 800;
    margin: 14px 0 6px;
    color: var(--primary);
  }

  .modal-body h3:first-child { margin-top: 0; }

  .modal-body ul { padding-left: 18px; }
  .modal-body li { margin-bottom: 4px; }
  .modal-body p { margin-bottom: 10px; }
  .modal-body strong { font-weight: 800; }

  /* ── 피드 (CDSS 채팅 영역 공유) ── */
  .feed {
    flex: 1;
    overflow-y: auto;
    padding: 28px 0;
    scroll-behavior: smooth;
  }

  .feed::-webkit-scrollbar { width: 4px; }
  .feed::-webkit-scrollbar-thumb { background: #d8d8d8; border-radius: 4px; }
  .feed::-webkit-scrollbar-track { background: transparent; }

  .feed-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 14px; /* 기존 20px → 30% 감소 */
    display: flex;
    flex-direction: column;
    gap: 20px;
  }
