/* ============================================================
   CIPHER — styles (light + dark themes via [data-theme])
   ============================================================ */
:root {
  --navy-950: #081420;
  --navy-900: #0B1B2B;
  --navy-800: #12293F;
  --teal: #0E9488;
  --teal-deep: #0B7C72;
  --radius: 14px;
  --col: 780px;

  /* Light theme tokens */
  --paper: #F6F8FA;
  --surface: #FFFFFF;
  --ink: #1C2B3A;
  --heading: #0B1B2B;
  --muted: #5C6B7A;
  --faint: #8A97A5;
  --line: #E3E9EF;
  --teal-soft: #E3F3F1;
  --bubble-user-bg: #0B1B2B;
  --bubble-user-ink: #EDF2F6;
  --code-bg: #081420;
  --code-ink: #D8E4EE;
  --shadow: 0 1px 2px rgba(11, 27, 43, 0.04);
  --composer-shadow: 0 4px 18px rgba(11, 27, 43, 0.07);
  --send-bg: #0B1B2B;
  --send-disabled: #C4CFD9;
  --error-bg: #FDF6F4;
  --error-ink: #7A3B2E;
  --error-line: #C0533E;
}

[data-theme="dark"] {
  --paper: #0B141F;
  --surface: #13202E;
  --ink: #DCE6EF;
  --heading: #EDF3F8;
  --muted: #93A5B5;
  --faint: #5F7183;
  --line: #223140;
  --teal-soft: rgba(14, 148, 136, 0.16);
  --bubble-user-bg: #1B3A57;
  --bubble-user-ink: #E8F0F7;
  --code-bg: #060D15;
  --code-ink: #C9D8E4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  --composer-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --send-bg: #0E9488;
  --send-disabled: #2B3B4B;
  --error-bg: #2A1815;
  --error-ink: #E8A493;
  --error-line: #C0533E;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.6;
  transition: background 0.2s ease, color 0.2s ease;
}

/* ---------- Header (navy in both themes) ---------- */
header {
  background: var(--navy-900);
  border-bottom: 1px solid var(--navy-800);
  position: sticky; top: 0; z-index: 20;
}
.header-inner {
  max-width: var(--col); margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; gap: 12px;
}
.monogram {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--teal), var(--teal-deep));
  color: #fff; display: grid; place-items: center;
  font-family: 'Newsreader', serif; font-weight: 600; font-size: 19px;
  flex: none;
}
.wordmark {
  font-family: 'Newsreader', serif; font-size: 21px; font-weight: 500;
  color: #F2F6F9; letter-spacing: 0.04em;
}
.tagline { font-size: 11.5px; color: #8FA3B5; margin-top: 1px; }
.header-spacer { flex: 1; }
.status {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: #9DB2C4;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px rgba(14, 148, 136, 0.22);
}
.btn-icon {
  margin-left: 14px; width: 32px; height: 32px; flex: none;
  color: #C9D6E1; background: transparent;
  border: 1px solid #2A3F55; border-radius: 8px;
  cursor: pointer; display: grid; place-items: center;
  transition: all 0.15s ease;
}
.btn-icon:hover { border-color: var(--teal); color: #fff; }
.btn-newchat {
  margin-left: 10px; font: 500 12.5px 'Inter', sans-serif;
  color: #C9D6E1; background: transparent;
  border: 1px solid #2A3F55; border-radius: 8px;
  padding: 7px 13px; cursor: pointer; transition: all 0.15s ease;
}
.btn-newchat:hover { border-color: var(--teal); color: #fff; }

/* ---------- Chat area ---------- */
main { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: var(--col); margin: 0 auto; padding: 28px 20px 40px; }

/* Welcome */
.welcome { padding: 9vh 4px 20px; }
.welcome h1 {
  font-family: 'Newsreader', serif; font-weight: 500;
  font-size: clamp(30px, 5vw, 42px); line-height: 1.15;
  color: var(--heading);
}
.welcome h1 em { font-style: italic; color: var(--teal); }
.welcome p { margin-top: 12px; color: var(--muted); max-width: 58ch; }
.welcome p strong { color: var(--teal); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.chip {
  font: 400 13.5px 'Inter', sans-serif; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 16px; cursor: pointer;
  transition: all 0.15s ease; text-align: left;
}
.chip:hover { border-color: var(--teal); background: var(--teal-soft); }

/* Messages */
.msg { display: flex; gap: 12px; margin-bottom: 26px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--bubble-user-bg); color: var(--bubble-user-ink);
  border-radius: var(--radius); border-bottom-right-radius: 4px;
  padding: 12px 17px; max-width: 78%;
  white-space: pre-wrap; overflow-wrap: break-word;
}
.avatar {
  width: 30px; height: 30px; border-radius: 9px; flex: none; margin-top: 2px;
  background: linear-gradient(135deg, var(--teal), var(--teal-deep));
  color: #fff; display: grid; place-items: center;
  font-family: 'Newsreader', serif; font-weight: 600; font-size: 16px;
}
.msg.bot .bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: var(--radius); border-top-left-radius: 4px;
  padding: 14px 19px; max-width: 86%;
  box-shadow: var(--shadow);
  overflow-wrap: break-word;
}
.bubble.error {
  border-left-color: var(--error-line); background: var(--error-bg); color: var(--error-ink);
}

/* Markdown inside bot bubbles */
.bubble h1, .bubble h2, .bubble h3 {
  font-family: 'Newsreader', serif; font-weight: 600;
  margin: 14px 0 6px; line-height: 1.3; color: var(--heading);
}
.bubble h1 { font-size: 20px; } .bubble h2 { font-size: 18px; } .bubble h3 { font-size: 16px; }
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child, .bubble p:first-child { margin-top: 0; }
.bubble p { margin: 8px 0; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble strong { font-weight: 600; color: var(--heading); }
.bubble code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px;
  background: var(--teal-soft); color: var(--teal);
  padding: 2px 6px; border-radius: 5px;
}
.bubble pre {
  background: var(--code-bg); color: var(--code-ink); border-radius: 10px;
  padding: 14px 16px; overflow-x: auto; margin: 10px 0; font-size: 13px;
}
.bubble pre code { background: none; color: inherit; padding: 0; }
.bubble blockquote {
  border-left: 3px solid var(--line); padding: 2px 0 2px 14px;
  color: var(--muted); margin: 10px 0; font-style: italic;
}
.bubble table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 13.5px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; }
.bubble th { background: var(--paper); font-weight: 600; }
.bubble a { color: var(--teal); }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* Thinking indicator */
.thinking { display: flex; align-items: center; gap: 10px; }
.dots { display: flex; gap: 4px; }
.dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--teal);
  animation: pulse 1.2s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: 0.18s; }
.dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-3px); }
}
.thinking-label { font-size: 13px; color: var(--muted); font-style: italic; }
@media (prefers-reduced-motion: reduce) {
  .dots span { animation: none; opacity: 0.7; }
  main { scroll-behavior: auto; }
}

/* ---------- Composer ---------- */
.composer-wrap {
  position: sticky; bottom: 0;
  background: linear-gradient(to top, var(--paper) 65%, transparent);
  padding: 8px 0 18px;
}
.composer { max-width: var(--col); margin: 0 auto; padding: 0 20px; }
.input-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--composer-shadow);
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px 10px 12px;
  transition: border-color 0.15s ease;
}
.input-card:focus-within { border-color: var(--teal); }
.btn-attach {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); cursor: pointer; display: grid; place-items: center;
  transition: all 0.15s ease;
}
.btn-attach:hover { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
textarea {
  flex: 1; border: none; outline: none; resize: none;
  font: 400 15px/1.5 'Inter', sans-serif; color: var(--ink);
  background: transparent; max-height: 160px; padding: 8px 0 4px;
}
textarea::placeholder { color: var(--faint); }
.btn-send {
  width: 38px; height: 38px; border-radius: 12px; border: none; flex: none;
  background: var(--send-bg); color: #fff; cursor: pointer;
  display: grid; place-items: center; transition: background 0.15s ease;
}
.btn-send:hover:not(:disabled) { background: var(--teal-deep); }
.btn-send:disabled { background: var(--send-disabled); cursor: not-allowed; }
.composer-note {
  text-align: center; font-size: 11.5px; color: var(--faint); margin-top: 9px;
}

@media (max-width: 560px) {
  .tagline, .status { display: none; }
  .msg.bot .bubble { max-width: 100%; }
  .msg.user .bubble { max-width: 88%; }
  .welcome { padding-top: 5vh; }
}

/* ============================================================
   v2 — Sidebar / chat history layout
   ============================================================ */
body { flex-direction: row; }
.app { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; }

#sidebar {
  width: 264px; flex: none; height: 100vh;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: margin-left 0.22s ease;
}
#sidebar.hidden { margin-left: -264px; }

.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 12px;
}
.sidebar-title .wordmark {
  color: var(--heading); font-size: 18px;
}
.sidebar-sub { font-size: 11px; color: var(--faint); }

.btn-primary {
  margin: 4px 14px 10px; padding: 9px 12px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  font: 500 13px 'Inter', sans-serif; color: #fff;
  background: var(--teal-deep); border: none; border-radius: 10px;
  cursor: pointer; transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--teal); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.chat-item {
  display: flex; align-items: center; gap: 6px;
  width: 100%; text-align: left;
  padding: 9px 10px; margin-bottom: 2px;
  font: 400 13px/1.35 'Inter', sans-serif; color: var(--ink);
  background: transparent; border: none; border-radius: 9px;
  cursor: pointer; transition: background 0.12s ease;
}
.chat-item:hover { background: var(--teal-soft); }
.chat-item.active { background: var(--teal-soft); font-weight: 500; }
.chat-item .chat-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item .chat-del {
  flex: none; width: 20px; height: 20px; border: none; border-radius: 6px;
  background: transparent; color: var(--faint); cursor: pointer;
  display: none; place-items: center; font-size: 14px; line-height: 1;
}
.chat-item:hover .chat-del { display: grid; }
.chat-item .chat-del:hover { color: var(--error-line); background: var(--paper); }
.chat-empty { padding: 14px 12px; font-size: 12.5px; color: var(--faint); }

.sidebar-foot {
  padding: 12px 16px; font-size: 11px; color: var(--faint);
  border-top: 1px solid var(--line);
}

.header-brand .wordmark { font-size: 19px; }
header .btn-icon:first-child { margin-left: 0; }

.scrim {
  display: none; position: fixed; inset: 0; z-index: 25;
  background: rgba(8, 20, 32, 0.5);
}

@media (max-width: 900px) {
  #sidebar {
    position: fixed; left: 0; top: 0; z-index: 30;
    margin-left: 0; transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.hidden { margin-left: 0; }
  .scrim.show { display: block; }
}
