:root {
  --bg-primary: #1a1915;
  --bg-secondary: #1e1d17;
  --bg-card: #2a2922;
  --bg-input: #1e1d17;
  --bg-hover: #33322a;
  --bg-active: #3d3c33;
  --text-primary: #e6e5e0;
  --text-secondary: rgba(230, 229, 224, 0.55);
  --text-tertiary: rgba(230, 229, 224, 0.35);
  --accent: #f54e00;
  --accent-glow: rgba(245, 78, 0, 0.15);
  --error: #e04a6f;
  --error-glow: rgba(224, 74, 111, 0.15);
  --success: #2fba8a;
  --success-glow: rgba(47, 186, 138, 0.12);
  --gold: #d9a04a;
  --thinking: #a06b50;
  --grep: #5a9e5e;
  --read: #5a8ab8;
  --edit: #8a6fb8;
  --border-default: rgba(230, 229, 224, 0.1);
  --border-medium: rgba(230, 229, 224, 0.2);
  --border-strong: rgba(230, 229, 224, 0.55);
  --shadow-card: rgba(0, 0, 0, 0.4) 0px 28px 70px 0px, rgba(0, 0, 0, 0.3) 0px 14px 32px 0px, rgba(230, 229, 224, 0.08) 0px 0px 0px 1px;
  --shadow-ambient: rgba(0, 0, 0, 0.1) 0px 0px 16px 0px, rgba(0, 0, 0, 0.05) 0px 0px 8px 0px;
  --shadow-focus: rgba(245, 78, 0, 0.3) 0px 4px 12px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-pill: 9999px;
  --font-gothic: "Lato", system-ui, -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --font-ui: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-gothic);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
}

/* ========== Navigation ========== */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 12px 32px;
  background: rgba(26, 25, 21, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-default);
  gap: 24px;
}

nav .logo {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.28px;
  text-decoration: none;
  margin-right: auto;
}

nav .nav-links {
  display: flex;
  gap: 8px;
  list-style: none;
}

nav .nav-link {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  transition: color 0.15s ease, background 0.15s ease;
}

nav .nav-link:hover {
  color: var(--accent);
  background: var(--accent-glow);
}

nav .nav-link.active {
  color: var(--accent);
  background: var(--accent-glow);
}

/* ========== Container ========== */
.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px;
}

/* ========== Card ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 20px;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-card);
}

.card-title {
  font-size: 22px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.11px;
  color: var(--text-primary);
  margin-bottom: 20px;
}

/* ========== Section Labels ========== */
.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

/* ========== Forms ========== */
.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 8px 8px 6px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: var(--font-gothic);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

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

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

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-group {
  flex: 1;
}

.form-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ========== Buttons ========== */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-gothic);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  line-height: 1;
}

.btn-primary {
  background: var(--bg-active);
  color: var(--text-primary);
}

.btn-primary:hover {
  color: var(--accent);
}

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

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}

.btn-accent:hover {
  opacity: 0.85;
}

.btn-ghost {
  background: rgba(230, 229, 224, 0.06);
  color: var(--text-secondary);
  padding: 6px 12px;
}

.btn-ghost:hover {
  color: var(--accent);
}

.btn-pill {
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
}

.btn-pill:hover {
  color: var(--accent);
}

/* ========== Status Messages ========== */
.status-msg {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 12px;
  line-height: 1.4;
}

.status-info {
  background: rgba(245, 78, 0, 0.08);
  color: var(--accent);
  border-left: 2px solid var(--accent);
}

.status-success {
  background: var(--success-glow);
  color: var(--success);
  border-left: 2px solid var(--success);
}

.status-error {
  background: var(--error-glow);
  color: var(--error);
  border-left: 2px solid var(--error);
}

/* ========== Hidden ========== */
.hidden {
  display: none !important;
}

/* ========== Chat Page ========== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px - 64px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--border-medium);
}

.message {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.65;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
  border-bottom-right-radius: 2px;
  font-weight: 500;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-bottom-left-radius: 2px;
  color: var(--text-primary);
}

.message.assistant p {
  margin-bottom: 10px;
}

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

.message.assistant pre {
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.67;
  color: var(--text-secondary);
}

.message.assistant code {
  font-family: var(--font-mono);
  font-size: 12px;
}

.message.assistant :not(pre) > code {
  background: rgba(230, 229, 224, 0.08);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--gold);
}

.message.assistant ul,
.message.assistant ol {
  padding-left: 20px;
  margin: 8px 0;
}

.message.assistant li {
  margin-bottom: 4px;
}

.message.assistant blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 12px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-family: var(--font-serif);
  font-style: italic;
}

.sources {
  margin-top: 14px;
  padding: 12px 14px;
  background: rgba(230, 229, 224, 0.04);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-tertiary);
}

.sources-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.sources div:not(.sources-title) {
  margin-top: 3px;
  line-height: 1.5;
}

.chat-input-area {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--border-default);
}

.chat-input-area textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 14px;
}

.chat-input-area textarea:focus {
  border-color: var(--border-medium);
  box-shadow: none;
}

.chat-input-area .btn-accent {
  align-self: flex-end;
}

.loading-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 40px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--text-tertiary);
  line-height: 1.35;
}

/* ========== Chunk Preview ========== */
.chunk-preview {
  margin-top: 16px;
}

.chunk-item {
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-secondary);
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.6;
  transition: border-color 0.15s;
}

.chunk-item:hover {
  border-color: var(--border-medium);
}

.chunk-index {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

/* ========== File Upload ========== */
.file-upload-area {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-md);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.file-upload-area:hover {
  border-color: var(--border-medium);
  background: rgba(230, 229, 224, 0.02);
}

.file-upload-area .icon {
  font-size: 32px;
  margin-bottom: 10px;
  opacity: 0.5;
}

.file-upload-area p {
  font-size: 14px;
  color: var(--text-secondary);
}

.file-upload-area .sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ========== Truncate ========== */
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== Page Header ========== */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 36px;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.72px;
  color: var(--text-primary);
}

.page-header p {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--text-secondary);
  line-height: 1.35;
  margin-top: 8px;
}

/* ========== Divider ========== */
.section-divider {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: 0;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  nav {
    padding: 12px 16px;
  }

  .container {
    padding: 20px 16px;
  }

  .form-row {
    flex-direction: column;
  }

  .message {
    max-width: 90%;
  }

  .page-header h1 {
    font-size: 26px;
    letter-spacing: -0.325px;
  }

  .card-title {
    font-size: 18px;
  }
}
