/* ================================================================
   PepDoc — Base structural CSS
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; height: 100%; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.7;
  height: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--color-text);
  line-height: 1.25;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; font-family: inherit; }

/* ── Layout shell ──────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
}
.sidebar__logo-icon {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.9rem;
}
.sidebar__logo-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
}

.sidebar__actions {
  padding: 10px 10px 4px;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn-new-chat:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.btn-new-chat svg { flex-shrink: 0; }

.sidebar__section-label {
  padding: 10px 16px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.sidebar__conversations {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s;
  gap: 4px;
}
.conv-item:hover { background: var(--color-border); }
.conv-item.active { background: var(--color-primary-light); }

.conv-item__title {
  flex: 1;
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text);
}
.conv-item.active .conv-item__title { color: var(--color-primary); font-weight: 500; }

.conv-item__actions {
  display: none;
  gap: 2px;
}
.conv-item:hover .conv-item__actions { display: flex; }

.conv-action-btn {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.conv-action-btn:hover { background: var(--color-border); color: var(--color-text); }
.conv-action-btn.delete:hover { background: #fee2e2; color: #dc2626; }

/* ── Main area ─────────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Chat header ───────────────────────────────────────────────── */
.chat-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  flex-shrink: 0;
  background: var(--color-bg);
}
.chat-header__title {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.chat-header__share-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: none;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  transition: all 0.15s;
}
.chat-header__share-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

/* ── Message list ──────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  scroll-behavior: smooth;
}

/* ── Welcome screen ────────────────────────────────────────────── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 24px;
  gap: 20px;
}
.welcome__logo {
  width: 56px;
  height: 56px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.3rem;
}
.welcome h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
}
.welcome p {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  max-width: 400px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 480px;
}
.suggestion-btn {
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  font-size: 0.875rem;
  color: var(--color-text);
  transition: all 0.15s;
  white-space: nowrap;
}
.suggestion-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

/* ── Message items ─────────────────────────────────────────────── */
.msg-row {
  padding: 6px 16px;
}
.msg-row--inner {
  max-width: 720px;
  margin: 0 auto;
}

/* User messages */
.msg-row--user .msg-row--inner {
  display: flex;
  justify-content: flex-end;
}
.msg-bubble--user {
  max-width: 72%;
  background: var(--color-user-bubble);
  color: var(--color-user-bubble-fg);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl);
  padding: 12px 18px;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Assistant messages */
.msg-row--assistant .msg-row--inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.msg-avatar {
  width: 30px;
  height: 30px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.75rem;
  margin-top: 2px;
}
.msg-content {
  flex: 1;
  min-width: 0;
}
.msg-content__text {
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--color-text);
}

/* Prose inside assistant messages */
.msg-content__text p { margin-bottom: 0.9rem; }
.msg-content__text p:last-child { margin-bottom: 0; }
.msg-content__text h2, .msg-content__text h3 {
  margin-top: 1.4rem;
  margin-bottom: 0.5rem;
  font-family: var(--font-heading);
}
.msg-content__text ul, .msg-content__text ol {
  margin-left: 1.4rem;
  margin-bottom: 0.9rem;
}
.msg-content__text li { margin-bottom: 0.25rem; }
.msg-content__text strong { color: var(--color-text); }
.msg-content__text a { color: var(--color-primary); }
.msg-content__text code {
  background: var(--color-surface);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.875em;
  font-family: var(--font-mono);
}
.msg-content__text pre {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 0.9rem;
}
.msg-content__text pre code { background: none; padding: 0; }
.msg-content__text table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.msg-content__text th {
  background: var(--color-surface);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  text-align: left;
}
.msg-content__text td {
  padding: 7px 12px;
  border: 1px solid var(--color-border);
  vertical-align: top;
}
.msg-content__text tr:nth-child(even) td { background: var(--color-surface); }
.msg-content__text img {
  max-width: 180px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  margin: 4px 0;
}
.msg-content__text blockquote {
  border-left: 3px solid var(--color-primary);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--color-text-muted);
}

/* Message actions */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-row--assistant:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
  font-size: 0.8rem;
}
.msg-action-btn:hover { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text); }
.msg-action-btn.active { color: var(--color-primary); }

/* Streaming cursor */
.cursor-blink {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--color-primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.9s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Input area ────────────────────────────────────────────────── */
.input-area {
  padding: 12px 16px 20px;
  flex-shrink: 0;
}
.input-wrap {
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}
.chat-form {
  display: flex;
  flex-direction: column;
}
.input-box {
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 4px 4px 4px 18px;
  box-shadow: 0 1px 4px var(--color-shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-box:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(46,147,111,0.12);
}

#chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--color-text);
  resize: none;
  min-height: 44px;
  max-height: 200px;
  line-height: 1.5;
  padding: 10px 0;
  overflow-y: auto;
}
#chat-input::placeholder { color: var(--color-text-muted); opacity: 0.6; }

.send-btn, .stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
  transition: all 0.15s;
}
.send-btn {
  background: var(--color-primary);
  color: #fff;
}
.send-btn:hover { background: var(--color-primary-dark); }
.send-btn:disabled { background: var(--color-border); cursor: not-allowed; }
.stop-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}
.stop-btn:hover { background: var(--color-border); }

/* ── Share modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36,34,32,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.modal h3 { font-size: 1rem; font-weight: 700; margin-bottom: 6px; }
.modal p { font-size: 0.875rem; color: var(--color-text-muted); margin-bottom: 16px; }
.share-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.share-url-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
}
.btn-copy {
  padding: 8px 14px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-copy:hover { background: var(--color-primary-dark); }
.btn-copy.copied { background: #059669; }
.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  float: right;
  margin-top: -4px;
}
.modal-close:hover { background: var(--color-surface); }

/* ── Share page ────────────────────────────────────────────────── */
.share-page {
  min-height: 100vh;
  background: var(--color-bg);
}
.share-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface-2);
}
.share-header__logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.share-header__badge {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-lg);
}
.share-body { max-width: 760px; margin: 0 auto; padding: 32px 24px; }
.share-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 24px; }
.share-cta {
  margin-top: 40px;
  padding: 20px;
  background: var(--color-primary-light);
  border-radius: var(--radius-lg);
  text-align: center;
}
.share-cta p { margin-bottom: 12px; font-size: 0.95rem; color: var(--color-primary-dark); }
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--color-primary-dark); text-decoration: none; }

/* ── Rename dialog ─────────────────────────────────────────────── */
.rename-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--color-text);
  outline: none;
  margin-bottom: 12px;
}
.rename-input:focus { border-color: var(--color-primary); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn-secondary {
  padding: 7px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: none;
  font-size: 0.84rem;
  color: var(--color-text-muted);
}
.btn-secondary:hover { background: var(--color-surface); }

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 99px; }

/* ── Mobile ────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 49;
  }
  .sidebar-overlay.open { display: block; }
  .mobile-menu-btn { display: flex; }
}

@media (min-width: 701px) {
  .mobile-menu-btn { display: none; }
}

.mobile-menu-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  align-items: center;
  justify-content: center;
}
.mobile-menu-btn:hover { background: var(--color-surface); }
