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

:root {
  --bg: #0f0e17;
  --surface: #1a1a2e;
  --surface2: #232340;
  --accent: #7f5af0;
  --accent-hover: #6b46d6;
  --text: #e0def4;
  --text-muted: #908caa;
  --border: #2e2e4a;
  --success: #3dd68c;
  --danger: #eb6f92;
  --warning: #f6c177;
  --radius: 10px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Login screen */
.login-screen[hidden] { display: none; }
#app[hidden] { display: none; }

.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.login-card {
  text-align: center;
  padding: 3rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 400px;
  width: 90%;
}

.login-card h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, #c4b5fd, #7f5af0, #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 2px;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

#google-signin-btn {
  display: flex;
  justify-content: center;
}

/* Header with user info */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #2d1b69 50%, #1a1a2e 100%);
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

header h1 {
  font-size: 2.2rem;
  background: linear-gradient(135deg, #c4b5fd, #7f5af0, #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 2px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.3rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
}

#user-name {
  color: var(--text-muted);
  font-size: 0.85rem;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Search */
.search-bar {
  margin-bottom: 1.5rem;
}

.search-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.search-row input[type="text"] {
  flex: 1;
}

.tag-search-input {
  max-width: 200px;
}

.search-bar input[type="text"] {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
}

.empty-tags {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(127, 90, 240, 0.15);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.tag-cloud {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 200px;
}

.tag-cloud .tag {
  cursor: pointer;
  transition: all 0.15s;
}

.tag-cloud .tag:hover, .tag-cloud .tag.active {
  background: var(--accent);
  color: white;
}

select {
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
}

.lucid-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.panel h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Form */
label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  margin-top: 0.8rem;
}

label:first-of-type { margin-top: 0; }

input[type="text"], input[type="date"], textarea, .form-panel select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(127, 90, 240, 0.15);
}

textarea { resize: vertical; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  margin-top: 1rem;
  color: var(--text);
  font-size: 0.9rem;
}

/* Buttons */
.btn {
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
  width: 100%;
  margin-top: 1.2rem;
  padding: 0.75rem;
  font-size: 0.95rem;
}

.btn-primary:hover { background: var(--accent-hover); }

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

.btn-analyze {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

.btn-analyze:hover {
  background: var(--accent);
  color: white;
}

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
  font-size: 0.8rem;
}

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

/* Dream list */
.dream-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 70vh;
  overflow-y: auto;
}

.dream-list::-webkit-scrollbar { width: 6px; }
.dream-list::-webkit-scrollbar-track { background: transparent; }
.dream-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.dream-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}

.dream-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.dream-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.4rem;
}

.dream-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.dream-card .date {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.dream-card .preview {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dream-card .card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
}

.dream-card .tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: rgba(127, 90, 240, 0.15);
  color: #a78bfa;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 500;
}

.mood-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  background: rgba(246, 193, 119, 0.15);
  color: var(--warning);
}

.lucid-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  background: rgba(61, 214, 140, 0.15);
  color: var(--success);
}

.analyzed-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  margin-left: 0.3rem;
  title: "AI Analyzed";
}

.count-badge {
  font-size: 0.75rem;
  background: var(--surface2);
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  color: var(--text-muted);
  font-weight: 400;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
  font-style: italic;
}

/* Modal */
.modal[hidden] {
  display: none;
}

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

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 700px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

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

#modal-body h2 {
  margin-bottom: 0.5rem;
}

#modal-body .meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

#modal-body .dream-text {
  background: var(--surface2);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  white-space: pre-wrap;
  line-height: 1.7;
}

.analysis-section {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.analysis-section h3 {
  color: var(--accent);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.analysis-content {
  font-size: 0.9rem;
  line-height: 1.8;
}

.analysis-content strong {
  color: #c4b5fd;
}

.analysis-content p {
  margin-bottom: 0.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 0.4rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Markdown-like rendering in analysis */
.analysis-content ul, .analysis-content ol {
  margin-left: 1.2rem;
  margin-bottom: 0.5rem;
}

.analysis-content li {
  margin-bottom: 0.25rem;
}
