/* ==========================================================================
   Seufic Arctic — styles
   Dark near-black theme · DM Sans · ChatGPT-style layout · Apple-fluid motion
   ========================================================================== */

:root {
  /* surfaces */
  --bg: #0d0d0f;            /* very dark gray, almost black */
  --bg-sidebar: #0a0a0c;
  --surface: #17171b;
  --surface-2: #202027;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* text */
  --text: #ffffff;
  --text-dim: #a3a3ad;
  --text-faint: #6f6f79;

  /* arctic accent */
  --accent: #5ec8e6;
  --accent-strong: #7ad4ee;
  --accent-ink: #06222b;

  --radius: 14px;
  --radius-lg: 20px;

  /* apple-style springs (critically damped default) */
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
  --spring-soft: cubic-bezier(0.34, 1.2, 0.64, 1); /* slight bounce for momentum */

  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  font-optical-sizing: auto;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; }

button, input, textarea { font-family: inherit; }

::selection { background: rgba(94, 200, 230, 0.28); }

/* thin, unobtrusive scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.14) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ============================ AUTH SCREEN ================================= */
.auth-screen,
.setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 600px at 50% -10%, rgba(94,200,230,0.10), transparent 60%),
    var(--bg);
}

/* slow, static arctic glow behind the card (no animation — apple guidance
   warns against slow full-viewport oscillation; static keeps it calm) */
.auth-aurora {
  position: absolute; inset: -20%;
  pointer-events: none;
  background:
    radial-gradient(680px 420px at 26% 20%, rgba(94, 200, 230, 0.18), transparent 60%),
    radial-gradient(620px 460px at 78% 78%, rgba(122, 140, 240, 0.14), transparent 60%);
  filter: saturate(120%);
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 384px;
  /* translucent material — a real surface catching light, per apple materials */
  background: rgba(23, 23, 27, 0.72);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid var(--border-strong);
  border-top-color: rgba(255, 255, 255, 0.18); /* bright top edge = light on the material */
  border-radius: 24px;
  padding: 34px 30px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
  /* materialize: blur + scale in together, not just a fade */
  animation: materialize 560ms var(--spring) both;
}

.setup-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  animation: rise 480ms var(--spring) both;
}

.auth-brand {
  font-weight: 700;
  font-size: 27px;
  letter-spacing: -0.03em;   /* tighten large text (apple typography) */
  line-height: 1.1;
  margin-bottom: 6px;
  background: linear-gradient(176deg, #ffffff 0%, #bfe6f2 78%, #8fd6ec 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  width: fit-content;
}
.auth-brand::after {
  content: "";
  display: inline-block;
  width: 8px; height: 8px; margin-left: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  vertical-align: middle;
}

.auth-sub { color: var(--text-dim); margin: 0 0 22px; font-size: 14px; line-height: 1.5; }

/* ---- segmented control (iOS-style) ---- */
.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 22px;
  isolation: isolate;
}
.seg-indicator {
  position: absolute;
  top: 4px; left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  z-index: 0;
  /* the whole point: spring-driven slide, critically damped (no bounce) */
  transition: transform 340ms var(--spring);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.seg-btn {
  position: relative; z-index: 1;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim);
  font-size: 14px; font-weight: 600; letter-spacing: -0.005em;
  padding: 9px 0;
  border-radius: 9px;
  transition: color 200ms var(--spring), transform 120ms ease-out;
}
.seg-btn.active { color: var(--text); }
.seg-btn:active { transform: scale(0.97); }   /* respond on press */

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 12.5px; color: var(--text-dim);
  margin-bottom: 6px; letter-spacing: 0.01em;
}
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 160ms var(--spring), box-shadow 160ms var(--spring);
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94,200,230,0.18);
}

.btn-primary {
  width: 100%;
  margin-top: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 120ms ease-out, background 160ms var(--spring), opacity 160ms;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: scale(0.975); }   /* respond on press */
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-primary.loading { color: transparent; position: relative; }
.btn-primary.loading::after {
  content: "";
  position: absolute; inset: 0; margin: auto;
  width: 17px; height: 17px;
  border: 2px solid var(--accent-ink);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 620ms linear infinite;
}

/* ---- password field with reveal toggle ---- */
.password-wrap { position: relative; display: flex; }
.password-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 8px;
  background: none; border: none; cursor: pointer;
  color: var(--text-faint);
  display: grid; place-items: center;
  transition: color 160ms var(--spring), background 160ms var(--spring), transform 120ms ease-out;
}
.pw-toggle:hover { color: var(--text-dim); background: rgba(255,255,255,0.05); }
.pw-toggle:active { transform: translateY(-50%) scale(0.9); }
.pw-toggle .eye-off { display: none; }
.pw-toggle.on .eye { display: none; }
.pw-toggle.on .eye-off { display: block; }
.pw-toggle.on { color: var(--accent); }

.auth-fine {
  margin: 18px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}

.auth-note {
  font-size: 13px;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 14px;
  animation: rise 260ms var(--spring) both;
}
.auth-note-error {
  background: rgba(255, 90, 90, 0.12);
  border: 1px solid rgba(255, 90, 90, 0.35);
  color: #ffb4b4;
}
.auth-note-ok {
  background: rgba(94, 200, 230, 0.12);
  border: 1px solid rgba(94, 200, 230, 0.4);
  color: var(--accent-strong);
}

/* setup notice */
.setup-card { max-width: 440px; text-align: left; }
.setup-card h2 { margin: 14px 0 6px; font-size: 18px; letter-spacing: -0.01em; }
.setup-card p, .setup-card li { color: var(--text-dim); font-size: 14px; line-height: 1.6; }
.setup-card code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; color: var(--accent-strong); }
.setup-card ol { padding-left: 18px; }

/* ================================ APP ==================================== */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 264px 1fr;
}

/* ------------------------------ sidebar --------------------------------- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
}

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 6px 14px;
}
.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.brand::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px; margin-left: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px var(--accent);
  vertical-align: middle;
}

.new-chat {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 120ms ease-out, background 160ms var(--spring), border-color 160ms;
}
.new-chat:hover { background: var(--surface-2); border-color: var(--border-strong); }
.new-chat:active { transform: scale(0.98); }
.new-chat .plus { font-size: 18px; line-height: 1; color: var(--accent); }

.conversations {
  flex: 1; min-height: 0;
  overflow-y: auto;
  margin-top: 14px;
  display: flex; flex-direction: column; gap: 2px;
  /* scroll edge fade instead of a hard divider (apple materials) */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
}
.conv-empty { color: var(--text-faint); font-size: 13px; padding: 10px 8px; }

.conv {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-dim);
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background 140ms var(--spring), color 140ms;
}
.conv:hover { background: var(--surface); color: var(--text); }
.conv.active { background: var(--surface-2); color: var(--text); }
.conv-title {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-del {
  opacity: 0; font-size: 13px; transition: opacity 140ms;
  flex-shrink: 0;
}
.conv:hover .conv-del, .conv.active .conv-del { opacity: 0.55; }
.conv-del:hover { opacity: 1; }

.sidebar-foot {
  display: flex; align-items: center; gap: 8px;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 1px solid var(--border);
}
.user-chip {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 6px;
}
.avatar {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.user-email {
  font-size: 13px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  width: 34px; height: 34px; border-radius: 9px;
  font-size: 16px; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center;
  transition: background 140ms var(--spring), color 140ms, transform 120ms ease-out;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }

/* -------------------------------- main ---------------------------------- */
.main {
  position: relative;
  min-width: 0;
  display: flex; flex-direction: column;
  height: 100%;
  background: var(--bg);
}

/* translucent floating top bar; content scrolls under it */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  height: 56px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  background: rgba(13, 13, 15, 0.62);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.messages {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 76px 20px 24px;
  scroll-behavior: smooth;
}

/* chat column */
.msg, .empty-state, .loading-dots {
  max-width: 760px;
  margin-left: auto; margin-right: auto;
}

.msg { display: flex; margin: 18px auto; }
.msg.user { justify-content: flex-end; }
.msg.model { justify-content: flex-start; }

.bubble-body {
  font-size: 15.5px;
  line-height: 1.65;
  letter-spacing: 0.001em;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* user = right-aligned pill; assistant = plain full-width text (ChatGPT feel) */
.msg.user .bubble-body {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 11px 16px;
  border-radius: 18px 18px 6px 18px;
  max-width: 88%;
}
.msg.model .bubble-body { width: 100%; color: #efeff3; }

/* markdown inside assistant messages */
.bubble-body p { margin: 0 0 12px; }
.bubble-body p:last-child { margin-bottom: 0; }
.bubble-body h1, .bubble-body h2, .bubble-body h3 {
  letter-spacing: -0.015em; line-height: 1.25; margin: 18px 0 10px;
}
.bubble-body h1 { font-size: 21px; }
.bubble-body h2 { font-size: 18px; }
.bubble-body h3 { font-size: 16px; }
.bubble-body ul, .bubble-body ol { margin: 0 0 12px; padding-left: 22px; }
.bubble-body li { margin: 4px 0; }
.bubble-body a { color: var(--accent-strong); text-decoration: none; border-bottom: 1px solid rgba(122,212,238,0.35); }
.bubble-body a:hover { border-bottom-color: var(--accent-strong); }
.bubble-body code {
  background: var(--surface-2);
  padding: 2px 6px; border-radius: 6px;
  font-size: 0.9em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.bubble-body pre {
  background: #0a0a0c;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 12px;
}
.bubble-body pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; }
.bubble-body blockquote {
  margin: 0 0 12px; padding: 4px 14px;
  border-left: 3px solid var(--border-strong); color: var(--text-dim);
}
.bubble-body table { border-collapse: collapse; margin: 0 0 12px; width: 100%; }
.bubble-body th, .bubble-body td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }

/* empty state */
.empty-state { text-align: center; padding: 16vh 0 0; color: var(--text-dim); }
.empty-mark {
  font-size: 34px; font-weight: 700; letter-spacing: -0.035em;
  margin-bottom: 12px;
  /* arctic vibrancy — distinctive without shouting (frontend-design) */
  background: linear-gradient(176deg, #ffffff 0%, #bfe6f2 78%, #8fd6ec 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.empty-state p { font-size: 15px; }

.suggests {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; margin-top: 24px;
}
.suggest-chip {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px; font-weight: 500;
  cursor: pointer;
  transition: transform 120ms ease-out, background 160ms var(--spring),
              color 160ms var(--spring), border-color 160ms var(--spring);
}
.suggest-chip:hover { background: var(--surface-2); color: var(--text); border-color: rgba(94,200,230,0.4); }
.suggest-chip:active { transform: scale(0.96); }   /* respond on press */

/* ----------------------------- composer --------------------------------- */
.composer-wrap {
  padding: 8px 20px 16px;
  background: linear-gradient(to top, var(--bg) 40%, transparent);
}
.composer {
  max-width: 760px;
  margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 8px 8px 8px 16px;
  transition: border-color 160ms var(--spring), box-shadow 160ms var(--spring);
}
.composer:focus-within {
  border-color: rgba(94,200,230,0.5);
  box-shadow: 0 0 0 3px rgba(94,200,230,0.14);
}
.input {
  flex: 1;
  background: none; border: none; outline: none; resize: none;
  color: var(--text);
  font-size: 15.5px; line-height: 1.5;
  max-height: 200px;
  padding: 8px 0;
}
.input::placeholder { color: var(--text-faint); }

.send-btn {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 120ms var(--spring), background 160ms, opacity 160ms;
}
.send-btn:hover { background: var(--accent-strong); }
.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.45; cursor: default; }

.composer-hint {
  text-align: center; color: var(--text-faint);
  font-size: 11.5px; margin-top: 8px;
}

/* --------------------------- loading dots ------------------------------- */
.loading-dots { display: flex; gap: 5px; padding: 6px 0; }
.loading-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  animation: blink 1.3s infinite ease-in-out both;
}
.loading-dots span:nth-child(2) { animation-delay: 0.18s; }
.loading-dots span:nth-child(3) { animation-delay: 0.36s; }

/* ------------------------------ mobile ---------------------------------- */
.only-mobile { display: none; }
.scrim {
  position: fixed; inset: 0; z-index: 8;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  animation: fade 200ms ease both;
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: grid; }
  .sidebar {
    position: fixed; z-index: 9; top: 0; bottom: 0; left: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 360ms var(--spring);   /* interruptible-feeling slide */
    box-shadow: 24px 0 60px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .messages { padding-left: 14px; padding-right: 14px; }
  .composer-wrap { padding-left: 12px; padding-right: 12px; }
}

/* ------------------------------ motion ---------------------------------- */
.enter { animation: rise 420ms var(--spring) both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}
@keyframes spin { to { transform: rotate(360deg); } }
/* materialize: the surface arrives as a real material (blur + scale together) */
@keyframes materialize {
  from { opacity: 0; transform: scale(0.955); filter: blur(10px); }
  to   { opacity: 1; transform: scale(1);     filter: blur(0); }
}

/* respect reduced motion — gentle cross-fades, no slides/springs */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .enter, .auth-card, .setup-card { animation: fade 200ms ease both; }
  .sidebar { transition: none; }
  .seg-indicator { transition: none; }
  .btn-primary:active, .send-btn:active, .new-chat:active,
  .icon-btn:active, .seg-btn:active { transform: none; }
  .pw-toggle:active { transform: translateY(-50%); }
}

/* frostier surfaces when the user reduces transparency */
@media (prefers-reduced-transparency: reduce) {
  .topbar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .auth-card {
    background: var(--surface);
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .auth-aurora { opacity: 0.5; }
}
