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

:root {
  --bg:        #15171a;
  --bg2:       #1c1f23;
  --bg3:       #22262b;
  --border:    #2a2f36;
  --text:      #d4ccbe;
  --text-dim:  #7a7670;
  --gold:      #c9a876;
  --gold-dim:  #8a7356;
  --danger:    #c96a6a;
  --success:   #5a9a6e;
  --radius:    10px;
  --font:      'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
}

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

/* ── Utility ─────────────────────────────────── */
.hidden { display: none !important; }

/* ── Login screen ────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 60%, #1e1f2e 0%, var(--bg) 70%);
}

.login-card {
  text-align: center;
  max-width: 340px;
  width: 100%;
}

.moon-icon {
  font-size: 3.5rem;
  margin-bottom: 20px;
  display: block;
  filter: drop-shadow(0 0 20px rgba(201, 168, 118, 0.3));
}

.login-card h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.login-card p {
  color: var(--text-dim);
  margin-bottom: 40px;
  font-size: 0.95rem;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  transition: border-color 0.2s, background 0.2s;
}

.btn-google:hover {
  border-color: var(--gold-dim);
  background: var(--bg2);
}

/* ── App layout ──────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 52px;
}

.logo {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: -0.01em;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg3);
  flex-shrink: 0;
}

#user-name {
  font-size: 0.85rem;
  color: var(--text-dim);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: border-color 0.2s, color 0.2s;
}

.btn-icon:hover { border-color: var(--gold-dim); color: var(--gold); }

.admin-link { font-size: 0.85rem; }

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font);
  transition: border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}

.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

/* ── Body: sidebar + editor ──────────────────── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  padding: 20px 16px;
}

/* Streak card */
.streak-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
}

.streak-current {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
}

.streak-num {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}

.streak-label {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.streak-longest {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.streak-longest strong { color: var(--gold-dim); }

/* Ambient */
.ambient-section h3,
.entries-section h3 {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
  font-weight: 600;
}

.sound-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.sound-label {
  font-size: 0.82rem;
  width: 58px;
  flex-shrink: 0;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
  cursor: pointer;
  height: 2px;
}

/* Entries list */
.entries-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.entry-item {
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.entry-item:hover {
  background: var(--bg3);
}

.entry-item.active {
  background: var(--bg3);
  border-color: var(--border);
}

.entry-date {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.entry-item.active .entry-date { color: var(--gold); }

.entry-preview {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-load-more {
  margin-top: 8px;
  width: 100%;
  padding: 7px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font);
  transition: border-color 0.2s;
}

.btn-load-more:hover { border-color: var(--gold-dim); }

/* ── Editor area ─────────────────────────────── */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 28px;
  gap: 14px;
  min-width: 0;
}

/* Toolbar */
.editor-toolbar {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.btn-prompt {
  padding: 7px 14px;
  background: none;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  flex-shrink: 0;
  transition: background 0.2s;
}

.btn-prompt:hover { background: rgba(201, 168, 118, 0.08); }

.prompt-text {
  flex: 1;
  font-size: 0.88rem;
  color: var(--gold-dim);
  font-style: italic;
  padding: 6px 0;
  line-height: 1.6;
  min-width: 0;
}

.timer-section {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.timer-display {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 54px;
  letter-spacing: 0.03em;
}

.timer-display.running { color: var(--gold); }
.timer-display.done    { color: var(--danger); }

.btn-timer {
  padding: 6px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: var(--font);
  transition: border-color 0.2s;
}

.btn-timer:hover { border-color: var(--gold-dim); }

.btn-timer-reset {
  padding: 6px 10px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: color 0.2s;
}

.btn-timer-reset:hover { color: var(--text); }

/* Textarea */
.editor {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.85;
  resize: none;
  outline: none;
  font-family: var(--font);
  transition: border-color 0.2s;
  min-height: 0;
}

.editor:focus { border-color: var(--gold-dim); }
.editor::placeholder { color: var(--text-dim); }

/* Footer */
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}

.count-display {
  font-size: 0.78rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.save-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-status {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.save-status.synced  { color: var(--success); }
.save-status.pending { color: var(--gold-dim); }
.save-status.error   { color: var(--danger); }

.btn-save {
  padding: 8px 22px;
  background: var(--gold);
  border: none;
  color: #15171a;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font);
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.btn-save:hover    { opacity: 0.85; }
.btn-save:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-new {
  padding: 7px 14px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  flex-shrink: 0;
  transition: border-color 0.2s, color 0.2s;
}

.btn-new:hover { border-color: var(--gold-dim); color: var(--text); }

/* ── Right AI panel ──────────────────────────── */
.ai-right-panel {
  width: 0;
  flex-shrink: 0;
  background: #191e2c;
  border-left: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.28s ease, border-color 0.28s ease;
}

.ai-right-panel.open {
  width: 340px;
  border-left: 1px solid #2e3a55;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #1e2538;
  border-bottom: 1px solid #2e3a55;
  flex-shrink: 0;
  gap: 8px;
}

.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #7aabdc;
  white-space: nowrap;
}

.ai-panel-icon { font-size: 1rem; }

.ai-panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-ai-regen {
  padding: 4px 10px;
  background: none;
  border: 1px solid #2e3a55;
  border-radius: 6px;
  color: #7aabdc;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font);
  white-space: nowrap;
  transition: border-color 0.2s, background 0.2s;
}

.btn-ai-regen:hover    { border-color: #7aabdc; background: rgba(122,171,220,0.08); }
.btn-ai-regen:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ai-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.2s;
}

.btn-ai-close:hover { color: var(--text); }

.ai-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-text {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.85;
  white-space: pre-wrap;
  flex: 1;
}

.ai-disclaimer {
  font-size: 0.72rem;
  color: var(--text-dim);
  border-top: 1px solid #2e3a55;
  padding-top: 10px;
  margin-top: auto;
}

/* Loading dots */
.ai-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
}

.ai-loading-text {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.ai-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7aabdc;
  animation: aiPulse 1.2s ease-in-out infinite;
}

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

@keyframes aiPulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%            { opacity: 1;   transform: scale(1); }
}

/* ── AI consultant button ────────────────────── */
.btn-ai {
  padding: 7px 14px;
  background: none;
  border: 1px solid #4a6fa5;
  color: #7aabdc;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.btn-ai:hover    { background: rgba(122, 171, 220, 0.08); border-color: #7aabdc; }
.btn-ai:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── AI panel ────────────────────────────────── */
.ai-panel {
  flex-shrink: 0;
  background: #1a1f2e;
  border: 1px solid #2e3a55;
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 280px;
  display: flex;
  flex-direction: column;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #1e2538;
  border-bottom: 1px solid #2e3a55;
  font-size: 0.82rem;
  color: #7aabdc;
  font-weight: 600;
  flex-shrink: 0;
}

.ai-close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.ai-close-btn:hover { color: var(--text); }

.ai-response {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.ai-text {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.8;
  white-space: pre-wrap;
}

/* Loading dots */
.ai-loading {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 4px 0 12px;
}

.ai-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7aabdc;
  animation: pulse 1.2s ease-in-out infinite;
}

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

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

/* ── User settings modal ─────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.2s;
}

.modal-close:hover { color: var(--text); }

.modal-subtitle {
  padding: 12px 20px 0;
  font-size: 0.82rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.consultant-toggles {
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg3);
  border-radius: 8px;
  border: 1px solid var(--border);
  gap: 12px;
}

.toggle-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.toggle-label { font-size: 0.88rem; color: var(--text); font-weight: 500; }
.toggle-desc  { font-size: 0.75rem; color: var(--text-dim); }

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-track::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-track { background: var(--gold); }
.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(18px);
  background: #15171a;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  text-align: right;
  flex-shrink: 0;
}

.btn-modal-save {
  padding: 9px 24px;
  background: var(--gold);
  border: none;
  color: #15171a;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font);
  transition: opacity 0.2s;
}

.btn-modal-save:hover { opacity: 0.85; }

/* ── Responsive: tablet ──────────────────────── */
@media (max-width: 900px) {
  .ai-right-panel.open {
    width: 300px;
  }
}

@media (max-width: 768px) {
  .app { height: auto; min-height: 100vh; overflow-y: auto; }
  .app-body { flex-direction: column; overflow: visible; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
    gap: 16px;
    overflow: visible;
  }

  .streak-card     { flex: 0 0 auto; min-width: 130px; }
  .ambient-section { flex: 1; min-width: 200px; }
  .entries-section { width: 100%; }

  .editor-area { min-height: 60vh; overflow: visible; }
  .editor      { min-height: 40vh; }

  /* On mobile the AI panel is a full-width bottom sheet */
  .ai-right-panel {
    width: 100% !important;
    border-left: none !important;
    border-top: 1px solid #2e3a55;
    max-height: 0;
    transition: max-height 0.3s ease, border-top-color 0.3s;
  }

  .ai-right-panel.open {
    max-height: 400px;
    width: 100% !important;
  }
}

/* ── Responsive: mobile ──────────────────────── */
@media (max-width: 480px) {
  #user-name { display: none; }
  .editor-area { padding: 14px 16px; }
  .timer-section { margin-left: 0; }
  .editor-toolbar { gap: 8px; }
}
