@import url("./design-tokens.css");

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
}

body {
  display: flex;
  position: fixed;
  inset: 0;
}

/* ===== Character (하나 셀 내부 요소) ===== */
/* 주의: 아바타 그리드 패널/셀 스타일은 avatar-grid.css에서 관리 */

/* ===== Sidebar (desktop) ===== */
.sidebar {
  width: 240px;
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 20px 16px;
  font-size: 20px;
  font-weight: 600;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 150ms ease;
}

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

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.nav-item .badge {
  margin-left: auto;
  background: var(--accent-pink);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-full);
}

/* ===== Session List (sidebar) ===== */
.sidebar-sessions {
  padding: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 8px 8px;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-family);
  transition: all 150ms ease;
}

.session-item:hover {
  background: var(--bg-hover);
}

.session-item.active {
  background: var(--accent-light);
}

.session-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.session-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.session-summary {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.3;
}

.session-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px 8px;
  text-align: center;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  margin-top: 8px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 150ms ease;
}

.new-chat-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
  border-color: var(--accent);
}

.new-chat-btn.hidden {
  display: none;
}

.sidebar-bottom {
  padding: 8px;
  border-top: 1px solid var(--border);
}

/* ===== Agent Main Panel (직접 대화 모드) ===== */
.agent-main-panel {
  position: relative;
}

.agent-main-panel #agentMainCanvas {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  pointer-events: none;
}

/* 하나 부르기 버튼 */
.quick-cmd.cmd-hana-return {
  color: var(--accent-pink);
  border: 1.5px solid var(--accent-pink);
  background: var(--accent-pink-light);
  font-weight: 600;
  padding: 6px 16px;
}
.quick-cmd.cmd-hana-return:hover {
  background: var(--accent-pink);
  color: white;
}

/* 세션 목록: 에이전트 세션 표시 */
.session-item.session-agent {
  border-left: 3px solid transparent;
  padding-left: 9px;
}
.session-item.session-sori { border-left-color: var(--agent-sori-name); }
.session-item.session-seoyeon { border-left-color: var(--agent-seoyeon-name); }
.session-item.session-jihyun { border-left-color: var(--agent-jihyun-name); }

.session-owner-icon {
  font-size: 12px;
  margin-right: 2px;
}

/* ===== Character Area (하나 + 에이전트 카드) ===== */
.character-area {
  display: flex;
  flex-direction: row;
  height: 100%;
  flex-shrink: 0;
}

.character-panel {
  width: 420px;
  height: 100%;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
  transition: width 300ms ease;
}


.character-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #F8FAFF 0%, #E8EDFF 100%);
  transition: background 300ms ease;
}

#characterCanvas {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  pointer-events: none;
  /* 크기는 JS resizeCanvas()에서 비율 유지 계산 */
}

.character-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 48px 20px 24px;
  background: linear-gradient(transparent, rgba(0,0,0,0.45));
  z-index: 2;
}

.character-name {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-on-card);
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transition: opacity 150ms ease;
}

.character-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: rgba(255,255,255,0.9);
  margin-top: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-online);
  display: inline-block;
}

/* ===== View Container ===== */
.view-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  opacity: 0;
  transition: opacity 150ms ease;
}

.view.active {
  display: flex;
  opacity: 1;
}

/* ===== View Placeholder (Phase 4 준비) ===== */
.view-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 15px;
}

.view-placeholder-icon {
  font-size: 48px;
}

/* ===== Animations ===== */
@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Mobile Header (데스크탑 숨김) ===== */
.mobile-header {
  display: none;
}

/* ===== Drawer Overlay (데스크탑 숨김) ===== */
.drawer-overlay {
  display: none;
}

/* ===== Scrollbar ===== */
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== Mobile Layout (< 768px) ===== */
@media (max-width: 767px) {
  body {
    flex-direction: column;
  }

  /* 모바일 헤더 표시 */
  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 48px;
    padding: 0 12px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 30;
  }

  .drawer-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
  }

  .mobile-header-title {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
  }

  .mobile-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    object-fit: cover;
    object-position: top center;
    background: linear-gradient(180deg, #F8FAFF, #E8EDFF);
  }

  /* 드로어 배경 오버레이 */
  .drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease;
  }

  .drawer-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* 모바일: 헤더는 flex 흐름 안(48px 차지)이므로 뷰 패딩 불필요 */
  .view {
    padding-top: 0;
  }

  /* 채팅 뷰만: fixed 아바타 스트립 아래로 밀어내기 */
  .view-chat {
    padding-top: max(160px, 28svh);
    transition: padding-top 0.3s ease;
  }

  /* 아바타 토글 OFF: 스트립 없으므로 패딩 불필요 */
  body.avatar-off .view-chat {
    padding-top: 0;
  }

  /* 뷰 컨테이너 */
  .view-container {
    flex: 1;
    min-height: 0;
  }
}

/* ===== Tablet (768~1023px) ===== */
@media (min-width: 768px) and (max-width: 1023px) {
  .character-panel { width: 360px; }
}

/* ===== Work Home View (P3) ===== */
.work-home-lenses {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 16px 0;
}

.work-home-lens {
  background: var(--surface-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.work-home-lens-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.work-home-lens-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.work-home-lens-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.work-home-lens-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.work-home-lens-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.work-home-lens-item:hover {
  background: var(--surface-control-track);
}

.work-home-item-title {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-home-lens-loading,
.work-home-lens-more {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 8px;
  list-style: none;
}

/* lineage 상세 패널 */
.work-home-lineage {
  padding: 16px 0;
}

.work-home-lineage-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.work-home-lineage-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.work-home-lineage-events-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.work-home-lineage-events {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.work-home-lineage-event {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
}

.work-home-event-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.work-home-event-note {
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 720px) {
  .work-home-lenses {
    grid-template-columns: 1fr;
  }
}

