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

:root {
  --bg: #0a0a0f;
  --bg-surface: #12121a;
  --bg-elevated: #1a1a26;
  --bg-input: #16161f;
  --border: #252535;
  --border-focus: #4a4a6a;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --text-muted: #555568;
  --accent: #6ee7b7;
  --accent-dim: #2d6b53;
  --accent-glow: rgba(110, 231, 183, 0.1);
  --tier1: #6ee7b7;
  --tier2: #fbbf24;
  --tier3: #818cf8;
  --error: #f87171;
  --filed: #6ee7b7;
  --captured: #fbbf24;
  --pending: #a78bfa;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Header ──────────────────────────────── */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.logo {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.tagline {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pulse-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.header-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

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

/* ── Views ───────────────────────────────── */
.view {
  display: none;
  height: 100%;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* ── Chat View ───────────────────────────── */
#chat-view {
  padding-top: 56px;
  padding-bottom: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 100px;
  scroll-behavior: smooth;
}

.message {
  margin-bottom: 16px;
  animation: fadeIn 0.25s ease-out;
}

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

.message-content {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
}

.message.user .message-content {
  margin-left: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-right-radius: 3px;
}

.message.agent .message-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.message.agent.welcome .message-content {
  border-color: var(--accent-dim);
  background: var(--accent-glow);
}

.message-content p {
  margin-bottom: 8px;
}

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

.hint {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Filing Preview ──────────────────────── */
.filing-preview {
  margin-top: 10px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.filing-preview .fp-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.filing-preview .fp-summary {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.filing-preview .fp-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.fp-category {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.fp-tier {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.fp-tier.tier-1 { background: rgba(110,231,183,0.12); color: var(--tier1); border: 1px solid rgba(110,231,183,0.25); }
.fp-tier.tier-2 { background: rgba(251,191,36,0.12); color: var(--tier2); border: 1px solid rgba(251,191,36,0.25); }
.fp-tier.tier-3 { background: rgba(129,140,248,0.12); color: var(--tier3); border: 1px solid rgba(129,140,248,0.25); }

.fp-dedup {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.fp-why {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* ── Notes Textarea ──────────────────────── */
.fp-notes {
  margin-top: 8px;
}

.fp-notes textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 8px;
  resize: vertical;
  min-height: 36px;
}

.fp-notes textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.fp-notes textarea::placeholder {
  color: var(--text-muted);
}

/* ── Action Buttons ──────────────────────── */
.fp-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.fp-actions button {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}

.btn-file {
  background: var(--accent);
  color: #0a0a0f;
  border-color: var(--accent) !important;
}

.btn-file:hover {
  background: #5dd9a8;
}

.btn-inbox {
  background: transparent;
  color: var(--captured);
  border-color: var(--captured) !important;
}

.btn-inbox:hover {
  background: rgba(251,191,36,0.1);
}

.btn-review {
  background: transparent;
  color: var(--pending);
  border-color: var(--pending) !important;
}

.btn-review:hover {
  background: rgba(167,139,250,0.1);
}

/* ── Chat Input ──────────────────────────── */
.chat-input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
}

#chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 10px 14px;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.15s;
}

#chat-input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  background: var(--accent);
  border: none;
  color: #0a0a0f;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.btn-send:hover {
  background: #5dd9a8;
}

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

/* ── Browse View ─────────────────────────── */
#browse-view {
  padding-top: 56px;
}

.browse-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.browse-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.tab {
  padding: 6px 14px;
  border-radius: 20px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.15s;
}

.tab.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.count-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--captured);
  color: #0a0a0f;
  padding: 1px 5px;
  border-radius: 10px;
  margin-left: 4px;
  font-weight: 600;
}

.browse-search {
  margin-bottom: 8px;
}

.browse-search input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  font-family: var(--font-body);
}

.browse-search input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.browse-search input::placeholder {
  color: var(--text-muted);
}

.browse-filters {
  display: flex;
  gap: 8px;
}

.browse-filters select {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 6px 8px;
  font-family: var(--font-body);
}

.entries-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-style: italic;
}

.entry-card {
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.entry-card:hover {
  border-color: var(--accent-dim);
}

.entry-card .ec-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.entry-card .ec-summary {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.entry-card .ec-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.entry-card .ec-status {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ec-status.filed { background: rgba(110,231,183,0.12); color: var(--filed); }
.ec-status.captured { background: rgba(251,191,36,0.12); color: var(--captured); }
.ec-status.pending_review { background: rgba(167,139,250,0.12); color: var(--pending); }
.ec-status.failed { background: rgba(248,113,113,0.12); color: var(--error); }

.entry-card .ec-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

.browse-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.btn-primary {
  flex: 1;
  padding: 10px;
  background: var(--accent);
  color: #0a0a0f;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary {
  flex: 1;
  padding: 10px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
}

/* ── Loading Indicator ───────────────────── */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 8px 12px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* ── Responsive ──────────────────────────── */
@media (min-width: 640px) {
  .messages {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px;
    padding-bottom: 100px;
  }

  .message-content {
    max-width: 75%;
  }

  .tagline {
    display: inline;
  }
}

@media (max-width: 480px) {
  .tagline {
    display: none;
  }

  .pulse-badge {
    font-size: 10px;
    padding: 3px 8px;
  }
}

/* ── Scrollbar ───────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
