@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,400;8..60,500;8..60,600;8..60,700&display=swap');

/* ============================================================
   theme.css — Claude-inspired design system
   Warm terracotta accent · cream editorial canvas · serif display
   Supports: light / dark / auto (prefers-color-scheme)
   ============================================================ */

/* ── 1. Light theme (default) ────────────────────────────── */
:root {
  /* Background layers — warm cream instead of cold white */
  --bg-primary:    #FAF9F5;
  --bg-secondary:  #F3EFE4;
  --bg-tertiary:   #EAE4D3;
  --bg-elevated:   #FFFFFF;
  --bg-hover:      rgba(60, 45, 30, 0.04);
  --bg-active:     rgba(60, 45, 30, 0.08);

  /* Text — warm ink, not neutral gray */
  --text-primary:    #1F1E1D;
  --text-secondary:  #6B655C;
  --text-tertiary:   #A59E90;
  --text-on-accent:  #FFFFFF;

  /* Accent — Claude signature terracotta */
  --accent:         #CC785C;
  --accent-hover:   #B8674D;
  --accent-active:  #A85A42;
  --accent-bg:      rgba(204, 120, 92, 0.12);

  /* Borders & dividers — warm toned */
  --border:        rgba(60, 45, 30, 0.14);
  --border-light:  rgba(60, 45, 30, 0.07);
  --divider:       rgba(60, 45, 30, 0.09);

  /* Shadows — softer, warmer */
  --shadow-sm:   0 1px 3px rgba(60, 45, 30, 0.07), 0 1px 2px rgba(60, 45, 30, 0.04);
  --shadow-md:   0 4px 14px rgba(60, 45, 30, 0.08), 0 2px 4px rgba(60, 45, 30, 0.04);
  --shadow-lg:   0 10px 28px rgba(60, 45, 30, 0.10), 0 4px 10px rgba(60, 45, 30, 0.05);
  --shadow-card: 0 2px 8px rgba(60, 45, 30, 0.06), 0 1px 2px rgba(60, 45, 30, 0.04);

  /* Radii */
  --radius-sm:  8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Typography — Copernicus-style serif for display, clean sans for body */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "PingFang SC", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Source Serif Pro", "Source Serif 4", "Noto Serif SC",
                "Songti SC", "STSong", Georgia, "Times New Roman", serif;
  --font-mono: "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code",
               Consolas, "Courier New", monospace;

  /* Layout */
  --sidebar-width:  260px;
  --header-height:   52px;

  /* Semantic colors — muted, warm-family */
  --success:  #7A8F5C;
  --warning:  #D4A34A;
  --danger:   #C4584A;

  /* UI-specific */
  --msg-user-bg:    #CC785C;
  --msg-user-text:  #FFFFFF;
  --msg-ai-bg:      #F3EFE4;
  --msg-ai-text:    #1F1E1D;
  --input-bg:       #FFFFFF;
  --input-border:   rgba(60, 45, 30, 0.16);
  --sidebar-bg:     #F3EFE4;
  --sidebar-border: rgba(60, 45, 30, 0.09);
  --modal-backdrop: rgba(31, 30, 29, 0.42);
}

/* ── 2. Dark theme ───────────────────────────────────────── */
[data-theme="dark"] {
  --bg-primary:    #1F1E1D;
  --bg-secondary:  #2A2825;
  --bg-tertiary:   #3A3731;
  --bg-elevated:   #262522;
  --bg-hover:      rgba(255, 245, 230, 0.05);
  --bg-active:     rgba(255, 245, 230, 0.09);

  --text-primary:    #F5F1E8;
  --text-secondary:  #B8AE9E;
  --text-tertiary:   #7A7468;
  --text-on-accent:  #FFFFFF;

  --accent:         #D9896B;
  --accent-hover:   #E59A7D;
  --accent-active:  #C4745A;
  --accent-bg:      rgba(217, 137, 107, 0.18);

  --border:        rgba(255, 245, 230, 0.11);
  --border-light:  rgba(255, 245, 230, 0.06);
  --divider:       rgba(255, 245, 230, 0.08);

  --shadow-sm:   0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.22);
  --shadow-md:   0 4px 14px rgba(0, 0, 0, 0.40), 0 2px 4px rgba(0, 0, 0, 0.22);
  --shadow-lg:   0 10px 28px rgba(0, 0, 0, 0.46), 0 4px 10px rgba(0, 0, 0, 0.28);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.22);

  --msg-user-bg:    #D9896B;
  --msg-user-text:  #1F1E1D;
  --msg-ai-bg:      #2A2825;
  --msg-ai-text:    #F5F1E8;
  --input-bg:       #2A2825;
  --input-border:   rgba(255, 245, 230, 0.14);
  --sidebar-bg:     #1A1917;
  --sidebar-border: rgba(255, 245, 230, 0.08);
  --modal-backdrop: rgba(0, 0, 0, 0.62);
}

/* ── 3. Auto: follow system when no explicit theme set ────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary:    #1F1E1D;
    --bg-secondary:  #2A2825;
    --bg-tertiary:   #3A3731;
    --bg-elevated:   #262522;
    --bg-hover:      rgba(255, 245, 230, 0.05);
    --bg-active:     rgba(255, 245, 230, 0.09);

    --text-primary:    #F5F1E8;
    --text-secondary:  #B8AE9E;
    --text-tertiary:   #7A7468;
    --text-on-accent:  #FFFFFF;

    --accent:         #D9896B;
    --accent-hover:   #E59A7D;
    --accent-active:  #C4745A;
    --accent-bg:      rgba(217, 137, 107, 0.18);

    --border:        rgba(255, 245, 230, 0.11);
    --border-light:  rgba(255, 245, 230, 0.06);
    --divider:       rgba(255, 245, 230, 0.08);

    --shadow-sm:   0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.22);
    --shadow-md:   0 4px 14px rgba(0, 0, 0, 0.40), 0 2px 4px rgba(0, 0, 0, 0.22);
    --shadow-lg:   0 10px 28px rgba(0, 0, 0, 0.46), 0 4px 10px rgba(0, 0, 0, 0.28);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.22);

    --msg-user-bg:    #D9896B;
    --msg-user-text:  #1F1E1D;
    --msg-ai-bg:      #2A2825;
    --msg-ai-text:    #F5F1E8;
    --input-bg:       #2A2825;
    --input-border:   rgba(255, 245, 230, 0.14);
    --sidebar-bg:     #1A1917;
    --sidebar-border: rgba(255, 245, 230, 0.08);
    --modal-backdrop: rgba(0, 0, 0, 0.62);
  }
}

/* ── 4. Reset ─────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── 5. Base ──────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ── 6. Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── 7. Typography classes ────────────────────────────────── */
.text-title {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: var(--text-primary);
}

.text-headline {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.3;
  color: var(--text-primary);
}

.text-body {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-primary);
}

.text-caption {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-secondary);
}

.text-label {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
}

/* ── 8. Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease,
              box-shadow 0.15s ease, transform 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Primary */
.btn-primary {
  background-color: var(--accent);
  color: var(--text-on-accent);
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}
.btn-primary:active:not(:disabled) {
  background-color: var(--accent-active);
}
.btn-primary:focus-visible {
  box-shadow: 0 0 0 4px var(--accent-bg);
}

/* Secondary */
.btn-secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-tertiary);
}
.btn-secondary:active:not(:disabled) {
  background-color: var(--bg-active);
}
.btn-secondary:focus-visible {
  box-shadow: 0 0 0 4px var(--accent-bg);
}

/* Ghost */
.btn-ghost {
  background-color: transparent;
  color: var(--accent);
}
.btn-ghost:hover:not(:disabled) {
  background-color: var(--accent-bg);
}
.btn-ghost:active:not(:disabled) {
  background-color: rgba(204, 120, 92, 0.20);
}
.btn-ghost:focus-visible {
  box-shadow: 0 0 0 4px var(--accent-bg);
}

/* Danger */
.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background-color: #B44E42;
}
.btn-danger:active:not(:disabled) {
  background-color: #9E4337;
}
.btn-danger:focus-visible {
  box-shadow: 0 0 0 4px rgba(196, 88, 74, 0.20);
}

/* Small */
.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

/* ── 9. Inputs ────────────────────────────────────────────── */
.input,
.textarea {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-tertiary);
}

.input:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.input:disabled,
.textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── 10. Cards ────────────────────────────────────────────── */
.card {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 16px;
  transition: background-color 0.2s ease;
}

.card-interactive {
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease,
              transform 0.15s ease;
}
.card-interactive:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.card-interactive:active {
  box-shadow: var(--shadow-sm);
  transform: translateY(0);
}

/* ── 11. Badges ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  border-radius: 100px;
  white-space: nowrap;
}

.badge-blue {
  background-color: var(--accent-bg);
  color: var(--accent);
}

.badge-green {
  background-color: rgba(122, 143, 92, 0.16);
  color: #5C6E43;
}

.badge-orange {
  background-color: rgba(212, 163, 74, 0.18);
  color: #9A7328;
}

.badge-purple {
  background-color: rgba(139, 93, 138, 0.14);
  color: #7A4F7A;
}

.badge-gray {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
}

[data-theme="dark"] .badge-green  { color: #A8BD83; }
[data-theme="dark"] .badge-orange { color: #E8C17A; }
[data-theme="dark"] .badge-purple { color: #C89EC6; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-green  { color: #A8BD83; }
  :root:not([data-theme="light"]) .badge-orange { color: #E8C17A; }
  :root:not([data-theme="light"]) .badge-purple { color: #C89EC6; }
}

/* ── 12. Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background-color: var(--modal-backdrop);
  padding: 16px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

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

.modal {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(8px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

/* ── 13. Markdown rendering ───────────────────────────────── */
.md h1 {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 24px 0 12px;
  color: var(--text-primary);
}

.md h2 {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 20px 0 10px;
  color: var(--text-primary);
}

.md h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text-primary);
}

.md p {
  margin: 0 0 12px;
  line-height: 1.7;
  color: var(--text-primary);
}

.md ul,
.md ol {
  margin: 0 0 12px;
  padding-left: 20px;
}

.md li {
  margin-bottom: 4px;
  line-height: 1.6;
  color: var(--text-primary);
}

.md code {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 2px 6px;
  background-color: var(--bg-tertiary);
  border-radius: 4px;
  color: var(--text-primary);
}

.md pre {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 0 0 14px;
  overflow-x: auto;
}

.md pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  border-radius: 0;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 14px;
  font-size: 14px;
}

.md th,
.md td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--divider);
  color: var(--text-primary);
}

.md th {
  font-weight: 600;
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
}

.md tr:last-child td {
  border-bottom: none;
}

.md blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 16px;
  margin: 0 0 14px;
  color: var(--text-secondary);
  font-style: italic;
}

.md hr {
  border: none;
  border-top: 1px solid var(--divider);
  margin: 20px 0;
}

.md strong {
  font-weight: 600;
  color: var(--text-primary);
}

/* ── 14. Theme toggle widget ──────────────────────────────── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  user-select: none;
  -webkit-user-select: none;
}

.theme-toggle button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 26px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  transition: background-color 0.15s ease, color 0.15s ease;
  outline: none;
}

.theme-toggle button:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.theme-toggle button.active {
  background-color: var(--bg-elevated);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ── 15. Layout helpers ───────────────────────────────────── */
.flex         { display: flex; }
.flex-col     { display: flex; flex-direction: column; }
.flex-1       { flex: 1 1 0%; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.items-end    { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.p-3  { padding: 12px; }
.p-4  { padding: 16px; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.py-3 { padding-top: 12px; padding-bottom: 12px; }

.hidden        { display: none !important; }
.truncate      { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overflow-y-auto { overflow-y: auto; }
.shrink-0      { flex-shrink: 0; }
.w-full        { width: 100%; }

/* ── 16. Animations ───────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

.anim-fade {
  animation: fadeIn 0.25s ease both;
}

.anim-slide {
  animation: slideUp 0.25s ease both;
}

/* ── 17. Print ────────────────────────────────────────────── */
@media print {
  .no-print {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .card,
  .modal {
    box-shadow: none !important;
    border: 1px solid #cccccc !important;
  }
}
