:root {
  --fairway: #1F3B2C;
  --fairway-dark: #16291F;
  --fairway-line: rgba(255, 255, 255, 0.08);
  --gold: #C9A55C;
  --gold-soft: #E4CD98;
  --paper: #FAF8F4;
  --paper-raised: #FFFFFF;
  --ink: #1C2321;
  --ink-soft: #5B6B63;
  --line: #E4DFD3;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--gold);
  color: var(--fairway-dark);
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: 18px;
  letter-spacing: 0.01em;
  color: var(--paper);
}

.brand-name em {
  font-style: normal;
  color: var(--gold-soft);
}

/* ---------- Layout principal ---------- */

.app {
  display: flex;
  height: 100vh;
  width: 100%;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(201,165,92,0.10), transparent 55%),
    var(--fairway);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='280' height='140' viewBox='0 0 280 140'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='0.05' stroke-width='1'%3E%3Cpath d='M-20 30 C 60 10, 140 60, 220 20 S 340 30, 400 10'/%3E%3Cpath d='M-20 60 C 60 40, 140 90, 220 50 S 340 60, 400 40'/%3E%3Cpath d='M-20 90 C 60 70, 140 120, 220 80 S 340 90, 400 70'/%3E%3Cpath d='M-20 120 C 60 100, 140 150, 220 110 S 340 120, 400 100'/%3E%3C/g%3E%3C/svg%3E"),
    var(--fairway);
  background-repeat: no-repeat, no-repeat;
  background-position: top, top;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.new-chat {
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.05);
  color: var(--paper);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.new-chat:hover {
  background: rgba(255,255,255,0.10);
  border-color: rgba(255,255,255,0.3);
}

.history-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.45);
  padding: 0 4px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: -4px;
  padding: 4px;
}

.history-empty {
  color: rgba(255,255,255,0.35);
  font-size: 13px;
  padding: 8px 4px;
}

.history-item {
  padding: 9px 10px;
  border-radius: 8px;
  color: rgba(255,255,255,0.78);
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
}

.history-item:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
}

.history-item .h-date {
  display: block;
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  margin-top: 2px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--fairway-line);
  padding-top: 14px;
}

.user-pill {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
}

.logout-link {
  font-size: 13px;
  color: var(--gold-soft);
  text-decoration: none;
}

.logout-link:hover {
  text-decoration: underline;
}

/* ---------- Panel principal ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  max-width: 480px;
  margin: 10vh auto 0;
  text-align: center;
}

.empty-state h1 {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: 30px;
  margin: 0 0 10px;
  color: var(--ink);
}

.empty-state p {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
}

.msg-row {
  display: flex;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.msg-row.user {
  justify-content: flex-end;
}

.msg-row.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.msg-row.user .bubble {
  background: var(--fairway);
  color: var(--paper);
  border-bottom-right-radius: 4px;
}

.msg-row.assistant .bubble {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.bubble .sources {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.bubble.thinking {
  color: var(--ink-soft);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bubble.error {
  background: #FBEAEA;
  border-color: #EBC6C6;
  color: #7A2E2E;
}

.dot-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  animation: pulse 1s infinite ease-in-out;
}

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

/* ---------- Composer ---------- */

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 720px;
  width: calc(100% - 48px);
  margin: 0 auto 24px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 10px 10px 16px;
  box-shadow: 0 2px 10px rgba(28, 35, 33, 0.04);
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Inter', sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  max-height: 160px;
  padding: 6px 0;
  background: transparent;
  color: var(--ink);
}

.composer button {
  background: var(--fairway);
  color: var(--paper);
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.composer button:hover {
  background: var(--fairway-dark);
}

.composer button:disabled {
  background: var(--ink-soft);
  cursor: not-allowed;
}

/* ---------- Login ---------- */

.login-body {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 30% 20%, rgba(201,165,92,0.12), transparent 55%),
    var(--fairway);
}

.login-card {
  background: var(--paper-raised);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.brand-center {
  justify-content: center;
  margin-bottom: 4px;
}

.login-body .brand-name {
  color: var(--ink);
}

.login-body .brand-name em {
  color: #A9812E;
}

.login-sub {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  margin: 6px 0 24px;
}

.login-error {
  background: #FBEAEA;
  border: 1px solid #EBC6C6;
  color: #7A2E2E;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  text-align: center;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-form label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 10px;
}

.login-form input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  outline: none;
}

.login-form input:focus {
  border-color: var(--gold);
}

.login-form button {
  margin-top: 20px;
  background: var(--fairway);
  color: var(--paper);
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.login-form button:hover {
  background: var(--fairway-dark);
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .sidebar {
    display: none;
  }
  .composer {
    width: calc(100% - 24px);
  }
}
