:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1f0eb;
  --border: #e2e0d8;
  --text: #1c1b18;
  --text-muted: #75736a;
  --accent: #2d6a4f;
  --accent-hover: #1f5138;
  --accent-soft: #e8f2ec;
  --danger-bg: #fdecea;
  --danger-text: #a12;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.04), 0 4px 16px rgba(20, 20, 15, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #16160f;
  --surface: #1e1e17;
  --surface-2: #262619;
  --border: #34331f;
  --text: #ede9d8;
  --text-muted: #a3a08c;
  --accent: #6fcf9c;
  --accent-hover: #8adeb0;
  --accent-soft: #1e3529;
  --danger-bg: #3a1f1c;
  --danger-text: #f2938a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.6;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

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

.topbar .brand {
  font-weight: 600;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--text);
}

.topbar .session {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.topbar .session a {
  color: var(--accent);
  text-decoration: none;
  margin-left: 8px;
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 8px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 32px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

form p { margin: 0 0 16px; }

label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="file"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 1rem;
  background: var(--bg);
}

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

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button, .btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

button:hover, .btn:hover { background: var(--accent-hover); }

.doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.doc-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.doc-list li:last-child { border-bottom: none; }

.doc-list a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.doc-list a:hover { color: var(--accent); }

.status-badge {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef4f1;
  color: var(--accent);
  font-weight: 600;
}

.status-badge.processing { background: #fdf3e3; color: #a56b0a; }
.status-badge.failed { background: var(--danger-bg); color: var(--danger-text); }

.answer-box {
  background: #f3f7f5;
  border: 1px solid #d9e8e1;
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 20px;
  white-space: pre-wrap;
}

.answer-box h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--accent);
}

.error-box {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 20px;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-switch a { color: var(--accent); font-weight: 600; text-decoration: none; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-flex; align-items: center; gap: 8px; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.doc-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.doc-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.doc-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.75rem;
  margin-bottom: 12px;
}

.doc-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 8px;
  word-break: break-word;
}

.doc-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.doc-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}
