/* public/css/app.css */

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--smooth);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-primary);
}
.sidebar-logo .logo-mark { color: var(--accent); font-size: 18px; }
.sidebar-logo .logo-text { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }

.btn-new-chat {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--fast);
}
.btn-new-chat:hover { color: var(--text-primary); border-color: var(--border-bright); }

.sidebar-section { flex: 1; overflow-y: auto; padding: 12px 0; }
.sidebar-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 16px;
  margin-bottom: 8px;
}

.conv-list { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.conv-empty { font-size: 13px; color: var(--text-muted); padding: 8px; }

.conv-item {
  padding: 9px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--fast);
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
}
.conv-item:hover { background: var(--elevated); color: var(--text-primary); }
.conv-item.active { background: var(--accent-dim); color: var(--text-primary); }

/* Memory panel */
.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 12px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-panel {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.memory-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
.mp-icon { color: var(--accent); font-size: 12px; }
.mp-title { font-family: var(--font-display); font-weight: 600; font-size: 12px; flex: 1; }
.mp-expand {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  transition: transform var(--fast);
}
.mp-expand.open { transform: rotate(180deg); }

.memory-panel-body { padding: 0 12px 12px; }
.mp-stat-row { display: flex; justify-content: space-between; margin-bottom: 6px; }
.mp-stat-label { font-size: 11px; color: var(--text-muted); }
.mp-stat-val { font-size: 11px; color: var(--text-secondary); font-weight: 500; }

.mp-nodes-list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.mp-node-item {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface);
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mp-node-item .node-type {
  color: var(--accent);
  font-weight: 600;
  margin-right: 4px;
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.06em;
}

.mp-export {
  width: 100%;
  justify-content: center;
  font-size: 11px;
  padding: 6px 10px;
  gap: 6px;
}

/* User row */
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 0;
  position: relative;
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent-dim);
  border: 1px solid rgba(232,184,75,0.3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-plan { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.user-menu-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 4px;
  transition: color var(--fast);
}
.user-menu-btn:hover { color: var(--text-primary); }

.user-dropdown {
  position: absolute;
  bottom: 100%;
  right: 0;
  background: var(--elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--r-md);
  padding: 4px;
  min-width: 140px;
  z-index: 50;
}
.dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: all var(--fast);
  text-align: left;
}
.dd-item:hover { background: rgba(255,80,80,0.08); color: #ff6b6b; }

/* ─── Chat area ────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--void);
}

.chat-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-toggle {
  background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px;
}
.chat-header-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; }

/* Messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Welcome screen */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
}
.welcome-mark {
  font-size: 40px;
  color: var(--accent);
  margin-bottom: 20px;
  opacity: 0.7;
}
.welcome-screen h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: -0.025em;
  margin-bottom: 8px;
}
.welcome-screen p { color: var(--text-secondary); font-size: 16px; margin-bottom: 40px; }

.welcome-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 560px;
  margin-bottom: 40px;
}
.suggestion-chip {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 18px;
  cursor: pointer;
  transition: all var(--smooth);
  font-family: var(--font-body);
}
.suggestion-chip:hover {
  border-color: rgba(232,184,75,0.4);
  color: var(--text-primary);
  background: var(--accent-dim);
}

/* Limit bar */
.msg-limit-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 360px;
}
.mlb-track {
  flex: 1;
  height: 3px;
  background: var(--elevated);
  border-radius: 2px;
  overflow: hidden;
}
.mlb-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s var(--ease);
  width: 0%;
}
.mlb-fill.warning { background: #ff9500; }
.mlb-fill.danger { background: #ff3b30; }
#mlb-text { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* Messages list */
.messages-list {
  flex: 1;
  padding: 32px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.msg-row {
  display: flex;
  flex-direction: column;
  padding: 12px 40px;
  animation: fadeUp 0.3s var(--ease);
  max-width: 100%;
}
.msg-row:hover { background: rgba(255,255,255,0.01); }
.msg-row.user { align-items: flex-end; }
.msg-row.assistant { align-items: flex-start; }

.msg-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
  font-weight: 600;
}
.msg-row.user .msg-label { color: var(--text-muted); }
.msg-row.assistant .msg-label { color: var(--accent); opacity: 0.7; }

.msg-bubble {
  max-width: 680px;
  font-size: 15px;
  line-height: 1.75;
}
.msg-row.user .msg-bubble {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg) var(--r-lg) 4px var(--r-lg);
  padding: 12px 18px;
  color: var(--text-primary);
}
.msg-row.assistant .msg-bubble {
  color: var(--text-primary);
}

/* Markdown-like em respostas */
.msg-bubble strong { color: var(--text-primary); font-weight: 600; }
.msg-bubble em { color: var(--text-secondary); font-style: italic; }
.msg-bubble code {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: var(--accent);
}
.msg-bubble pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.msg-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: var(--text-primary);
}

/* Typing indicator no chat */
.typing-row {
  padding: 12px 40px;
  animation: fadeIn 0.3s var(--ease);
}
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 14px;
}
.typing-dots span {
  width: 5px; height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: blink 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ─── Input area ───────────────────────────────────────────────────────── */
.input-area {
  padding: 16px 40px 24px;
  border-top: 1px solid var(--border);
  background: var(--void);
}
.input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.textarea-wrap { flex: 1; }
.chat-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 14px 18px;
  resize: none;
  outline: none;
  transition: border-color var(--fast), box-shadow var(--fast);
  line-height: 1.6;
  max-height: 200px;
  overflow-y: auto;
}
.chat-textarea::placeholder { color: var(--text-muted); }
.chat-textarea:focus {
  border-color: rgba(232,184,75,0.4);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.send-btn {
  width: 48px; height: 48px;
  background: var(--accent);
  border: none;
  border-radius: var(--r-md);
  color: #1a1000;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--smooth);
  flex-shrink: 0;
}
.send-btn:hover:not(:disabled) {
  background: #f0c55a;
  transform: translateY(-1px);
}
.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}
.send-btn.loading {
  background: var(--elevated);
  color: var(--accent);
}

.input-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}
.input-hint { font-size: 11px; color: var(--text-muted); }
.char-count { font-size: 11px; color: var(--text-muted); }

/* ─── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
    display: none;
  }
  .sidebar-overlay.visible { display: block; }
  .chat-header { display: flex; }
  .msg-row { padding: 10px 16px; }
  .input-area { padding: 12px 16px 20px; }
  .typing-row { padding: 10px 16px; }
}

@media (min-width: 769px) {
  .chat-header { display: none; }
}
