:root {
  --bg: #070a14;
  --surface: #0d1322;
  --surface-2: #141d33;
  --border: rgba(255, 255, 255, 0.08);
  --border-hi: rgba(139, 92, 246, 0.35);
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --violet: #8b5cf6;
  --violet-soft: rgba(139, 92, 246, 0.16);
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.14);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.08), transparent 45%), var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.login-brand h1 { margin: 0; font-size: 20px; font-weight: 800; }
.login-brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.alert-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--red-soft);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  font-size: 13px;
  margin-bottom: 14px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(7, 10, 20, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { display: block; border-radius: 9px; flex-shrink: 0; }
.brand-text { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-title { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid rgba(16, 185, 129, 0.28);
  white-space: nowrap;
}
.status-pill .dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.status-pill.busy {
  background: var(--violet-soft);
  color: #c4b5fd;
  border-color: rgba(139, 92, 246, 0.35);
}
.status-pill.busy .dot { animation: pulse 1.1s infinite; }
.status-pill.warn {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.35);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* Container & Cards */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-header > div { min-width: 0; }
.card-title { margin: 0; font-size: 15.5px; font-weight: 700; }
.card-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--border-hi); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #0891b2);
  border-color: transparent;
  color: #fff;
}
.btn-ghost { background: rgba(255, 255, 255, 0.03); }
.btn-danger { background: var(--red-soft); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 7px 10px; }
.btn-full { width: 100%; }
.upload-label { user-select: none; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
  width: 100%;
  background: #090e1a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  padding: 9px 11px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--violet); }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.highlight-card {
  background: linear-gradient(145deg, rgba(139, 92, 246, 0.14), var(--surface));
  border-color: rgba(139, 92, 246, 0.28);
}
.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
  min-width: 0;
}
.kpi-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}
.kpi-value { font-size: 25px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.kpi-value-sm {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.violet-text { color: #c4b5fd; }
.cyan-text { color: var(--cyan); }
.green-text { color: var(--green); }

/* Tabs */
.tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.tab-btn.active {
  background: var(--violet-soft);
  border-color: rgba(139, 92, 246, 0.35);
  color: #e9d5ff;
}

/* Toolbar & Filters */
.toolbar { margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.toolbar-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; }
.toolbar-actions { display: flex; gap: 8px; }
.filter-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.seg-group {
  display: inline-flex;
  background: #090e1a;
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  gap: 2px;
}
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.seg-btn.active { background: var(--violet-soft); color: #ede9fe; }
.toggle-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }

/* Dreams List */
.dreams-list { display: flex; flex-direction: column; gap: 10px; }
.dream-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.dream-card:hover { border-color: var(--border-hi); }
.dream-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.dream-card-main { min-width: 0; flex: 1; }
.dream-meta { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px 8px; flex-wrap: wrap; }
.dream-title { margin: 5px 0 0; font-size: 15.5px; font-weight: 700; line-height: 1.3; color: var(--text); word-break: break-word; }
.dream-summary { margin: 6px 0 10px; font-size: 13.5px; color: #cbd5e1; }
.dream-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  max-width: 100%;
}
.pill-lucid-0 { background: rgba(148, 163, 184, 0.12); color: #94a3b8; }
.pill-lucid-1 { background: var(--amber-soft); color: #fcd34d; }
.pill-lucid-2 { background: var(--cyan-soft); color: var(--cyan); }
.pill-lucid-3, .pill-lucid-4 { background: var(--green-soft); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.3); }
.pill-pending { background: var(--violet-soft); color: #c4b5fd; }
.pill-error { background: var(--red-soft); color: #fca5a5; }
.pill-mood { background: rgba(255, 255, 255, 0.05); color: var(--text-dim); }
.chip-sign {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(34, 211, 238, 0.09);
  border: 1px solid rgba(34, 211, 238, 0.22);
  color: #a5f3fc;
  max-width: 100%;
  white-space: normal;
  line-height: 1.3;
}
.fav-star {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.fav-star.active { color: #fbbf24; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Lucid Lab */
.lab-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.lab-grid > * { min-width: 0; }
.coach-card { grid-column: 1 / -1; }
.chart-wrap { position: relative; height: 240px; }
.chart-wrap-sm { height: 220px; }
.signs-ranking { display: flex; flex-direction: column; gap: 10px; }
.sign-rank-row { display: flex; flex-direction: column; gap: 5px; }
.sign-rank-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}
.sign-rank-count { white-space: nowrap; flex-shrink: 0; color: var(--text-dim); font-size: 12px; }
.sign-rank-bar { height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.sign-rank-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--violet), var(--cyan)); }

.entities-wrap { display: flex; flex-direction: column; gap: 12px; }
.entity-group-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 6px; font-weight: 700; }
.entity-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.entity-chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.coach-content { display: flex; flex-direction: column; gap: 12px; }
.coach-headline { font-size: 15px; font-weight: 700; color: #e9d5ff; margin: 0; }
.coach-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.coach-grid > * { min-width: 0; }
.coach-box {
  background: #090e1a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.coach-box h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--cyan); text-transform: uppercase; letter-spacing: 0.04em; }
.coach-box p, .coach-box li { font-size: 13px; color: #cbd5e1; margin: 0; }
.coach-box ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(3, 5, 12, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.65);
}
.modal-card-sm { max-width: 460px; }
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head > div { min-width: 0; flex: 1; }
.modal-head h2 { margin: 2px 0 0; font-size: 17px; font-weight: 800; line-height: 1.25; word-break: break-word; }
.modal-date { font-size: 12px; color: var(--text-dim); }
.modal-head-actions { display: flex; gap: 6px; flex-shrink: 0; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }

.audio-box { background: #090e1a; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; }
.audio-box audio { width: 100%; height: 38px; }
.audio-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.detail-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-section h3 { margin: 0 0 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); }
.detail-section p { margin: 0; color: #e2e8f0; }

.signs-detail-list { display: flex; flex-direction: column; gap: 7px; }
.sign-detail-item {
  background: #090e1a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
}
.sign-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
}
.sign-detail-head .pill { flex-shrink: 0; }
.sign-detail-why { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }

.mild-box {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.16), rgba(34, 211, 238, 0.09));
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-weight: 600;
  color: #f3e8ff;
}
.trigger-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; color: #cbd5e1; }
.transcript-box {
  background: #090e1a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  white-space: pre-wrap;
  line-height: 1.55;
  color: #e2e8f0;
}

.edit-drawer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.edit-drawer summary { cursor: pointer; font-weight: 700; font-size: 13px; color: var(--cyan); }
.edit-form { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.edit-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.edit-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.alert-banner {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
  font-size: 13px;
}

/* Mic Modal */
.mic-modal-body { align-items: center; text-align: center; padding: 24px 18px; }
.mic-orb {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--violet-soft);
  border: 2px solid rgba(139, 92, 246, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ddd6fe;
}
.mic-orb.recording {
  background: var(--red-soft);
  border-color: var(--red);
  color: #fecaca;
  animation: pulse 1s infinite;
}
.mic-timer { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.mic-hint { color: var(--text-dim); margin: 0; font-size: 13px; }
.mic-buttons { display: flex; gap: 10px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  background: #141d33;
  border: 1px solid var(--border-hi);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.toast[hidden] { display: none; }

@media (max-width: 860px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lab-grid, .coach-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .topbar-inner { padding: 10px 12px; gap: 8px; }
  .container { padding: 12px; }
  .kpi-grid { gap: 10px; }
  .kpi-card { padding: 12px; }
  .toolbar-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .seg-group { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .seg-btn { text-align: center; padding: 6px 4px; }
  .card-header { flex-wrap: wrap; }
  .hide-sm { display: none; }
  .edit-row-2 { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
  .kpi-value-sm { font-size: 13.5px; }
}
