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

/* ══════════════════════════════════════════
   테마 변수 — 라이트 (기본)
══════════════════════════════════════════ */
:root {
  --accent:  #4f7ef8;
  --accent2: #7c3aed;
  --accent-grad: linear-gradient(135deg, #4f7ef8, #7c3aed);

  --bg-login:   linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-body:    #e8edf5;
  --bg-chat:    #f0f2f5;
  --bg-header:  #ffffff;
  --bg-input:   #ffffff;
  --bg-settings: #ffffff;

  --bubble-me:    linear-gradient(135deg, #4f7ef8, #3563e9);
  --bubble-other: #ffffff;
  --bubble-alert: linear-gradient(135deg, #ffeaa7, #fdcb6e);
  --alert-border: rgba(253,203,110,.7);
  --alert-text:   #7d5a00;

  --text-primary:  #1a1a2e;
  --text-secondary:#666;
  --text-muted:    #aaa;
  --text-header:   #1a1a2e;
  --text-input:    #333;

  --border:  #e5e7eb;
  --divider: #e0e0e0;

  --shadow-header: 0 2px 12px rgba(0,0,0,.08);
  --shadow-input:  0 -2px 12px rgba(0,0,0,.06);
  --shadow-card:   0 4px 20px rgba(0,0,0,.10);
  --shadow-bubble: 0 1px 4px rgba(0,0,0,.08);

  --radius: 18px;
  --header-h: 62px;
  --input-h: 64px;

  /* 글자 크기 */
  --fs-bubble: .92rem;
  --fs-time:   .67rem;
  --fs-sender: .70rem;

  /* 글꼴 */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
}

/* ══════════════════════════════════════════
   다크 테마
══════════════════════════════════════════ */
[data-theme="dark"] {
  --bg-login:   linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  --bg-body:    #0f0f1a;
  --bg-chat:    #1a1a2e;
  --bg-header:  #16213e;
  --bg-input:   #1e2235;
  --bg-settings: #1e2235;

  --bubble-other: #2a2d3e;

  --text-primary:  #f0f0f0;
  --text-secondary:#aaa;
  --text-muted:    #666;
  --text-header:   #ffffff;
  --text-input:    #eee;

  --border:  #2d3151;
  --divider: #2a2d3e;

  --shadow-header: 0 2px 16px rgba(0,0,0,.4);
  --shadow-input:  0 -4px 20px rgba(0,0,0,.5);
  --shadow-card:   0 8px 32px rgba(0,0,0,.6);
  --shadow-bubble: 0 1px 4px rgba(0,0,0,.3);
}

/* ══════════════════════════════════════════
   글자 크기 단계
══════════════════════════════════════════ */
[data-font-size="sm"] { --fs-bubble: .80rem; --fs-time: .62rem; --fs-sender: .65rem; }
[data-font-size="md"] { --fs-bubble: .92rem; --fs-time: .67rem; --fs-sender: .70rem; }
[data-font-size="lg"] { --fs-bubble: 1.05rem; --fs-time: .73rem; --fs-sender: .76rem; }
[data-font-size="xl"] { --fs-bubble: 1.18rem; --fs-time: .80rem; --fs-sender: .82rem; }

/* ══════════════════════════════════════════
   기본 구조
══════════════════════════════════════════ */
body {
  font-family: var(--font);
  background: var(--bg-body);
  display: flex;
  justify-content: center;
  height: 100dvh;
  overflow: hidden;
  transition: background .3s;
}

#app {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg-chat);
}

#chat-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ══════════════════════════════════════════
   로그인
══════════════════════════════════════════ */
#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px 28px;
  background: var(--bg-login);
  transition: background .3s;
}

.login-card {
  width: 100%;
  background: rgba(255,255,255,.09);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 28px;
  padding: 44px 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 30px 70px rgba(0,0,0,.35);
}

.login-icon  { font-size: 3rem; line-height: 1; margin-bottom: 2px; }
.login-title { font-size: 1.7rem; font-weight: 800; color: #fff; letter-spacing: -.5px; }
.login-sub   { font-size: .82rem; color: rgba(255,255,255,.5); margin-top: -6px; margin-bottom: 6px; }

.login-input-wrap { width: 100%; position: relative; }
.login-input-wrap .icon {
  position: absolute; left: 14px; top: 50%;
  transform: translateY(-50%); font-size: .95rem; opacity: .6;
}
#login-screen input {
  width: 100%;
  padding: 13px 14px 13px 40px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 12px;
  font-size: .95rem; color: #fff; outline: none;
  transition: border-color .2s, background .2s;
  font-family: var(--font);
}
#login-screen input::placeholder { color: rgba(255,255,255,.4); }
#login-screen input:focus { border-color: rgba(255,255,255,.6); background: rgba(255,255,255,.18); }

#login-btn {
  width: 100%; padding: 14px;
  background: var(--accent-grad);
  border: none; border-radius: 12px;
  font-size: 1rem; font-weight: 700; color: #fff;
  cursor: pointer; margin-top: 4px;
  box-shadow: 0 4px 20px rgba(79,126,248,.4);
  transition: opacity .2s, transform .1s;
  font-family: var(--font);
}
#login-btn:hover  { opacity: .92; }
#login-btn:active { transform: scale(.98); }
#login-error { color: #ff7675; font-size: .82rem; text-align: center; }

/* ══════════════════════════════════════════
   헤더
══════════════════════════════════════════ */
#header {
  height: var(--header-h);
  background: var(--bg-header);
  color: var(--text-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-header);
  z-index: 20;
  transition: background .3s, box-shadow .3s;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 800; color: #fff; flex-shrink: 0;
}
.header-info { display: flex; flex-direction: column; }
.header-name { font-size: .98rem; font-weight: 700; color: var(--text-header); line-height: 1.2; }
.header-sub  { font-size: .68rem; color: var(--text-muted); line-height: 1.2; }

.header-right { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: var(--text-secondary);
  transition: background .15s;
}
.icon-btn:hover { background: var(--border); }

#conn-status {
  font-size: .70rem; font-weight: 600;
  padding: 4px 10px; border-radius: 20px;
  background: var(--border);
  display: flex; align-items: center; gap: 5px;
  color: var(--text-secondary);
  transition: all .3s;
}
#conn-status::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: #aaa; flex-shrink: 0; transition: all .3s;
}
#conn-status.online  { background: rgba(39,174,96,.12); color: #27ae60; }
#conn-status.online::before  { background: #27ae60; box-shadow: 0 0 6px #27ae60; }
#conn-status.offline { background: rgba(231,76,60,.12); color: #e74c3c; }
#conn-status.offline::before { background: #e74c3c; }
#conn-status.retry   { background: rgba(243,156,18,.12); color: #f39c12; }
#conn-status.retry::before   { background: #f39c12; }

/* ══════════════════════════════════════════
   검색 바
══════════════════════════════════════════ */
#search-bar {
  background: var(--bg-header);
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  max-height: 0; overflow: hidden; padding: 0 14px;
  transition: max-height .25s ease, padding .2s;
  z-index: 19;
}
#search-bar.open { max-height: 60px; padding: 10px 14px; }
#search-input {
  flex: 1; padding: 9px 14px;
  border: 1.5px solid var(--border); border-radius: 20px;
  font-size: .9rem; outline: none;
  background: var(--bg-chat); color: var(--text-primary);
  font-family: var(--font);
  transition: border-color .2s;
}
#search-input:focus { border-color: var(--accent); }
#search-clear {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--text-muted); padding: 4px;
}
#search-count { font-size: .78rem; color: var(--text-muted); white-space: nowrap; }

/* ══════════════════════════════════════════
   메시지 목록
══════════════════════════════════════════ */
#messages {
  flex: 1; overflow-y: auto;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 6px;
  transition: background .3s;
}
#messages::-webkit-scrollbar { width: 3px; }
#messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 2px; }

.date-divider {
  display: flex; align-items: center; gap: 8px;
  margin: 8px 0; color: var(--text-muted); font-size: .72rem;
}
.date-divider::before, .date-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--divider);
}

.msg-row {
  display: flex; align-items: flex-end; gap: 6px;
  max-width: 78%; animation: msgIn .22s ease;
}
.msg-row.me    { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.other { align-self: flex-start; }

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

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #a29bfe, #6c5ce7);
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 800; color: #fff;
  flex-shrink: 0; box-shadow: var(--shadow-bubble);
}
.msg-row.me .msg-avatar { background: var(--accent-grad); }
.scanner-avatar { background: linear-gradient(135deg, #fd9644, #e55039) !important; }

.msg-body { display: flex; flex-direction: column; gap: 2px; }
.msg-row.me    .msg-body { align-items: flex-end; }
.msg-row.other .msg-body { align-items: flex-start; }

.msg-sender { font-size: var(--fs-sender); color: var(--text-muted); padding: 0 4px; }

.bubble {
  padding: 9px 13px;
  border-radius: var(--radius);
  font-size: var(--fs-bubble);
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-bubble);
  font-family: var(--font);
  transition: font-size .2s;
}
.msg-row.me    .bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.other .bubble { background: var(--bubble-other); color: var(--text-primary); border-bottom-left-radius: 4px; }

/* 이미지 메시지 */
.bubble.img-bubble { padding: 4px; background: transparent !important; box-shadow: none; }
.bubble.img-bubble img {
  max-width: 220px; max-height: 280px; border-radius: 14px;
  display: block; cursor: pointer; box-shadow: var(--shadow-card);
}
/* 파일/동영상 */
.file-bubble {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; text-decoration: none;
}
.file-bubble .file-icon { font-size: 1.4rem; flex-shrink: 0; }
.file-bubble .file-info { display: flex; flex-direction: column; }
.file-bubble .file-name { font-size: var(--fs-bubble); font-weight: 600; color: inherit; }
.file-bubble .file-dl   { font-size: .72rem; opacity: .7; }

/* alert */
.msg-row.alert-row {
  align-self: center; max-width: 90%;
  flex-direction: column; align-items: center;
}
.msg-row.alert-row .bubble {
  background: var(--bubble-alert);
  color: var(--alert-text);
  border-radius: 12px;
  border: 1px solid var(--alert-border);
  font-size: calc(var(--fs-bubble) - .06rem);
  font-weight: 500; text-align: center;
  box-shadow: 0 2px 12px rgba(253,203,110,.3);
  padding: 8px 16px;
}

/* 검색 하이라이트 */
.highlight { background: #ffe082; border-radius: 3px; padding: 0 2px; color: #333; }

.msg-time { font-size: var(--fs-time); color: var(--text-muted); padding: 0 4px; transition: font-size .2s; }
.msg-row.me .msg-time { color: rgba(79,126,248,.6); }
[data-theme="dark"] .msg-row.me .msg-time { color: rgba(79,126,248,.8); }

/* ══════════════════════════════════════════
   첨부 메뉴
══════════════════════════════════════════ */
#attach-menu {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg-input);
  border-top: 1px solid var(--border);
  overflow: hidden;
  max-height: 0; opacity: 0;
  transition: max-height .25s ease, opacity .2s, padding .25s;
}
#attach-menu.open { max-height: 80px; opacity: 1; padding: 12px 16px; }

.attach-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--bg-chat); border: 1.5px solid var(--border);
  border-radius: 14px; padding: 10px 14px;
  cursor: pointer; flex: 1; transition: background .15s, border-color .15s;
  font-family: var(--font);
}
.attach-btn:hover { background: var(--border); border-color: var(--accent); }
.attach-btn .ab-icon { font-size: 1.3rem; line-height: 1; }
.attach-btn .ab-label { font-size: .65rem; color: var(--text-secondary); font-weight: 600; white-space: nowrap; }

/* ══════════════════════════════════════════
   입력창
══════════════════════════════════════════ */
#input-bar {
  min-height: var(--input-h);
  background: var(--bg-input);
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-input);
  transition: background .3s;
}

#attach-toggle {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg-chat); border: 1.5px solid var(--border);
  cursor: pointer; font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .2s;
  flex-shrink: 0; color: var(--text-secondary);
}
#attach-toggle.open { transform: rotate(45deg); background: var(--accent); color: #fff; border-color: var(--accent); }

#msg-input {
  flex: 1; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: 22px;
  font-size: .93rem; outline: none;
  background: var(--bg-chat); color: var(--text-primary);
  resize: none; line-height: 1.4;
  font-family: var(--font);
  transition: border-color .2s, background .3s;
}
#msg-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,126,248,.08); }
#msg-input::placeholder { color: var(--text-muted); }
#msg-input.ai-mode { border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124,58,237,.1); }

#logout-btn {
  width: 100%; padding: 13px;
  background: none; border: 1.5px solid #e74c3c;
  border-radius: 12px; color: #e74c3c;
  font-size: .95rem; font-weight: 600; cursor: pointer;
  transition: background .2s, color .2s;
}
#logout-btn:hover { background: #e74c3c; color: #fff; }

#ai-toggle-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: none; cursor: pointer;
  font-size: 1.1rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s, background .2s;
  opacity: 0.5;
}
#ai-toggle-btn.active {
  opacity: 1;
  background: rgba(124,58,237,.15);
  transform: scale(1.1);
}

#send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-grad); border: none; color: #fff;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(79,126,248,.4);
  transition: transform .15s, box-shadow .15s;
}
#send-btn:hover  { box-shadow: 0 6px 20px rgba(79,126,248,.5); }
#send-btn:active { transform: scale(.92); }
#send-btn svg { width: 17px; height: 17px; }

/* 숨겨진 파일 입력 */
.file-input-hidden { display: none; }

/* ══════════════════════════════════════════
   설정 패널 (바텀 시트)
══════════════════════════════════════════ */
#settings-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 50;
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
#settings-overlay.open { opacity: 1; pointer-events: all; }

#settings-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--bg-settings);
  border-radius: 24px 24px 0 0;
  padding: 14px 20px 32px;
  z-index: 51;
  box-shadow: 0 -8px 40px rgba(0,0,0,.2);
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1), background .3s;
  max-height: 90dvh;
  overflow-y: auto;
  /* 스크롤바 완전 숨김 */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#settings-panel::-webkit-scrollbar { display: none; }
#settings-panel.open { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 0 auto 14px; cursor: pointer;
}
.settings-title {
  font-size: 1rem; font-weight: 800;
  color: var(--text-primary); margin-bottom: 16px;
}

.settings-section { margin-bottom: 18px; }
.settings-label {
  font-size: .70rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .7px; margin-bottom: 8px;
}

/* 테마 토글 */
.theme-row { display: flex; gap: 8px; }
.theme-option {
  flex: 1; padding: 9px 8px;
  border: 2px solid var(--border); border-radius: 12px;
  background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .15s, background .15s;
  font-family: var(--font);
}
.theme-option .th-icon { font-size: 1.1rem; }
.theme-option .th-label { font-size: .82rem; font-weight: 600; color: var(--text-secondary); }
.theme-option.active { border-color: var(--accent); background: rgba(79,126,248,.08); }
.theme-option.active .th-label { color: var(--accent); }

/* 글꼴 옵션 */
.font-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.font-option {
  padding: 8px 10px; border: 2px solid var(--border); border-radius: 10px;
  background: none; cursor: pointer;
  text-align: left; transition: border-color .15s, background .15s;
  font-family: var(--font);
}
.font-option .fo-name  { font-size: .82rem; font-weight: 700; color: var(--text-primary); }
.font-option .fo-preview { font-size: .68rem; color: var(--text-muted); margin-top: 1px; }
.font-option.active { border-color: var(--accent); background: rgba(79,126,248,.08); }
.font-option.active .fo-name { color: var(--accent); }

/* 글자 크기 */
.size-row { display: flex; gap: 6px; }
.size-option {
  flex: 1; padding: 8px 4px; border: 2px solid var(--border);
  border-radius: 10px; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: border-color .15s, background .15s;
  font-family: var(--font);
}
.size-option .sz-text  { font-weight: 700; color: var(--text-primary); }
.size-option .sz-label { font-size: .68rem; color: var(--text-muted); }
.size-option.active { border-color: var(--accent); background: rgba(79,126,248,.08); }
.size-option.active .sz-text { color: var(--accent); }

/* ══════════════════════════════════════════
   이미지 라이트박스
══════════════════════════════════════════ */
#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
#lightbox.open { opacity: 1; pointer-events: all; }
#lightbox img { max-width: 95vw; max-height: 90dvh; border-radius: 12px; }

/* ══════════════════════════════════════════
   음성 녹음 버튼
══════════════════════════════════════════ */
#mic-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg-chat); border: 1.5px solid var(--border);
  cursor: pointer; font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
  flex-shrink: 0; color: var(--text-secondary);
}
#mic-btn.recording {
  background: #e74c3c; border-color: #e74c3c; color: #fff;
  animation: pulse-red 1s infinite;
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,.5); }
  50%       { box-shadow: 0 0 0 8px rgba(231,76,60,0); }
}

/* 오디오 메시지 */
.audio-bubble { padding: 6px 10px !important; }
.audio-bubble audio {
  max-width: 220px; height: 36px; border-radius: 8px; display: block;
  accent-color: var(--accent);
}

/* 즐겨찾기 표시 */
.msg-star {
  position: absolute; top: -6px; right: -6px;
  font-size: .75rem; line-height: 1;
  opacity: 0; transition: opacity .15s;
  pointer-events: none;
}
.msg-body { position: relative; }
.msg-body:hover .msg-star,
.starred .msg-star { opacity: 1; }
.starred .bubble { outline: 2px solid rgba(255,193,7,.5); outline-offset: 2px; }

/* ══════════════════════════════════════════
   컨텍스트 메뉴
══════════════════════════════════════════ */
#ctx-menu {
  position: absolute;
  background: var(--bg-settings);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  z-index: 60;
  display: flex; gap: 4px;
  opacity: 0; pointer-events: none;
  transform: scale(.85);
  transition: opacity .15s, transform .15s;
}
#ctx-menu.open { opacity: 1; pointer-events: all; transform: scale(1); }

.ctx-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 12px; border-radius: 10px;
  background: none; border: none; cursor: pointer;
  font-family: var(--font); transition: background .12s;
}
.ctx-item:hover { background: var(--border); }
.ctx-item .ci-icon  { font-size: 1.2rem; line-height: 1; }
.ctx-item .ci-label { font-size: .62rem; color: var(--text-secondary); font-weight: 600; }
.ctx-item.danger .ci-label { color: #e74c3c; }

/* ══════════════════════════════════════════
   설정 — 내보내기/푸시 버튼
══════════════════════════════════════════ */
.settings-action-row { display: flex; gap: 8px; margin-top: 2px; }
.settings-action-btn {
  flex: 1; padding: 10px 8px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font); transition: background .15s, border-color .15s;
}
.settings-action-btn:hover { background: var(--border); border-color: var(--accent); }
.settings-action-btn .sa-icon  { font-size: 1.1rem; }
.settings-action-btn .sa-label { font-size: .78rem; font-weight: 600; color: var(--text-secondary); }
.settings-action-btn.active-push .sa-label { color: #27ae60; }

/* ══════════════════════════════════════════
   날짜 이동 바
══════════════════════════════════════════ */
#date-jump-bar {
  background: var(--bg-header);
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  max-height: 0; overflow: hidden;
  transition: max-height .25s, padding .2s;
  z-index: 18;
}
#date-jump-bar.open { max-height: 56px; padding: 9px 14px; }
#date-jump-input {
  flex: 1; padding: 8px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: .9rem; outline: none;
  background: var(--bg-chat); color: var(--text-primary);
  font-family: var(--font); cursor: pointer;
}
#date-jump-go, #date-jump-close {
  padding: 8px 14px; border-radius: 10px;
  border: none; cursor: pointer; font-size: .85rem; font-family: var(--font);
}
#date-jump-go { background: var(--accent); color: #fff; font-weight: 700; }
#date-jump-close { background: var(--border); color: var(--text-secondary); }

/* ══════════════════════════════════════════
   핀 고정 바
══════════════════════════════════════════ */
#pin-bar {
  background: rgba(79,126,248,.08);
  border-bottom: 1.5px solid rgba(79,126,248,.25);
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  font-size: .82rem; color: var(--accent);
  z-index: 17; flex-shrink: 0;
}
.pin-icon { font-size: 1rem; flex-shrink: 0; }
#pin-bar-content { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#pin-bar-close {
  background: none; border: none; cursor: pointer;
  font-size: .9rem; color: var(--text-muted); padding: 2px 6px;
}

/* ══════════════════════════════════════════
   인용 답장 바
══════════════════════════════════════════ */
#quote-bar {
  background: rgba(79,126,248,.06);
  border-left: 3px solid var(--accent);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  max-height: 0; overflow: hidden;
  transition: max-height .2s, padding .2s;
  flex-shrink: 0;
}
#quote-bar.open { max-height: 52px; padding: 8px 12px; }
.quote-bar-inner { flex: 1; overflow: hidden; }
.quote-bar-label { font-size: .72rem; font-weight: 700; color: var(--accent); margin-right: 6px; }
#quote-bar-text {
  font-size: .8rem; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#quote-bar-close {
  background: none; border: none; cursor: pointer;
  font-size: .9rem; color: var(--text-muted); padding: 2px 6px; flex-shrink: 0;
}

/* 인용구 표시 (버블 안) */
.quote-block {
  background: rgba(0,0,0,.1);
  border-left: 2px solid rgba(255,255,255,.6);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 5px;
  font-size: calc(var(--fs-bubble) - .1rem);
}
.msg-row.other .quote-block {
  background: rgba(79,126,248,.08);
  border-left: 2px solid var(--accent);
}
.quote-block .q-sender { font-weight: 700; font-size: .65rem; opacity: .8; margin-bottom: 2px; }
.quote-block .q-text   { opacity: .85; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ══════════════════════════════════════════
   종목 태그
══════════════════════════════════════════ */
.stock-tag {
  display: inline-block;
  background: rgba(39,174,96,.12);
  color: #27ae60;
  border: 1px solid rgba(39,174,96,.3);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: calc(var(--fs-bubble) - .1rem);
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.stock-tag:hover { background: rgba(39,174,96,.22); }

/* ══════════════════════════════════════════
   AI 봇 버블
══════════════════════════════════════════ */
.msg-row.ai-row .msg-avatar { background: linear-gradient(135deg, #00b894, #00cec9); }
.msg-row.ai-row .bubble {
  background: linear-gradient(135deg, #f8fff8, #e8f8f5);
  color: var(--text-primary);
  border: 1px solid rgba(39,174,96,.2);
}
[data-theme="dark"] .msg-row.ai-row .bubble {
  background: linear-gradient(135deg, #1a3a2e, #1a2e2e);
  border-color: rgba(39,174,96,.3);
}
.ai-thinking {
  display: flex; align-items: center; gap: 5px;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--bubble-other);
  box-shadow: var(--shadow-bubble);
  font-size: var(--fs-bubble); color: var(--text-muted);
}
.dot-anim { display: flex; gap: 3px; }
.dot-anim span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: .4;
  animation: dotBounce 1.2s infinite;
}
.dot-anim span:nth-child(2) { animation-delay: .2s; }
.dot-anim span:nth-child(3) { animation-delay: .4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(.7); opacity: .4; }
  40%            { transform: scale(1); opacity: 1; }
}

/* 핀 표시 */
.pinned-indicator {
  font-size: .65rem; color: var(--accent);
  padding: 0 4px; display: inline-block;
}

/* ══════════════════════════════════════════
   오른쪽 아이콘바
══════════════════════════════════════════ */
#right-icon-bar {
  position: absolute; right: 0; top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 6px;
  background: var(--bg-settings);
  border-radius: 16px 0 0 16px;
  box-shadow: -3px 0 18px rgba(0,0,0,.12);
  z-index: 42;
  transition: transform .3s ease;
}
#right-icon-bar.collapsed {
  transform: translateX(calc(100% - 22px)) translateY(-50%);
}
#rib-toggle {
  width: 22px; height: 34px; border: none; background: none;
  cursor: pointer; font-size: .75rem; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  padding: 0; border-radius: 6px;
  margin-bottom: 2px;
  transition: color .15s;
}
#rib-toggle:hover { color: var(--text-primary); }
.rib-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: none; background: none; cursor: pointer;
  font-size: 1.2rem; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  position: relative;
}
.rib-btn:hover, .rib-btn.active { background: rgba(79,126,248,.12); }

/* ══════════════════════════════════════════
   오른쪽 슬라이드 패널
══════════════════════════════════════════ */
#right-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
#right-overlay.open { opacity: 1; pointer-events: all; }

#right-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 85%;
  background: var(--bg-settings);
  z-index: 41;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,.2);
}
#right-panel.open { transform: translateX(0); }

.rp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#rp-title { font-size: 1rem; font-weight: 800; color: var(--text-primary); }
#rp-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--border); cursor: pointer;
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
}

#rp-content { flex: 1; overflow-y: auto; padding: 16px; }

.rp-section { display: flex; flex-direction: column; gap: 12px; }

.panel-btn {
  padding: 10px 16px; border-radius: 10px;
  border: 1.5px solid var(--border);
  background: none; cursor: pointer;
  font-size: .85rem; font-weight: 700; color: var(--accent);
  font-family: var(--font);
  transition: background .15s;
}
.panel-btn:hover { background: rgba(79,126,248,.08); }

/* ── 핀 목록 패널 ── */
.pin-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-chat); cursor: pointer;
  transition: background .15s;
}
.pin-item:hover { background: var(--border); }
.pin-item .pi-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.pin-item .pi-text { flex: 1; font-size: .85rem; color: var(--text-primary); line-height: 1.4; }
.pin-item .pi-unpin {
  background: none; border: none; cursor: pointer;
  font-size: .75rem; color: var(--text-muted); padding: 2px 6px; flex-shrink: 0;
}

/* ── 알람 패널 ── */
.alarm-add-form {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-chat);
}
.alarm-add-form input[type="time"],
.alarm-add-form input[type="text"] {
  padding: 9px 12px; border-radius: 8px;
  border: 1.5px solid var(--border);
  font-size: .9rem; font-family: var(--font);
  background: var(--bg-settings); color: var(--text-primary); outline: none;
  transition: border-color .2s;
}
.alarm-add-form input:focus { border-color: var(--accent); }
.alarm-days { display: flex; gap: 6px; flex-wrap: wrap; }
.alarm-days label {
  display: flex; align-items: center; gap: 4px;
  font-size: .8rem; color: var(--text-secondary); cursor: pointer;
}
.alarm-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-chat);
}
.alarm-item .al-time { font-size: 1.2rem; font-weight: 800; color: var(--text-primary); flex: 1; }
.alarm-item .al-label { font-size: .75rem; color: var(--text-muted); }
.alarm-item .al-days { font-size: .7rem; color: var(--accent); }
.alarm-item .al-del {
  background: none; border: none; cursor: pointer;
  font-size: .9rem; color: var(--text-muted); padding: 4px;
}
.alarm-toggle { cursor: pointer; }

/* ── 날씨 패널 ── */
.weather-card {
  padding: 16px; border-radius: 16px;
  background: linear-gradient(135deg, #74b9ff, #0984e3);
  color: #fff; text-align: center;
}
.weather-emoji { font-size: 3.5rem; line-height: 1; margin-bottom: 6px; }
.weather-temp  { font-size: 2.2rem; font-weight: 800; }
.weather-desc  { font-size: .9rem; opacity: .85; margin-top: 4px; }
.weather-detail { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }
.weather-detail span { font-size: .78rem; background: rgba(255,255,255,.2); padding: 4px 10px; border-radius: 20px; }
.weather-location { font-size: .75rem; opacity: .7; margin-top: 8px; }
.weather-error { text-align: center; color: var(--text-muted); font-size: .9rem; padding: 20px; }

/* ── 학습 패널 ── */
.study-title { font-size: 1rem; font-weight: 800; color: var(--text-primary); margin-bottom: 8px; }
.study-subjects { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.subj-btn {
  padding: 14px 10px; border-radius: 12px;
  border: 2px solid var(--border); background: none; cursor: pointer;
  font-size: .9rem; font-weight: 700; color: var(--text-secondary);
  font-family: var(--font); transition: all .15s;
}
.subj-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(79,126,248,.06); }

.study-chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
  font-size: .85rem; font-weight: 700; color: var(--text-primary);
}
#study-change-subj {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 10px; font-size: .75rem; cursor: pointer;
  color: var(--accent); font-family: var(--font);
}

#study-messages {
  height: 300px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px 0;
}
.study-msg {
  padding: 8px 12px; border-radius: 12px;
  font-size: .85rem; line-height: 1.5; white-space: pre-wrap;
}
.study-msg.ai {
  background: linear-gradient(135deg, rgba(39,174,96,.1), rgba(0,184,148,.1));
  border: 1px solid rgba(39,174,96,.2);
  color: var(--text-primary); align-self: flex-start;
}
.study-msg.user {
  background: var(--bubble-me); color: #fff;
  align-self: flex-end; max-width: 80%;
}

.study-tts-ctrl {
  display: flex; gap: 8px; justify-content: flex-end;
}
.study-tts-ctrl button {
  padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: none; cursor: pointer;
  font-size: .8rem; font-family: var(--font); color: var(--text-secondary);
  transition: background .15s;
}
.study-tts-ctrl button:hover { background: var(--border); }

.study-input-row {
  display: flex; gap: 8px; align-items: center;
  border-top: 1px solid var(--border); padding-top: 10px;
}
#study-input {
  flex: 1; padding: 9px 12px; border-radius: 10px;
  border: 1.5px solid var(--border);
  font-size: .88rem; font-family: var(--font);
  background: var(--bg-chat); color: var(--text-primary); outline: none;
}
#study-input:focus { border-color: var(--accent); }
#study-voice-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid var(--border); background: none; cursor: pointer; font-size: 1rem;
}
#study-voice-btn.recording { background: #e74c3c; border-color: #e74c3c; color: #fff; }
#study-send-btn {
  padding: 8px 14px; border-radius: 10px;
  background: var(--accent); border: none; color: #fff;
  font-size: .85rem; font-weight: 700; cursor: pointer; font-family: var(--font);
}

/* ══════════════════════════════════════════
   배경 커스터마이징
══════════════════════════════════════════ */
.bg-row { display: flex; flex-direction: column; gap: 7px; }
.bg-first-row { display: flex; align-items: center; gap: 8px; }
.bg-option {
  display: flex; align-items: center; gap: 8px;
  font-size: .82rem; color: var(--text-secondary);
}
.bg-option input[type="color"] {
  width: 36px; height: 28px; border-radius: 7px;
  border: 1.5px solid var(--border); cursor: pointer; padding: 2px;
}
#bg-image-url {
  flex: 1; padding: 7px 10px; border-radius: 9px;
  border: 1.5px solid var(--border);
  font-size: .82rem; font-family: var(--font);
  background: var(--bg-chat); color: var(--text-primary); outline: none;
}
#bg-image-url:focus { border-color: var(--accent); }
.bg-btn-row { display: flex; gap: 7px; }
.bg-btn-row .panel-btn { flex: 1; padding: 7px 10px; font-size: .8rem; }

/* 알림음 */
.sound-row { display: flex; align-items: center; gap: 10px; }
.switch-label {
  display: flex; align-items: center; gap: 7px;
  font-size: .82rem; color: var(--text-secondary); cursor: pointer;
}

/* ══════════════════════════════════════════
   공통
══════════════════════════════════════════ */
.hidden { display: none !important; }
