@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  --font-display: "Outfit", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  --transition-fast: 150ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-base: 260ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] {
  --brand-primary: #282623;
  --brand-deep: #1a1a18;
  --brand-accent: #5c5a55;
  --brand-soft: #f3f2ef;
  --brand-glow: rgba(40, 38, 35, 0.15);

  --bg-primary: #ffffff;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f5f5;
  --bg-elevated: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.85);

  --text-primary: #1a1a18;
  --text-secondary: #4a4844;
  --text-tertiary: #6e6c68;
  --text-inverse: #fafaf8;

  --border-default: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.14);
  --border-focus: var(--brand-accent);

  --chat-bubble-mine: rgba(40, 38, 35, 0.06);
  --chat-bubble-theirs: #ffffff;
  --chat-bubble-theirs-border: rgba(0, 0, 0, 0.08);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --brand-primary: #dbd7d0;
  --brand-deep: #c4bfb6;
  --brand-accent: #a89f93;
  --brand-soft: #f0ede8;
  --brand-glow: rgba(219, 215, 208, 0.2);

  --bg-primary: #000000;
  --bg-secondary: #0a0a09;
  --bg-tertiary: #141311;
  --bg-elevated: #0a0a09;
  --bg-glass: rgba(20, 20, 20, 0.75);

  --text-primary: #f0ede8;
  --text-secondary: #bdb9b2;
  --text-tertiary: #76736d;
  --text-inverse: #020202;

  --border-default: rgba(219, 215, 208, 0.08);
  --border-hover: rgba(219, 215, 208, 0.14);
  --border-focus: var(--brand-primary);

  --chat-bubble-mine: rgba(219, 215, 208, 0.12);
  --chat-bubble-theirs: #0a0a09;
  --chat-bubble-theirs-border: rgba(219, 215, 208, 0.08);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  overflow: hidden;
  transition: background-color var(--transition-base), color var(--transition-base);
}

h1, h2, h3, h4, .brand-font {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: var(--radius-full);
}

.twigs-layout-sidebar {
  width: 310px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left var(--transition-base);
  z-index: 20;
}

.twigs-layout-sidebar.is-collapsed {
  margin-left: -310px;
}

.twigs-sidebar-header {
  height: 64px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-titles h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.brand-titles span {
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

.twigs-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.twigs-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  display: block;
}

.twigs-card {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 14px;
  transition: border-color var(--transition-fast);
}

.twigs-expandable summary::-webkit-details-marker {
  display: none;
}

.twigs-expandable-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.twigs-expandable[open] .chevron-icon {
  transform: rotate(180deg);
}

.chevron-icon {
  transition: transform var(--transition-fast);
  color: var(--text-tertiary);
}

.twigs-card:hover {
  border-color: var(--border-hover);
}

.twigs-custom-dropdown {
  position: relative;
  width: 100%;
}

.twigs-dropdown-trigger {
  width: 100%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
  user-select: none;
}

.twigs-dropdown-trigger:hover {
  border-color: var(--border-hover);
}

.twigs-dropdown-trigger:focus-visible,
.twigs-dropdown-trigger.is-open {
  border-color: var(--border-focus);
}

.twigs-dropdown-trigger .dropdown-chevron {
  color: var(--text-tertiary);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.twigs-dropdown-trigger.is-open .dropdown-chevron {
  transform: rotate(180deg);
}

.twigs-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
  display: none;
  max-height: 260px;
  overflow-y: auto;
  backdrop-filter: blur(8px);
}

.twigs-dropdown-menu.is-open {
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: dropdownFadeIn 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.twigs-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  user-select: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.twigs-dropdown-item:hover {
  background-color: var(--border-default);
  color: var(--text-primary);
}

.twigs-dropdown-item.is-selected {
  background-color: var(--chat-bubble-mine);
  color: var(--brand-primary);
  font-weight: 500;
}

.twigs-dropdown-item-check {
  width: 14px;
  height: 14px;
  color: var(--brand-primary);
  opacity: 0;
  flex-shrink: 0;
}

.twigs-dropdown-item.is-selected .twigs-dropdown-item-check {
  opacity: 1;
}

.twigs-select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.twigs-select:focus {
  border-color: var(--border-focus);
}

.twigs-dropzone {
  border: 1px dashed var(--border-hover);
  border-radius: var(--radius-lg);
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  background-color: var(--bg-tertiary);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.twigs-dropzone:hover {
  border-color: var(--brand-accent);
  background-color: var(--bg-secondary);
}

.twigs-dropzone p {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  margin-top: 6px;
}

.twigs-dropzone small {
  font-size: 10.5px;
  color: var(--text-tertiary);
}

.twigs-doc-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
  width: fit-content;
}

.doc-name-text {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 8px 0;
  word-break: break-all;
}

.meta-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.twigs-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
}

.twigs-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  outline: none;
  letter-spacing: -0.01em;
  transition: opacity var(--transition-base), transform var(--transition-base), background-color var(--transition-base), box-shadow var(--transition-base);
  white-space: nowrap;
}

.twigs-btn:active:not(:disabled) {
  opacity: 0.85;
}

.twigs-btn--sm {
  padding: 0.4rem 0.875rem;
  font-size: 0.8125rem;
}

.twigs-btn--md {
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
}

.twigs-btn--full {
  width: 100%;
}

.twigs-btn--primary {
  background: var(--brand-primary);
  color: var(--text-inverse);
}

.twigs-btn--primary:hover:not(:disabled) {
  background: var(--brand-deep);
  transform: translateY(-1px);
}

.twigs-btn--secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
}

.twigs-btn--secondary:hover:not(:disabled) {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.twigs-btn--danger {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #ef4444;
}

.twigs-btn--danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.08);
}

.slider-line {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.slider-line span:last-child {
  font-family: var(--font-mono);
  color: var(--brand-primary);
}

.twigs-range {
  width: 100%;
  accent-color: var(--brand-primary);
  height: 4px;
  background: var(--border-default);
  border-radius: var(--radius-full);
  cursor: pointer;
}

.twigs-sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.twigs-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg-primary);
  position: relative;
}

.twigs-topbar {
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-default);
  background-color: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.icon-trigger {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-trigger:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.doc-topbar-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
}

.chat-inner-wrap {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  flex: 1;
}

.twigs-empty-state {
  margin: auto 0;
  text-align: center;
  padding: 40px 20px;
  max-width: 580px;
  margin-left: auto;
  margin-right: auto;
}

.empty-state-badge {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-xl);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px auto;
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.twigs-empty-state h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.twigs-empty-state p {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 24px;
}

.twigs-prompt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.twigs-prompt-chip {
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-default);
  cursor: pointer;
  transition: all var(--transition-base);
}

.twigs-prompt-chip:hover {
  border-color: var(--border-hover);
  background-color: var(--bg-tertiary);
  transform: translateY(-1px);
}

.twigs-prompt-chip strong {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
}

.twigs-prompt-chip span {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 3px;
  display: block;
}

.chat-msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  gap: 0.2rem;
}

.chat-msg-wrap.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg-wrap.theirs {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 90%;
  width: 100%;
}

.chat-bubble {
  padding: 0.75rem 1.1rem;
  font-size: 0.925rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.mine {
  background: var(--chat-bubble-mine);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.chat-bubble.theirs {
  background: var(--chat-bubble-theirs);
  border: 1px solid var(--chat-bubble-theirs-border);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-xl) var(--radius-sm);
  color: var(--text-primary);
  width: 100%;
}

.assistant-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-default);
  font-size: 11.5px;
  color: var(--text-tertiary);
}

.assistant-model-pill {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--brand-primary);
}

.prose {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
}

.prose h1, .prose h2, .prose h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 12px 0 6px 0;
  color: var(--text-primary);
}

.prose p {
  margin-bottom: 10px;
}
.prose p:last-child {
  margin-bottom: 0;
}

.prose pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  margin: 10px 0;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.prose th, .prose td {
  border: 1px solid var(--border-default);
  padding: 6px 10px;
}

.prose th {
  background: var(--bg-tertiary);
}

.twigs-sources-section {
  margin-top: 12px;
  border-top: 1px solid var(--border-default);
  padding-top: 8px;
}

.twigs-sources-section summary {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.twigs-sources-section summary:hover {
  color: var(--text-secondary);
}

.source-excerpt-box {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  font-size: 12px;
  line-height: 1.5;
}

.source-excerpt-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--brand-accent);
  margin-bottom: 4px;
}

.chat-input-dock {
  padding: 16px 24px 24px 24px;
  background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
  flex-shrink: 0;
}

.chat-input-bar {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-fast);
}

.chat-input-bar:focus-within {
  border-color: var(--border-focus);
}

.chat-input-field {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.925rem;
  resize: none;
  outline: none;
  line-height: 1.5;
}

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

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--brand-primary);
  border: none;
  color: var(--bg-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.chat-send-btn:hover:not(:disabled) {
  opacity: 0.85;
  transform: scale(1.05);
}

.chat-send-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.twigs-modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.twigs-modal-bg.hidden {
  display: none;
}

.twigs-modal-window {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.twigs-modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.twigs-modal-head h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.twigs-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.twigs-toast-container {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 100;
  pointer-events: none;
}

.twigs-toast {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1.25rem;
  background: var(--bg-elevated);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 440px;
  animation: toastSlideIn 0.26s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  position: relative;
  overflow: hidden;
  will-change: transform, opacity;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(-1rem) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastFadeOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-0.75rem) scale(0.96);
  }
}

.twigs-toast--exit {
  animation: toastFadeOut 0.28s ease forwards;
}

.twigs-toast__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.twigs-toast__msg {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.twigs-toast__close {
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  cursor: pointer;
  background: none;
  border: none;
  transition: color var(--transition-fast);
  flex-shrink: 0;
}

.twigs-toast__close:hover {
  color: var(--text-primary);
}

@keyframes dropzonePulse {
  0%, 100% { border-color: var(--border-hover); }
  50% { border-color: #f59e0b; }
}

.twigs-highlight-pulse {
  animation: dropzonePulse 1s ease 2;
}
