/* ============================================================
   LEDGER — Personal Expense Tracker
   Aesthetic: Dark terminal / financial ledger
   Fonts: IBM Plex Mono + IBM Plex Sans
   ============================================================ */

:root {
  --bg-base: #0a0b0e;
  --bg-surface: #0f1117;
  --bg-raised: #161820;
  --bg-overlay: #1c1f2a;
  --bg-hover: #1e2130;

  --border: #232635;
  --border-bright: #2e3248;

  --text-primary: #e8eaf0;
  --text-secondary: #8b90a8;
  --text-muted: #4a4f68;
  --text-mono: #c8cad6;

  --accent: #4fc3f7;
  --accent-dim: #1a3a50;
  --accent-glow: rgba(79, 195, 247, 0.15);

  --green: #69f0ae;
  --green-dim: #0d2a1a;
  --red: #ff6b6b;
  --red-dim: #2a0d0d;
  --amber: #ffca28;
  --amber-dim: #2a2008;
  --purple: #ce93d8;

  --sidebar-width: 240px;
  --header-height: 56px;
  --input-area-height: 100px;

  --radius: 6px;
  --radius-lg: 12px;
  --font-mono: 'IBM Plex Mono', monospace;
  --font-sans: 'IBM Plex Sans', sans-serif;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ─────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100dvh;
  transition: grid-template-columns 0.3s ease;
}

.app.sidebar-hidden {
  grid-template-columns: 0 1fr;
}

/* ── SIDEBAR ─────────────────────────────────── */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease;
  z-index: 50;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.logo-symbol {
  font-size: 1.2rem;
  animation: pulse-logo 4s ease-in-out infinite;
}

@keyframes pulse-logo {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  margin-top: 3px;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  overflow-y: auto;
}

.nav-section-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  padding: 0 8px;
  margin-bottom: 6px;
  margin-top: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 400;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}

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

.nav-btn:active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-btn.danger:hover {
  background: var(--red-dim);
  color: var(--red);
}

.nav-icon {
  font-size: 0.8rem;
  width: 16px;
  text-align: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.nav-btn:hover .nav-icon { color: inherit; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.hint-box {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.hint-title {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.hint-item {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 2px 0;
  line-height: 1.6;
}

.hint-item::before {
  content: '› ';
  color: var(--accent);
  opacity: 0.5;
}

/* ── MAIN ─────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-base);
  position: relative;
}

/* Subtle grid overlay */
.main::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.2;
  pointer-events: none;
  z-index: 0;
}

/* ── HEADER ─────────────────────────────────── */
.chat-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: rgba(10, 11, 14, 0.9);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-secondary);
  transition: background 0.15s;
  border-radius: 2px;
}

.sidebar-toggle:hover span { background: var(--text-primary); }

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

.header-title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: blink-dot 3s ease-in-out infinite;
}

.status-dot.loading {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  animation: blink-dot 0.8s ease-in-out infinite;
}

@keyframes blink-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.header-right {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

/* ── MESSAGES ─────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 18px;
  position: relative;
  z-index: 1;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 4px; }

/* Welcome block */
.welcome-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  animation: fade-up 0.6s ease both;
}

.welcome-symbol {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 16px;
  opacity: 0.7;
}

.welcome-title {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.welcome-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
  max-width: 360px;
  line-height: 1.6;
}

.welcome-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.example-chip {
  padding: 6px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  letter-spacing: 0.04em;
}

.example-chip:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Message rows */
.message-row {
  display: flex;
  margin-bottom: 16px;
  animation: fade-up 0.3s ease both;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }

.bubble {
  max-width: min(85%, 580px);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 0.875rem;
}

.message-row.user .bubble {
  background: var(--accent-dim);
  border: 1px solid rgba(79, 195, 247, 0.25);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
}

.message-row.assistant .bubble {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
}

.message-row.assistant .bubble.success {
  border-color: rgba(105, 240, 174, 0.25);
  background: linear-gradient(135deg, var(--bg-raised), var(--green-dim));
}

.message-row.assistant .bubble.edited {
  border-color: rgba(255, 202, 40, 0.25);
  background: linear-gradient(135deg, var(--bg-raised), var(--amber-dim));
}

.message-row.assistant .bubble.deleted {
  border-color: rgba(255, 107, 107, 0.2);
  background: linear-gradient(135deg, var(--bg-raised), rgba(42, 13, 13, 0.5));
}

.message-row.assistant .bubble.error {
  border-color: rgba(255, 107, 107, 0.3);
  background: linear-gradient(135deg, var(--bg-raised), var(--red-dim));
}

/* Typing indicator */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-4px); opacity: 1; }
}

/* Markdown rendering inside bubbles */
.bubble h1, .bubble h2, .bubble h3 {
  font-family: var(--font-mono);
  font-weight: 600;
  margin-bottom: 10px;
  margin-top: 6px;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.bubble h1 { font-size: 1rem; }
.bubble h2 { font-size: 0.9rem; }
.bubble h3 { font-size: 0.85rem; color: var(--text-secondary); }

.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }

.bubble ul, .bubble ol {
  margin: 8px 0;
  padding-left: 18px;
}
.bubble li { margin-bottom: 4px; }

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

.bubble em { color: var(--text-secondary); font-style: italic; }

.bubble code {
  font-family: var(--font-mono);
  font-size: 0.8em;
  background: var(--bg-overlay);
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--amber);
}

/* ── INPUT AREA ─────────────────────────────────── */
.input-area {
  border-top: 1px solid var(--border);
  padding: 14px 18px;
  background: rgba(10, 11, 14, 0.95);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: rgba(79, 195, 247, 0.4);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.5;
  min-height: 22px;
  max-height: 120px;
  overflow-y: auto;
}

.message-input::placeholder { color: var(--text-muted); }
.message-input::-webkit-scrollbar { width: 3px; }
.message-input::-webkit-scrollbar-thumb { background: var(--border-bright); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.send-btn svg {
  width: 16px;
  height: 16px;
  color: var(--bg-base);
}

.send-btn:hover { background: #7dd3fc; }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled {
  background: var(--bg-overlay);
  cursor: not-allowed;
}
.send-btn:disabled svg { color: var(--text-muted); }

.input-hint {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-top: 8px;
  text-align: center;
}

.input-hint kbd {
  background: var(--bg-overlay);
  border: 1px solid var(--border-bright);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
}

/* ── OVERLAY (mobile) ─────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 40;
  backdrop-filter: blur(2px);
}

/* ── ANIMATIONS ─────────────────────────────── */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── MOBILE ─────────────────────────────────── */
@media (max-width: 700px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 50;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .overlay.visible {
    display: block;
  }

  .sidebar-toggle {
    display: flex;
  }

  .main::before { display: none; }

  .bubble { max-width: 92%; }

  .welcome-block { min-height: 50vh; }
  .welcome-title { font-size: 1.4rem; }
}

@media (min-width: 701px) {
  .sidebar-toggle { display: none; }
}
