/* ═══════════════════════════════════════
   Ell — Warm Atelier
   Light, warm, modern chat interface
   ═══════════════════════════════════════ */

:root {
  --bg-page: #faf8f5;
  --bg-surface: #ffffff;
  --bg-sidebar: #f5f0eb;
  --bg-elevated: #f0ebe4;
  --bg-hover: #ece5dc;
  --bg-code: #faf6f1;
  --border: #e5ded4;
  --border-subtle: #ede8e1;
  --border-focus: #c9a882;
  --text-primary: #2c2520;
  --text-secondary: #7a6e62;
  --text-muted: #a99e92;
  --accent: #c0673b;
  --accent-hover: #a8562e;
  --accent-soft: rgba(192, 103, 59, 0.08);
  --accent-warm: #e8a97a;
  --user-bg: #c0673b;
  --user-text: #ffffff;
  --assistant-bg: transparent;
  --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(44, 37, 32, 0.04);
  --shadow-md: 0 4px 16px rgba(44, 37, 32, 0.06);
  --shadow-lg: 0 12px 40px rgba(44, 37, 32, 0.1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.65;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ── */

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

.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 800px;
}

/* ── Header ── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-hamburger,
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
}

.btn-hamburger:hover,
.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.logo {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 400;
  font-style: italic;
  font-optical-sizing: auto;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  user-select: none;
  line-height: 1;
}

.logo-dot {
  color: var(--accent);
}

.btn-new {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
}

.btn-new:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

.btn-new:active {
  transform: scale(0.97);
}

/* ── Sidebar ── */

.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 20px 12px;
  flex-shrink: 0;
}

.sidebar-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  font-style: italic;
  color: var(--text-secondary);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-list::-webkit-scrollbar {
  width: 4px;
}

.sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.sidebar-item {
  display: block;
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 3px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s var(--ease-out);
  font-family: var(--font-body);
}

.sidebar-item:hover {
  background: var(--bg-hover);
}

.sidebar-item.active {
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.sidebar-item-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  line-height: 1.4;
}

.sidebar-item.active .sidebar-item-title {
  color: var(--accent);
}

.sidebar-item-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}

.sidebar-item-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.sidebar-item-text {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.sidebar-item-menu-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar-item-menu-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-item-actions {
  display: none;
  padding-top: 6px;
}

.sidebar-item-actions.visible {
  display: flex;
  gap: 6px;
}

.sidebar-action {
  flex: 1;
  padding: 5px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar-action:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.sidebar-action--danger:hover {
  background: #fdf0ee;
  color: #c0392b;
  border-color: #e8c9c5;
}

.sidebar-rename-input {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border-focus);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sidebar-empty {
  padding: 32px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(44, 37, 32, 0.2);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 19;
}

/* ── Modal ── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(44, 37, 32, 0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s var(--ease-out);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  font-style: italic;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 0 24px 16px;
  flex: 1;
  overflow-y: auto;
}

.soul-editor {
  width: 100%;
  min-height: 200px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.soul-editor:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.soul-editor::placeholder {
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 8px 24px 20px;
}

.btn-modal {
  padding: 9px 22px;
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  border: 1px solid var(--border);
}

.btn-modal--cancel {
  background: transparent;
  color: var(--text-secondary);
}

.btn-modal--cancel:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.btn-modal--save {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-modal--save:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ── Messages Area ── */

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px 28px 16px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages::-webkit-scrollbar {
  width: 5px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Welcome Screen ── */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
  gap: 16px;
  animation: fadeIn 0.8s var(--ease-out);
}

.welcome-mark {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  background: linear-gradient(145deg, var(--accent-soft), rgba(232, 169, 122, 0.12));
  position: relative;
}

.welcome-letter {
  font-family: var(--font-display);
  font-size: 40px;
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
  line-height: 1;
}

.welcome-text {
  text-align: center;
  font-family: var(--font-display);
  font-size: 24px;
  font-style: italic;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.4;
}

.welcome-sub {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 14px;
  font-style: normal;
}

/* ── Message Bubbles ── */

.message {
  margin-bottom: 8px;
  animation: messageIn 0.3s var(--ease-out) both;
  display: flex;
  flex-direction: column;
}

.message-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 5px;
  padding: 0 4px;
}

.message--user .message-label {
  color: var(--accent);
  text-align: right;
}

.message--assistant .message-label {
  color: var(--text-muted);
}

.message-content {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message--user .message-content {
  background: var(--user-bg);
  color: var(--user-text);
  margin-left: 56px;
  border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
}

.message--assistant .message-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  margin-right: 56px;
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
}

/* ── Markdown in messages ── */

.message-content p {
  margin-bottom: 0.7em;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content strong {
  font-weight: 600;
  color: inherit;
}

.message-content em {
  font-style: italic;
}

.message--assistant .message-content em {
  color: var(--text-secondary);
}

.message-content code {
  font-family: 'DM Mono', 'SF Mono', monospace;
  font-size: 13px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--accent);
}

.message--user .message-content code {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.2);
  color: #fff;
}

.message-content pre {
  margin: 12px 0;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  position: relative;
}

.message--user .message-content pre {
  background: rgba(0,0,0,0.12);
  border-color: rgba(255,255,255,0.1);
}

.message-content pre code {
  display: block;
  padding: 14px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
}

.message--user .message-content pre code {
  color: rgba(255,255,255,0.9);
}

.message-content pre .code-lang {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 10px;
  font-family: var(--font-body);
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
}

.message-content ul,
.message-content ol {
  padding-left: 1.4em;
  margin-bottom: 0.7em;
}

.message-content li {
  margin-bottom: 0.25em;
}

.message-content blockquote {
  border-left: 3px solid var(--accent-warm);
  padding-left: 16px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message-content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(192, 103, 59, 0.3);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}

.message-content a:hover {
  text-decoration-color: var(--accent);
}

.message--user .message-content a {
  color: #fff;
  text-decoration-color: rgba(255,255,255,0.4);
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ── Typing Indicator ── */

.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  margin-bottom: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
  margin-right: 56px;
  width: fit-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingPulse 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* ── Input Area ── */

.input-area {
  padding: 12px 28px 18px;
  flex-shrink: 0;
  position: relative;
  background: var(--bg-page);
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px 10px 20px;
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
}

.input-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

.input-field {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  max-height: 160px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.input-field::placeholder {
  color: var(--text-muted);
}

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  flex-shrink: 0;
}

.btn-send:disabled {
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-send:not(:disabled):hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.btn-send:not(:disabled):active {
  transform: scale(0.95);
}

.input-footer {
  display: flex;
  justify-content: center;
  padding-top: 8px;
}

.input-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Streaming cursor ── */

.cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 0.8s step-end infinite;
  border-radius: 1px;
}

/* ── Animations ── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes typingPulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.3); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Responsive ── */

/* Desktop: sidebar always visible */
@media (min-width: 769px) {
  .btn-hamburger { display: none; }
  .sidebar { display: flex; }
}

/* Mobile: sidebar is overlay */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease-out);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }

  .chat-area {
    max-width: none;
  }
}

@media (max-width: 600px) {
  .header { padding: 12px 16px; }
  .messages { padding: 16px 16px 12px; }
  .input-area { padding: 10px 16px 14px; }

  .logo { font-size: 26px; }

  .btn-new-label { display: none; }
  .btn-new { padding: 8px 10px; }

  .message--user .message-content { margin-left: 32px; }
  .message--assistant .message-content { margin-right: 32px; }

  .input-hint { display: none; }
}

/* ── Admin page styles ── */

.admin-app {
  min-height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.admin-header .logo {
  font-size: 24px;
}

.admin-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  margin-left: 16px;
  transition: color 0.2s;
}

.admin-nav a:hover,
.admin-nav a.active {
  color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
}

.stat-value {
  font-size: 28px;
  font-weight: 300;
  color: var(--accent);
  font-family: var(--font-display);
  font-style: italic;
  line-height: 1.2;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.conversation-list {
  list-style: none;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
}

.conversation-item:hover {
  background: var(--bg-elevated);
  border-color: var(--border);
}

.conversation-title {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.conversation-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}

.conversation-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.conversation-messages {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-sidebar);
  padding: 4px 8px;
  border-radius: 4px;
}

.detail-panel {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-top: 24px;
  padding: 24px;
  display: none;
}

.detail-panel.visible {
  display: block;
  animation: fadeIn 0.3s var(--ease-out);
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.detail-title {
  font-size: 16px;
  color: var(--text-primary);
}

.detail-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
}

.detail-close:hover {
  color: var(--text-primary);
}

.detail-messages .message {
  animation: none;
}
