/* ============ Nick AI — styles ============ */
:root {
  --bg: #0b0d14;
  --bg-soft: #11141f;
  --panel: #151a28;
  --panel-2: #1b2133;
  --border: rgba(255, 255, 255, 0.07);
  --text: #eef1f8;
  --muted: #8b93a7;
  --faint: #5b6378;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --grad: linear-gradient(135deg, #7c5cff 0%, #22d3ee 100%);
  --user-bubble: linear-gradient(135deg, #5b3df5 0%, #4f46e5 100%);
  --danger: #f87171;
  --ok: #34d399;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --topbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1000px 500px at 85% -10%, rgba(124, 92, 255, 0.16), transparent 60%),
    radial-gradient(800px 400px at -10% 110%, rgba(34, 211, 238, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
  position: relative;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 10px 0;
  background: rgba(11, 13, 20, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; justify-content: center; }

.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  box-shadow: 0 4px 14px rgba(124, 92, 255, 0.45);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }

.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }

.brand-model {
  font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 180px;
}

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  flex: none;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
  width: min(320px, 86vw);
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 12px 12px;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.drawer-head span { font-weight: 700; font-size: 16px; padding-left: 4px; }

.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px; margin-bottom: 12px;
  border-radius: 14px; border: none; cursor: pointer;
  background: var(--grad); color: #fff; font-weight: 700; font-size: 14px;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.35);
  transition: transform 0.1s, filter 0.15s;
}
.new-chat-btn svg { width: 18px; height: 18px; }
.new-chat-btn:hover { filter: brightness(1.08); }
.new-chat-btn:active { transform: scale(0.97); }

.chat-list { list-style: none; overflow-y: auto; flex: 1; margin: 0 -4px; }
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 4px; }

.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 10px; margin: 2px 4px;
  border-radius: 12px; cursor: pointer; border: none; background: transparent;
  color: var(--text); font-size: 14px; text-align: left; width: calc(100% - 8px);
  transition: background 0.15s;
}
.chat-item:hover { background: var(--panel); }
.chat-item.active { background: var(--panel-2); }
.chat-item .ci-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-del {
  width: 28px; height: 28px; flex: none; border-radius: 8px; border: none; cursor: pointer;
  background: transparent; color: var(--faint); display: inline-flex; align-items: center; justify-content: center;
}
.chat-item .ci-del:hover { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.chat-item .ci-del svg { width: 15px; height: 15px; }

.scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 55;
  opacity: 0; transition: opacity 0.25s; backdrop-filter: blur(2px);
}
.scrim.show { opacity: 1; }

/* ---------- Chat area ---------- */
.chat { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }

.messages {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 14px 24px;
}

.empty {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 24px; gap: 10px;
  animation: fadeUp 0.5s ease both;
}
.empty-logo img {
  width: 84px; height: 84px; border-radius: 24px;
  box-shadow: 0 14px 44px rgba(124, 92, 255, 0.5), 0 4px 16px rgba(34, 211, 238, 0.25);
  animation: float 5s ease-in-out infinite;
}
.empty h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.3px; }
.empty p { color: var(--muted); font-size: 14.5px; max-width: 320px; line-height: 1.5; }
.wave { display: inline-block; }

.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; max-width: 420px; }

.chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 9px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.chip:hover { border-color: var(--accent); background: var(--panel-2); }
.chip:active { transform: scale(0.96); }

/* ---------- Message bubbles ---------- */
.msg { display: flex; gap: 10px; max-width: 100%; animation: fadeUp 0.3s ease both; }
.msg.user { justify-content: flex-end; }
.msg.bot { justify-content: flex-start; }

.avatar {
  width: 30px; height: 30px; border-radius: 10px; flex: none; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  background: var(--grad); font-size: 15px; box-shadow: 0 4px 12px rgba(124, 92, 255, 0.35);
}
.msg.user .avatar { background: var(--panel-2); box-shadow: none; font-size: 13px; }

.bubble {
  max-width: min(78%, 620px);
  border-radius: 18px;
  padding: 11px 14px;
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
}
.msg.user .bubble {
  background: var(--user-bubble); color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
}
.msg.bot .bubble {
  background: var(--panel); border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.bubble .bubble-meta {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px;
}

.file-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px; padding: 6px 10px; font-size: 12.5px; max-width: 100%;
}
.file-chip img { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; }
.file-chip .fc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.file-chip .fc-icon { font-size: 18px; line-height: 1; }
.file-chip .fc-size { color: var(--faint); font-size: 11px; }

.bubble-actions {
  display: flex; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity 0.2s;
}
.msg:hover .bubble-actions, .bubble-actions.show { opacity: 1; }
.act-btn {
  border: none; background: var(--panel-2); color: var(--muted);
  border-radius: 8px; padding: 5px 10px; font-size: 11.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  transition: color 0.15s, background 0.15s;
}
.act-btn:hover { color: var(--text); background: #262e45; }
.act-btn svg { width: 13px; height: 13px; }

/* ---------- Typing indicator ---------- */
.typing .dots { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing .dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing .dots span:nth-child(2) { animation-delay: 0.15s; }
.typing .dots span:nth-child(3) { animation-delay: 0.3s; }

/* ---------- Streaming caret ---------- */
.caret::after {
  content: ""; display: inline-block; width: 7px; height: 15px;
  background: var(--accent-2); margin-left: 3px; vertical-align: -2px;
  border-radius: 2px; animation: blink 0.9s infinite;
}

/* ---------- Markdown ---------- */
.md > * + * { margin-top: 0.6em; }
.md h1, .md h2, .md h3, .md h4 { font-weight: 700; line-height: 1.3; margin-top: 1em; }
.md h1 { font-size: 1.25em; } .md h2 { font-size: 1.15em; } .md h3 { font-size: 1.05em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: 0.25em 0; }
.md a { color: var(--accent-2); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md strong { font-weight: 700; }
.md code {
  font-family: var(--mono); font-size: 0.88em;
  background: rgba(255, 255, 255, 0.1); padding: 0.15em 0.4em; border-radius: 6px;
}
.msg.user .md code { background: rgba(255, 255, 255, 0.18); }
.md pre {
  background: #0a0d15; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; overflow-x: auto; margin: 0.8em 0; position: relative;
}
.md pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.5; }
.md pre .code-lang {
  position: absolute; top: 6px; right: 10px; font-size: 10px; color: var(--faint);
  text-transform: uppercase; letter-spacing: 0.5px; font-family: var(--mono);
}
.md blockquote {
  border-left: 3px solid var(--accent); padding: 2px 0 2px 12px;
  color: var(--muted); margin: 0.6em 0;
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.md table { border-collapse: collapse; width: 100%; margin: 0.8em 0; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--panel-2); }
.md img { max-width: 100%; border-radius: 10px; }

/* ---------- Composer ---------- */
.composer-wrap {
  padding: 8px 12px calc(10px + var(--safe-bottom));
  background: linear-gradient(180deg, transparent, rgba(11, 13, 20, 0.9) 30%);
  z-index: 20;
}

.attachments {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px;
  scrollbar-width: none;
}
.attachments::-webkit-scrollbar { display: none; }

.att {
  position: relative; flex: none;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px 28px 6px 6px; font-size: 12.5px; max-width: 190px;
  animation: fadeUp 0.2s ease both;
}
.att img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.att .att-icon { font-size: 20px; }
.att .att-info { min-width: 0; }
.att .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .att-size { color: var(--faint); font-size: 11px; }
.att .att-x {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
  border-radius: 7px; border: none; cursor: pointer;
  background: rgba(255, 255, 255, 0.08); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.att .att-x:hover { background: rgba(248, 113, 113, 0.2); color: var(--danger); }
.att .att-x svg { width: 12px; height: 12px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 22px;
  padding: 7px 7px 7px 6px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
}
.composer:focus-within { border-color: rgba(124, 92, 255, 0.55); }

#input {
  flex: 1; border: none; background: transparent; color: var(--text);
  font-family: var(--font); font-size: 15.5px; line-height: 1.45;
  resize: none; outline: none; padding: 8px 2px; max-height: 140px;
}
#input::placeholder { color: var(--faint); }

.send-btn {
  width: 42px; height: 42px; flex: none; border-radius: 16px; border: none;
  background: var(--grad); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.4);
  transition: transform 0.12s, filter 0.15s, opacity 0.2s;
}
.send-btn svg { width: 19px; height: 19px; }
.send-btn:hover { filter: brightness(1.1); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.send-btn.stop { background: var(--panel-2); box-shadow: none; border: 1px solid var(--border); }

.composer-note { text-align: center; color: var(--faint); font-size: 11px; margin-top: 6px; }

/* ---------- Sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.sheet-panel {
  position: relative; background: var(--bg-soft); border: 1px solid var(--border);
  border-bottom: none; border-radius: 24px 24px 0 0;
  padding: 14px 18px calc(20px + var(--safe-bottom));
  max-height: 88dvh; overflow-y: auto;
  animation: sheetUp 0.3s cubic-bezier(0.32, 0.72, 0, 1) both;
  max-width: 560px; margin: 0 auto; width: 100%;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { font-size: 19px; }

.field { display: block; margin-bottom: 18px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.field-label .hint { color: var(--faint); font-weight: 400; }

.field input[type="password"], .field input[type="text"], .field textarea, .field select {
  width: 100%; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 12px; padding: 11px 13px;
  font-family: var(--font); font-size: 14.5px; outline: none;
  transition: border-color 0.15s;
}
.field textarea { resize: vertical; min-height: 64px; }
.field select { appearance: none; background-image: 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='%238b93a7' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 13px center; padding-right: 36px; cursor: pointer; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: rgba(124, 92, 255, 0.6); }

.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; font-family: var(--mono); font-size: 13.5px; }

.field-note { font-size: 12px; color: var(--faint); margin-top: 7px; line-height: 1.45; }
.field-note a { color: var(--accent-2); text-decoration: none; }

.range-row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--faint); margin-top: 6px; }
#temp-value { color: var(--text); font-weight: 700; }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch-row .field-label { margin: 0; }
.switch-row input { width: 46px; height: 26px; accent-color: var(--accent); }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.primary-btn {
  flex: 1; padding: 13px; border-radius: 14px; border: none; cursor: pointer;
  background: var(--grad); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 8px 22px rgba(124, 92, 255, 0.4);
  transition: transform 0.1s, filter 0.15s;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: scale(0.98); }

.sheet-foot { font-size: 11.5px; color: var(--faint); line-height: 1.5; margin-top: 16px; text-align: center; }
.privacy-warn { display: block; color: #fbbf24; margin-top: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 16px; border-radius: 14px; font-size: 13.5px; max-width: 86vw;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; z-index: 120;
  transition: opacity 0.25s, transform 0.25s; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }

/* ---------- Animations ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes sheetUp { from { transform: translateY(60px); opacity: 0.6; } to { transform: none; opacity: 1; } }

/* ---------- Desktop polish ---------- */
@media (min-width: 640px) {
  .msg.user .bubble, .msg.bot .bubble { border-radius: 18px; }
  .chat { padding: 0 12px; }
  .topbar { padding-left: 18px; padding-right: 18px; }
}

/* ---------- Scrollbars ---------- */
.chat::-webkit-scrollbar { width: 5px; }
.chat::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 5px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
