:root {
  color-scheme: dark;
  --bg: #171818;
  --panel: #0f1011;
  --panel-soft: #17191a;
  --surface: #242626;
  --surface-hover: #2d3030;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f2f3f3;
  --muted: #9b9f9f;
  --faint: #707575;
  --accent: #d9ff65;
  --accent-ink: #172000;
  --danger: #ff8176;
  --sidebar-width: 278px;
  font-family: Inter, Pretendard, "Noto Sans KR", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  min-height: 0;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button, textarea { font: inherit; }
button { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px 12px;
  z-index: 20;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 4px 7px;
}

.brand-mark, .welcome-mark {
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  border-radius: 9px;
}

.brand-mark { width: 28px; height: 28px; font-size: 14px; }
.brand-name { font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}

.icon-button:hover { background: var(--surface); color: var(--text); }
.sidebar-close, .menu-button { display: none; }

.new-chat {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 9px;
  padding: 11px 12px;
  margin-top: 15px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 11px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}

.new-chat:hover { background: var(--surface); }
.new-chat .plus { font-size: 18px; line-height: 1; }
.new-chat kbd { margin-left: auto; color: var(--faint); font-size: 10px; background: transparent; }

.history-label {
  margin: 22px 10px 8px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.history { overflow-y: auto; min-height: 0; }

.history-item {
  position: relative;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 9px;
  padding: 9px 38px 9px 11px;
  color: #c5c8c8;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.history-item:hover, .history-item.active { background: var(--surface); color: var(--text); }

.history-delete {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  padding: 5px;
}

.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: var(--danger); }

.sidebar-footer { margin-top: auto; padding: 12px 5px 2px; }

.device-card { display: flex; gap: 10px; align-items: center; padding: 10px 7px; }
.device-card > div { display: flex; flex-direction: column; gap: 3px; }
.device-card strong { font-size: 12px; }
.device-card span:not(.status-dot) { font-size: 10px; color: var(--faint); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffc35c;
  box-shadow: 0 0 0 4px rgba(255, 195, 92, 0.1);
}

.status-dot.online { background: #78df9a; box-shadow: 0 0 0 4px rgba(120, 223, 154, 0.1); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 129, 118, 0.1); }
.privacy { padding: 7px; color: #555a5a; font-size: 9px; line-height: 1.4; }

.main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.topbar {
  height: 58px;
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid transparent;
  background: rgba(23, 24, 24, 0.86);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.model-switcher {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 650;
  padding: 8px 10px;
  border-radius: 9px;
}

.model-size { color: var(--faint); font-size: 11px; font-weight: 500; }
.topbar-actions { margin-left: auto; }

.conversation {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  scrollbar-gutter: stable;
  scroll-behavior: auto;
}

.welcome {
  min-height: calc(100vh - 190px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 44px 24px 28px;
}

.welcome.hidden { display: none; }
.welcome-mark { width: 50px; height: 50px; font-size: 23px; border-radius: 15px; box-shadow: 0 14px 42px rgba(217, 255, 101, 0.12); }
.welcome h1 { margin: 22px 0 7px; font-size: clamp(27px, 4vw, 36px); letter-spacing: -0.045em; font-weight: 680; }
.welcome > p { margin: 0; color: var(--muted); font-size: 14px; }

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  width: min(620px, 100%);
  margin-top: 34px;
}

.suggestion {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.025);
  text-align: left;
  cursor: pointer;
}

.suggestion:hover { background: var(--surface); border-color: rgba(255,255,255,0.14); transform: translateY(-1px); }
.suggestion-icon { width: 31px; height: 31px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 9px; background: var(--surface); color: var(--accent); }
.suggestion > span:last-child { display: flex; flex-direction: column; gap: 4px; }
.suggestion strong { font-size: 13px; font-weight: 650; }
.suggestion small { color: var(--faint); font-size: 11px; }

.messages { width: min(800px, 100%); margin: 0 auto; padding: 18px 24px 70px; }

.message {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 14px;
  padding: 19px 0;
}

.message + .message { border-top: 1px solid rgba(255,255,255,0.055); }
.avatar { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; font-size: 12px; font-weight: 800; }
.message.user .avatar { background: #e7e7e2; color: #1c1d1d; }
.message.assistant .avatar { background: var(--accent); color: var(--accent-ink); }
.message-role { font-size: 12px; font-weight: 700; margin: 6px 0 9px; }

.message-content { color: #e8e9e9; font-size: 14px; line-height: 1.78; overflow-wrap: anywhere; }
.message-content p { margin: 0 0 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content pre { overflow-x: auto; background: #0b0c0c; border: 1px solid var(--line); padding: 14px; border-radius: 11px; line-height: 1.55; }
.message-content code { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; background: rgba(255,255,255,0.07); padding: 2px 5px; border-radius: 5px; }
.message-content pre code { background: transparent; padding: 0; }
.message-content ul { padding-left: 21px; }
.message-actions { min-height: 26px; margin-top: 8px; }
.copy-button { opacity: 0; border: 0; background: transparent; color: var(--faint); padding: 4px 0; font-size: 11px; cursor: pointer; }
.message:hover .copy-button { opacity: 1; }
.copy-button:hover { color: var(--text); }

.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.scroll-latest {
  position: absolute;
  z-index: 14;
  left: 50%;
  bottom: 98px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(38, 40, 40, .94);
  color: #dfe1e1;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  font-size: 11px;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.scroll-latest:hover { background: #343737; color: #fff; }
.scroll-latest.hidden { display: none; }

.composer-wrap {
  flex: 0 0 auto;
  position: relative;
  z-index: 12;
  padding: 10px 22px max(13px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, rgba(23,24,24,0));
}

.composer {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 10px 10px 16px;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 18px;
  background: #232525;
  box-shadow: 0 14px 35px rgba(0,0,0,0.22);
}

.composer:focus-within { border-color: rgba(217,255,101,0.34); box-shadow: 0 14px 36px rgba(0,0,0,0.25), 0 0 0 3px rgba(217,255,101,0.04); }

.composer textarea {
  flex: 1;
  min-height: 28px;
  max-height: 170px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 4px 0;
  line-height: 1.5;
  font-size: 14px;
}

.composer textarea::placeholder { color: #777c7c; }

.send-button {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
}

.send-button:disabled { background: #4b4e4e; color: #868b8b; cursor: not-allowed; }
.send-button.stop { background: #eceee9; color: #191a1a; }
.disclaimer { margin: 8px auto 0; text-align: center; color: #5f6464; font-size: 9px; }
.sidebar-scrim { display: none; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #393c3c; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 300px); transform: translateX(-102%); transition: transform .22s ease; box-shadow: 12px 0 40px rgba(0,0,0,.38); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.5); }
  .sidebar-scrim.open { display: block; }
  .sidebar-close, .menu-button { display: grid; }
  .messages { padding-inline: 16px; }
  .message { grid-template-columns: 28px minmax(0, 1fr); gap: 11px; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion:nth-child(n+3) { display: none; }
  .composer-wrap { padding-inline: 12px; }
  .scroll-latest { bottom: 92px; }
  .welcome { justify-content: flex-start; padding-top: 12vh; }
}
