/* Kanana Chat - ChatGPT-style UI */

:root {
  --sidebar-bg: #171717;
  --sidebar-hover: #2f2f2f;
  --sidebar-text: #ececec;
  --sidebar-muted: #9b9b9b;
  --main-bg: #ffffff;
  --main-text: #0d0d0d;
  --border: #e5e5e5;
  --input-bg: #f4f4f4;
  --user-bg: #f4f4f4;
  --assistant-bg: transparent;
  --accent: #10a37f;
  --accent-hover: #0d8a6a;
  --error: #ef4444;
  --shadow: 0 0 15px rgba(0, 0, 0, 0.08);
  --sidebar-width: 260px;
  --header-height: 52px;
  --input-area-height: 120px;
  --font: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--main-text);
  background: var(--main-bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

textarea {
  font-family: inherit;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
}

.btn-new-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-new-chat:hover {
  background: var(--sidebar-hover);
}

.btn-sidebar-toggle,
.btn-sidebar-open {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: inherit;
  transition: background 0.15s;
}

.btn-sidebar-toggle {
  display: flex;
  color: var(--sidebar-muted);
}

.btn-sidebar-toggle:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.chat-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 14px;
  text-align: left;
  transition: background 0.15s;
  position: relative;
}

.chat-item:hover {
  background: var(--sidebar-hover);
}

.chat-item.active {
  background: var(--sidebar-hover);
}

.chat-item-title {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 28px;
}

.chat-item-model {
  font-size: 11px;
  color: var(--sidebar-muted);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
}

.chat-item-delete {
  opacity: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--sidebar-muted);
  flex-shrink: 0;
  transition: opacity 0.15s, background 0.15s;
  position: absolute;
  top: 10px;
  right: 8px;
}

.chat-item:hover .chat-item-delete {
  opacity: 1;
}

.chat-item-delete:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.model-badge {
  font-size: 12px;
  color: var(--sidebar-muted);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
}

/* ── Main ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--main-bg);
}

.main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.main-title {
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.model-select-wrap {
  margin-left: auto;
}

.model-select {
  appearance: none;
  padding: 7px 32px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--main-text);
  background: var(--main-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 10px center;
  cursor: pointer;
  transition: border-color 0.15s;
}

.model-select:hover:not(:disabled) {
  border-color: #aaa;
}

.model-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ── Chat area ── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height) - var(--input-area-height));
  padding: 32px 24px;
  text-align: center;
}

.welcome-icon {
  color: var(--accent);
  margin-bottom: 20px;
  opacity: 0.8;
}

.welcome h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
}

.welcome p {
  color: #666;
  margin-bottom: 32px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 640px;
  width: 100%;
}

.suggestion {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--main-text);
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}

.suggestion:hover {
  background: var(--input-bg);
  border-color: #ccc;
}

/* ── Messages ── */
.messages {
  max-width: 768px;
  margin: 0 auto;
  padding: 24px 16px 16px;
  width: 100%;
}

.message {
  display: flex;
  gap: 16px;
  padding: 20px 0;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
}

.message.user .message-avatar {
  background: #5436da;
  color: #fff;
}

.message.assistant .message-avatar {
  background: var(--accent);
  color: #fff;
}

.message-body {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}

.message-role {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.message-content {
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
}

.message-content p {
  margin-bottom: 0.75em;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.5;
}

.message-content code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.message-content pre code {
  background: none;
  padding: 0;
}

.message-content ul,
.message-content ol {
  padding-left: 1.5em;
  margin-bottom: 0.75em;
}

.message-content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: #666;
  margin: 12px 0;
}

.message-image {
  display: block;
  max-width: 280px;
  max-height: 280px;
  border-radius: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: #fff;
}

.message-text {
  white-space: pre-wrap;
}

.message.error .message-content {
  color: var(--error);
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: #999;
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Input area ── */
.input-area {
  flex-shrink: 0;
  padding: 12px 16px 20px;
  background: var(--main-bg);
}

.input-form {
  max-width: 768px;
  margin: 0 auto;
}

.image-preview {
  margin-bottom: 8px;
}

.image-preview-inner {
  position: relative;
  display: inline-block;
}

.image-preview-inner img {
  display: block;
  max-width: 120px;
  max-height: 120px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.btn-remove-image {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #333;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: background 0.15s;
}

.btn-remove-image:hover {
  background: #000;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px 10px 10px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.btn-attach {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.btn-attach:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--accent);
}

.btn-attach[hidden] {
  display: none;
}

.input-wrapper:focus-within {
  border-color: #aaa;
}

.input-wrapper textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  max-height: 200px;
  outline: none;
  padding: 4px 0;
}

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.input-hint {
  text-align: center;
  font-size: 12px;
  color: #999;
  margin-top: 10px;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .btn-sidebar-open {
    display: flex;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) {
  .btn-sidebar-toggle {
    display: none !important;
  }
}

/* scrollbar */
.chat-list::-webkit-scrollbar,
.chat-area::-webkit-scrollbar {
  width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.chat-area::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}
