/* ============================================================
   Fern LLM — dark, minimalist, leaf-themed UI
   Inspired by the uploaded reference screenshot
   ============================================================ */

:root {
  /* Surfaces */
  --bg-app: #121212;
  --bg-sidebar: #1A1A1A;
  --bg-elevated: #1E1E1E;
  --bg-input: #2A2A2A;
  --bg-input-focus: #2D2D2D;
  --bg-hover: #262626;

  /* Borders / dividers */
  --border-subtle: #2D2D2D;
  --border-strong: #3D3D3D;

  /* Text */
  --text-primary: #FFFFFF;
  --text-secondary: #B0B0B0;
  --text-tertiary: #6B6B6B;

  /* Brand / accent */
  --fern-green: #4CAF50;
  --fern-green-soft: #81C784;
  --fern-green-deep: #2E7D32;
  --fern-green-glow: rgba(76, 175, 80, 0.18);

  /* Sizing */
  --sidebar-w: 260px;
  --header-h: 56px;
  --radius-pill: 24px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Menlo, Monaco, 'Cascadia Mono', Consolas, monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ====================== App layout ====================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100vw;
}

/* ====================== Sidebar ====================== */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  filter: drop-shadow(0 0 6px var(--fern-green-glow));
}
.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 24px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.nav-item.active .nav-dot {
  display: block;
}
.nav-dot {
  display: none;
  width: 6px;
  height: 6px;
  background: var(--fern-green);
  border-radius: 50%;
  margin-left: auto;
  box-shadow: 0 0 6px var(--fern-green);
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 0 12px 8px;
}
.history {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-item {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s, color 0.15s;
}
.history-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.history-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.history-item .delete-btn {
  float: right;
  opacity: 0;
  color: var(--text-tertiary);
  transition: opacity 0.15s;
}
.history-item:hover .delete-btn { opacity: 1; }
.history-item .delete-btn:hover { color: var(--text-primary); }

.sidebar-footer {
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border-subtle);
}
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 4px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  flex-shrink: 0;
}
.status-dot.loading {
  background: #FFB300;
  box-shadow: 0 0 6px rgba(255, 179, 0, 0.6);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-dot.ready {
  background: var(--fern-green);
  box-shadow: 0 0 6px var(--fern-green);
}
.status-dot.error {
  background: #E53935;
  box-shadow: 0 0 6px rgba(229, 57, 53, 0.6);
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ====================== Main ====================== */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-app);
  position: relative;
  min-width: 0;
}

.main-header {
  height: var(--header-h);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
}

.model-selector {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  cursor: default;
}
.model-selector svg { color: var(--text-secondary); }

.mobile-menu { display: none; }

/* ====================== Chat view ====================== */
.chat-view {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  gap: 16px;
}
.empty-icon {
  filter: drop-shadow(0 8px 24px var(--fern-green-glow));
  animation: float 4s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.empty-title {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 8px;
}
.empty-subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.6;
  max-width: 480px;
}
.empty-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
  max-width: 560px;
}
.prompt-chip {
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.prompt-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* ====================== Messages ====================== */
.messages {
  flex: 1;
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.message {
  display: flex;
  gap: 14px;
  animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.message.user .msg-avatar {
  background: linear-gradient(135deg, #5a5a5a, #3a3a3a);
}
.message.fern .msg-avatar {
  background: linear-gradient(135deg, var(--fern-green-soft), var(--fern-green-deep));
}
.message.fern .msg-avatar::after {
  content: '';
  width: 18px;
  height: 18px;
  background: url('assets/fern-icon.svg') center/contain no-repeat;
  filter: brightness(1.4);
}

.msg-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg-content {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
  word-wrap: break-word;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg-content .cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--fern-green);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ====================== Input area ====================== */
.input-area {
  padding: 0 24px 16px;
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
}
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 6px 6px 6px 8px;
  transition: border-color 0.15s, background 0.15s;
}
.input-bar:focus-within {
  background: var(--bg-input-focus);
  border-color: var(--border-strong);
}

.input-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.input-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
  padding: 10px 4px;
  max-height: 200px;
  min-height: 24px;
}
.input::placeholder { color: var(--text-tertiary); }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--fern-green);
  color: #0c2208;
  border-radius: 50%;
  transition: all 0.15s;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.send-btn:hover:not(:disabled) {
  background: var(--fern-green-soft);
  transform: scale(1.05);
}
.send-btn:disabled {
  background: var(--bg-hover);
  color: var(--text-tertiary);
  cursor: not-allowed;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* ====================== About / model views ====================== */
.about-view {
  flex: 1;
  overflow-y: auto;
  padding: 48px 24px;
}
.about-content {
  max-width: 720px;
  margin: 0 auto;
}
.about-content img {
  display: block;
  margin: 0 auto 16px;
  filter: drop-shadow(0 0 16px var(--fern-green-glow));
}
.about-content h1 {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
  letter-spacing: -0.02em;
}
.about-content h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 24px 0 10px;
  color: var(--text-primary);
}
.about-content p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 12px;
}
.about-content ul {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
  padding-left: 24px;
  margin-bottom: 12px;
}
.about-content strong { color: var(--text-primary); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
}
.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--fern-green-soft);
}

.settings-row {
  display: grid;
  grid-template-columns: 140px 1fr 50px;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.settings-row label {
  font-size: 14px;
  color: var(--text-secondary);
}
.settings-row input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-elevated);
  height: 4px;
  border-radius: 2px;
  outline: none;
}
.settings-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fern-green);
  cursor: pointer;
  box-shadow: 0 0 8px var(--fern-green-glow);
}
.settings-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--fern-green);
  cursor: pointer;
}
.settings-row span {
  font-size: 14px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ====================== Mobile ====================== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    z-index: 100;
    box-shadow: 8px 0 32px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: inline-flex; }
  .main-header { justify-content: flex-start; }
  .model-selector { margin-left: 8px; }
  .empty-title { font-size: 26px; }
  .messages { padding: 16px; }
  .input-area { padding: 0 12px 12px; }
}

/* ====================== Scrollbar ====================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
