/* style.css — Privacy Chat App */

/* ============================================================
   CSS Reset + base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f11;
  --surface:   #1a1a1e;
  --border:    #2e2e35;
  --text:      #e8e8ec;
  --text-muted:#9090a0;
  --accent:    #7c6ff7;
  --accent-dim:#3a3470;
  --danger:    #e05050;
  --success:   #4caf80;
  --radius:    10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f4f4f7;
    --surface:   #ffffff;
    --border:    #dcdce8;
    --text:      #1a1a22;
    --text-muted:#70708a;
    --accent:    #5a4ff0;
    --accent-dim:#e0deff;
    --danger:    #c03030;
    --success:   #287a50;
  }
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
}

/* ============================================================
   Layout
   ============================================================ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 8px;  }

.app-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.main-layout {
  display: flex;
  height: calc(100vh - 57px); /* 57px = topbar height */
}

.chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  padding: 0 12px;
}

/* ============================================================
   Chat messages
   ============================================================ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 76%;
  animation: fadeIn 0.15s ease;
}

.message.user    { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message.system-message { align-self: center; max-width: 100%; }

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.65;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--accent-dim);
  color: var(--text);
  border-bottom-right-radius: 2px;
}

.message.assistant .message-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.message.system-message {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Streaming indicator: blinking cursor on the last message */
.message.streaming .message-bubble::after {
  content: '▋';
  animation: blink 0.7s step-end infinite;
  color: var(--accent);
  margin-left: 2px;
}

/* ============================================================
   Input area
   ============================================================ */
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

.message-textarea {
  flex: 1;
  resize: none;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

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

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  padding: 8px 16px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

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

.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-ghost     { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ============================================================
   Plan badge
   ============================================================ */
.plan-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

.plan-free   { background: var(--border); color: var(--text-muted); }
.plan-pro50  { background: #2a4a7f; color: #90c4ff; }
.plan-pro100 { background: #2e4a30; color: #90d090; }
.plan-pro200 { background: #4a2e50; color: #d090f0; }

/* ============================================================
   Model selector
   ============================================================ */
#model-select {
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  max-width: 200px;
}

/* ============================================================
   Modals
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-content h2 { font-size: 20px; }
.modal-subtitle   { color: var(--text-muted); font-size: 14px; }
.modal-actions    { display: flex; gap: 10px; flex-wrap: wrap; }

/* Plan grid in upgrade modal */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.plan-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

.plan-card.featured { border-color: var(--accent); }

.plan-badge-inner {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.plan-name  { font-weight: 600; font-size: 16px; }
.plan-price { font-size: 26px; font-weight: 700; color: var(--accent); }
.plan-price span { font-size: 14px; font-weight: 400; color: var(--text-muted); }

.plan-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
}

.plan-features li::before { content: "✓ "; color: var(--success); }

/* Recovery key box */
.recovery-key-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--mono);
  font-size: 20px;
  text-align: center;
  letter-spacing: 0.1em;
  color: var(--accent);
  word-break: break-all;
}

/* Text input */
.input-field {
  width: 100%;
  padding: 10px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: var(--mono);
  letter-spacing: 0.05em;
}

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

.error-msg { color: var(--danger); font-size: 13px; }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes blink  { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ============================================================
   Markdown-like formatting in assistant messages
   ============================================================ */
.message-bubble pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  margin: 8px 0;
}

.message-bubble code { font-size: 13px; }
.message-bubble p    { margin: 4px 0; }
