/* ============================================================
   Companion RV4 — Stylesheet
   Base: rv4-assistent; accent shifted to green to visually
   distinguish this tool from the web assistant.
   ============================================================ */

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

:root {
  --primary: #1a1a2e;
  --primary-accent: #2e9268;   /* green (companion identity) */
  --accent: #2e9268;
  --accent-soft: rgba(46,146,104,0.12);
  --bg: #f5f5f5;
  --white: #ffffff;
  --gray-100: #f0f0f0;
  --gray-200: #e0e0e0;
  --gray-300: #ccc;
  --gray-500: #888;
  --gray-700: #555;
  --user-bubble: #e8f5ee;      /* light green tint */
  --engineer-red: #c62828;
  --review-orange: #e77a1d;
  --completed-green: #2e9268;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
          Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 54px;
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  border-top: 3px solid var(--primary-accent); /* small green top bar as companion marker */
  top: -3px;  /* compensate border */
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar .tag {
  background: var(--primary-accent);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

.topbar .project-switcher {
  margin-left: 16px;
}

.topbar select {
  background: rgba(255,255,255,0.08);
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  max-width: 240px;
}

.topbar select:focus {
  outline: none;
  border-color: var(--primary-accent);
}

.topbar select option {
  color: #222;
  background: var(--white);
}

.topbar .topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.topbar .btn-ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.topbar .btn-ghost:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.5);
  color: var(--white);
}

/* ---------- Login page ---------- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 36px 36px;
  width: 100%;
  max-width: 380px;
}

.login-card .login-header {
  background: var(--primary);
  color: var(--white);
  margin: -40px -36px 28px;
  padding: 28px 36px 22px;
  border-radius: var(--radius) var(--radius) 0 0;
  text-align: center;
  border-top: 3px solid var(--primary-accent);
}

.login-card .login-header h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.login-card .login-header p {
  font-size: 13px;
  opacity: 0.75;
}

.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 5px;
}

.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  margin-bottom: 18px;
  transition: border-color 0.2s;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-card .btn-login {
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s;
}

.login-card .btn-login:hover { background: #16213e; }
.login-card .btn-login:disabled { opacity: 0.6; cursor: not-allowed; }

.login-error {
  background: #fdecea;
  color: #b71c1c;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: none;
}
.login-error.visible { display: block; }

/* ---------- Main layout ---------- */
.main-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #fafafa;
  border-right: 1px solid var(--gray-200);
  padding: 20px;
  padding-top: 74px;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }

.sidebar-heading {
  font-size: 1rem;
  font-weight: 700;
  color: #222;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-heading .btn-new-project {
  background: var(--accent);
  color: var(--white);
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s;
}
.sidebar-heading .btn-new-project:hover { background: #25755a; }

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #666;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 18px;
  margin-bottom: 8px;
}

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

.sidebar-item {
  padding: 9px 12px;
  font-size: 0.88rem;
  color: #333;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item:hover { background: var(--gray-100); }

.sidebar-item.active {
  background: var(--accent-soft);
  color: #1a5a3e;
  font-weight: 600;
}

.sidebar-item .meta {
  font-size: 11px;
  color: var(--gray-500);
  font-weight: 400;
}

.sidebar-empty {
  color: var(--gray-500);
  font-size: 13px;
  font-style: italic;
  padding: 12px;
}

/* ---------- Chat ---------- */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex: 1;
  min-width: 0;
  max-width: 860px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 70px 16px 160px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }

/* ---------- Starters ---------- */
.starters {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 20px;
}

.starters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 560px;
  width: 100%;
}

.starter-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px 16px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
  line-height: 1.4;
}

.starter-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.starter-card .starter-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  line-height: 24px;
  text-align: center;
  margin-bottom: 8px;
  font-weight: 700;
}

.starters .no-project-hint {
  max-width: 520px;
  text-align: center;
  padding: 32px;
  background: var(--white);
  border: 1px dashed var(--gray-300);
  border-radius: var(--radius);
  color: var(--gray-700);
}

.starters .no-project-hint strong {
  display: block;
  font-size: 16px;
  margin-bottom: 8px;
  color: #222;
}

/* ---------- Bubbles ---------- */
.message {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
}

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message.system { align-items: center; }

.bubble {
  max-width: 80%;
  padding: 10px 15px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message.assistant .bubble {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message.system .bubble {
  background: transparent;
  color: var(--gray-500);
  font-style: italic;
  font-size: 13px;
  padding: 6px 12px;
}

.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble ul, .bubble ol { margin: 6px 0 6px 20px; }
.bubble li { margin-bottom: 3px; }

.bubble code {
  background: var(--gray-100);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.bubble pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.45;
}

.bubble pre code { background: transparent; padding: 0; color: inherit; }
.bubble a { color: var(--accent); text-decoration: underline; }

/* Semàfors de marcadors */
.bubble .marker-eng,
.bubble strong.marker-eng { color: var(--engineer-red); }
.bubble .marker-rev,
.bubble strong.marker-rev { color: var(--review-orange); }
.bubble .marker-ok,
.bubble strong.marker-ok { color: var(--completed-green); }

/* ---------- Thinking indicator ---------- */
.thinking-indicator .bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
}

.thinking-indicator .dot {
  width: 7px;
  height: 7px;
  background: var(--gray-500);
  border-radius: 50%;
  animation: pulse-dot 1.4s ease-in-out infinite;
}

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

@keyframes pulse-dot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.thinking-text {
  font-size: 13px;
  color: var(--gray-500);
  margin-left: 6px;
  font-style: italic;
}

/* ---------- Input area ---------- */
.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  padding: 12px 16px;
  z-index: 50;
}

.input-inner {
  max-width: 860px;
  margin: 0 auto;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.45;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
}

.input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-row textarea::placeholder { color: var(--gray-500); }
.input-row textarea:disabled {
  background: var(--gray-100);
  color: var(--gray-500);
  cursor: not-allowed;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

.btn-send {
  background: var(--primary);
  color: var(--white);
}
.btn-send:hover { background: #16213e; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-mic {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-mic:hover { background: var(--gray-200); }
.btn-mic.recording {
  background: var(--engineer-red);
  color: var(--white);
  animation: pulse-rec 1.2s ease-in-out infinite;
}

@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(198,40,40,0.45); }
  50% { box-shadow: 0 0 0 8px rgba(198,40,40,0); }
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Status / error strip above input */
.status-strip {
  max-width: 860px;
  margin: 0 auto 8px;
  font-size: 12px;
  color: var(--gray-500);
  text-align: center;
  min-height: 18px;
}

.status-strip.error { color: var(--engineer-red); }

/* Modal for new project */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.visible { display: flex; }

.modal-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.modal-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  border: none;
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-primary {
  background: var(--accent);
  color: var(--white);
}
.btn-primary:hover { background: #25755a; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar .project-switcher { margin-left: 8px; }
  .topbar select { max-width: 140px; font-size: 12px; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 14px; }
  .topbar h1 { font-size: 15px; gap: 6px; }
  .topbar .tag { font-size: 9px; padding: 2px 6px; }
  .chat-messages { padding: 62px 10px 150px; }
  .starters-grid { grid-template-columns: 1fr; max-width: 100%; }
  .starter-card { font-size: 13px; padding: 14px; }
  .bubble { max-width: 90%; font-size: 13.5px; }
  .input-area { padding: 10px 10px; }
  .input-row textarea { font-size: 15px; }
  .login-card { padding: 32px 24px 28px; }
  .login-card .login-header { margin: -32px -24px 24px; padding: 24px 24px 18px; }
}
