/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  background: var(--surface-3); color: var(--ink);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur);
}
.btn:hover { background: var(--line); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--signal); color: #fff; }
.btn.primary:hover { background: var(--signal-2); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.danger:hover { background: color-mix(in srgb, var(--red) 22%, var(--red-soft)); }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; color: var(--ink-2); position: relative;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn[aria-pressed="true"] { background: var(--signal-soft); color: var(--signal); }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn .badge { position: absolute; top: 2px; right: 2px; }

/* 입력 */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.input, .textarea, .select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft); }
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input.invalid { border-color: var(--red); }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search-box .input { padding-left: 38px; background: var(--surface-2); border-color: transparent; }
.search-box .input:focus { background: var(--surface); border-color: var(--signal); }

/* 아바타 */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; overflow: hidden;
  font-weight: 700; font-size: 14px; color: #fff; letter-spacing: -.02em;
  background: var(--ink-3);
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.xl { width: 84px; height: 84px; font-size: 30px; }
.avatar.sm { width: 30px; height: 30px; font-size: 11.5px; }
.avatar.xs { width: 22px; height: 22px; font-size: 9px; }
.avatar.bot { background: linear-gradient(145deg, var(--violet), var(--signal)); }
.avatar.group { background: linear-gradient(145deg, #4a5f85, var(--ink-2)); border-radius: 14px; }
.avatar-wrap { position: relative; flex: none; }
.dot {
  position: absolute; right: 0; bottom: 0;
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--ink-4);
}
.dot[data-status="ONLINE"] { background: var(--green); }
.dot[data-status="AWAY"] { background: var(--amber); }
.dot[data-status="BUSY"] { background: var(--red); }
.dot[data-status="DO_NOT_DISTURB"] { background: var(--red); box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 3px var(--red); }
.dot[data-status="OFFLINE"] { background: var(--ink-4); }
.dot.inline { position: static; display: inline-block; border: 0; width: 8px; height: 8px; vertical-align: middle; margin-right: 6px; }

/* 배지 */
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700; line-height: 1;
  background: var(--amber); color: #2a1a00;
  font-variant-numeric: tabular-nums;
}
.badge.blue { background: var(--signal); color: #fff; }
.badge:empty { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 9px; border-radius: 12px;
  font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--ink-2);
}
.pill.blue { background: var(--signal-soft); color: var(--signal); }
.pill.amber { background: var(--amber-soft); color: var(--amber-ink); }
.pill.green { background: var(--green-soft); color: #137a4c; }
.pill.red { background: var(--red-soft); color: var(--red); }

/* 메뉴 */
.menu {
  position: absolute; z-index: 40; min-width: 200px;
  padding: 6px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-3);
  animation: pop var(--dur) var(--ease);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 9px; text-align: left; font-size: 14px;
  color: var(--ink);
}
.menu-item:hover { background: var(--surface-3); }
.menu-item.danger { color: var(--red); }
.menu-item .icon { color: var(--ink-3); }
.menu-item.danger .icon { color: var(--red); }
.menu-sep { height: 1px; background: var(--line-2); margin: 6px 4px; }
.menu-title { padding: 6px 10px 4px; font-size: 12px; color: var(--ink-3); font-weight: 600; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* 모달 — 네이티브 <dialog>. 최상위 레이어·포커스 가두기·Esc 닫기는 브라우저가 처리한다. */
.modal-root { display: contents; }
.modal {
  width: min(520px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px);
  padding: 0; border: 0; color: var(--ink);
  flex-direction: column;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-3);
  animation: rise var(--dur-slow) var(--ease);
}
.modal[open] { display: flex; }
.modal::backdrop { background: rgba(8, 14, 26, .45); backdrop-filter: blur(4px); animation: fade var(--dur) var(--ease); }
.modal.wide { width: min(680px, calc(100vw - 32px)); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px 22px; }
.modal-head h3 { flex: 1; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.modal-body { padding: 6px 22px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 20px; }
.menu.in-dialog { position: fixed; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.985); } }

/* 토스트 */
/* 데스크톱에서는 우상단: 우하단은 전송 버튼을 가린다 */
.toasts { position: fixed; right: 18px; top: 76px; z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 36px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--r-md);
  background: var(--toast-bg); border: 1px solid var(--toast-line); color: #fff; box-shadow: var(--shadow-3);
  animation: toast-in var(--dur-slow) var(--ease);
  cursor: default;
}
.toast.clickable { cursor: pointer; }
.toast .t-icon { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none; background: rgba(255,255,255,.12); }
.toast.success .t-icon { background: var(--green); }
.toast.error .t-icon { background: var(--red); }
.toast.info .t-icon { background: var(--signal); }
.toast .t-body { flex: 1; min-width: 0; }
.toast .t-title { font-weight: 700; font-size: 13.5px; }
.toast .t-text { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast.leaving { animation: toast-out var(--dur) var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@media (max-width: 900px) { .toasts { top: 12px; right: 12px; width: min(360px, calc(100vw - 24px)); } }

/* 탭 */
.tabs { display: flex; gap: 2px; padding: 4px; background: var(--surface-2); border-radius: 10px; }
.tab { flex: 1; height: 32px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-3); display: flex; align-items: center; justify-content: center; gap: 6px; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* 리스트 행 */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 12px; width: 100%; text-align: left;
  transition: background var(--dur) var(--ease);
}
.row:hover { background: var(--surface-2); }
.row .r-body { flex: 1; min-width: 0; }
.row .r-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-sub { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-side { display: flex; gap: 4px; align-items: center; flex: none; }

/* 섹션 제목 */
.section-title { font-size: 12.5px; font-weight: 700; color: var(--ink-3); padding: 14px 10px 6px; display: flex; align-items: center; gap: 8px; }
.section-title .count { font-weight: 600; color: var(--ink-4); }

/* 빈 상태 */
.empty { text-align: center; padding: 36px 16px; color: var(--ink-3); font-size: 13.5px; }
.empty .icon { width: 32px; height: 32px; margin: 0 auto 10px; color: var(--ink-4); }

/* 스켈레톤 */
.skel { background: linear-gradient(90deg, var(--surface-3) 25%, var(--line-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* 스위치 */
.switch { position: relative; width: 42px; height: 24px; border-radius: 12px; background: var(--ink-4); transition: background var(--dur); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform var(--dur) var(--ease); }
.switch[aria-checked="true"] { background: var(--signal); }
.switch:disabled { opacity: .45; cursor: not-allowed; }
.switch[aria-checked="true"]::after { transform: translateX(18px); }

/* 명령 팔레트 */
.palette { width: min(600px, calc(100vw - 32px)); margin: 10vh auto auto; }
.palette .search-box .input { height: 52px; font-size: 16px; border: 0; background: transparent; padding-left: 46px; }
.palette .search-box .icon { left: 18px; width: 22px; height: 22px; }
.palette-list { max-height: 50vh; overflow-y: auto; padding: 6px; border-top: 1px solid var(--line-2); }
.palette-list .row[aria-selected="true"] { background: var(--signal-soft); }
.palette-foot { padding: 8px 16px 12px; font-size: 12px; color: var(--ink-3); display: flex; gap: 14px; }
.palette-foot kbd { font-family: inherit; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface-2); }

/* 라이트박스 */
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(5, 9, 18, .9); display: grid; place-items: center; padding: 24px; animation: fade var(--dur); }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 48px); border-radius: 8px; box-shadow: var(--shadow-3); }
.lightbox .lb-bar { position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; }
.lightbox .icon-btn { color: #fff; background: rgba(255,255,255,.12); }
.lightbox .icon-btn:hover { background: rgba(255,255,255,.22); }
.lightbox .lb-caption { position: absolute; bottom: 16px; left: 0; right: 0; text-align: center; color: #cbd5e6; font-size: 13px; }

/* 연결 상태 */
.conn { position: fixed; top: 12px; left: 50%; translate: -50% 0; z-index: 45; display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 20px; background: var(--amber-soft); color: var(--amber-ink); font-size: 13px; font-weight: 600; box-shadow: var(--shadow-2); animation: rise var(--dur-slow) var(--ease); }
.conn[data-state="connected"] { display: none; }
.conn[data-state="error"] { background: var(--red-soft); color: var(--red); }
.conn .spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 테마 전환을 화면 전체 크로스페이드로 (View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--dur-slow); }
