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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
}

/* Auth Screen */
.auth-card {
  max-width: 400px;
  margin: 80px auto;
  background: #16213e;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.auth-card h1 {
  color: #e94560;
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.auth-card .subtitle {
  color: #888;
  margin-bottom: 24px;
}

.auth-card h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: #ccc;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input[type="text"],
input[type="password"] {
  padding: 10px 14px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #0f3460;
  color: #e0e0e0;
  font-size: 1rem;
}

input:focus {
  outline: none;
  border-color: #e94560;
}

button {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  background: #e94560;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover {
  background: #c73e54;
}

button:disabled {
  background: #555;
  cursor: not-allowed;
}

.error {
  color: #ff6b6b;
  margin-top: 12px;
  font-size: 0.9rem;
}

/* Dashboard */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #16213e;
  border-bottom: 2px solid #e94560;
}

header h1 {
  color: #e94560;
  font-size: 1.4rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#admin-name {
  color: #aaa;
}

#logout-btn {
  background: transparent;
  border: 1px solid #e94560;
  color: #e94560;
  padding: 6px 14px;
  font-size: 0.85rem;
}

#logout-btn:hover {
  background: #e94560;
  color: #fff;
}

main {
  max-width: 1000px;
  margin: 24px auto;
  padding: 0 24px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.controls label {
  font-weight: 600;
}

select {
  padding: 8px 12px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #0f3460;
  color: #e0e0e0;
  font-size: 1rem;
}

select:focus {
  outline: none;
  border-color: #e94560;
}

#impersonate-btn {
  background: #0f3460;
  border: 2px solid #45b7d1;
  color: #45b7d1;
}

#impersonate-btn:hover:not(:disabled) {
  background: #45b7d1;
  color: #1a1a2e;
}

#analyze-btn {
  margin-left: auto;
}

/* Table */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #16213e;
  border-radius: 8px;
  overflow: hidden;
}

thead {
  background: #0f3460;
}

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: #e94560;
  cursor: pointer;
  user-select: none;
}

th[data-sort]:hover {
  color: #ff6b8a;
}

td {
  padding: 10px 16px;
  border-top: 1px solid #1a1a2e;
}

tbody tr:hover {
  background: #1a2745;
}

.category-food { color: #4ecdc4; }
.category-activity { color: #45b7d1; }
.category-medication { color: #f9ca24; }
.category-symptom { color: #ff6b6b; }

/* Analysis */
#analysis-section {
  margin-top: 32px;
}

#analysis-section h2 {
  margin-bottom: 16px;
}

#analysis-loading {
  color: #aaa;
  font-style: italic;
}

#plot-container {
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

#plot-image {
  max-width: 100%;
  height: auto;
}

/* Summary Stats */
.summary-stats-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid #333;
}

.summary-stats-section h2 {
  margin-bottom: 16px;
}

.summary-stats-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

#create-summary-btn {
  background: #0f3460;
  border: 2px solid #e94560;
  color: #e94560;
}

#create-summary-btn:hover {
  background: #e94560;
  color: #fff;
}

#show-summary-btn {
  background: #0f3460;
  border: 2px solid #4ecdc4;
  color: #4ecdc4;
}

#show-summary-btn:hover {
  background: #4ecdc4;
  color: #1a1a2e;
}

.summary-status {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  background: #0f3460;
  color: #aaa;
  font-style: italic;
}

.summary-status.success {
  color: #4ecdc4;
  font-style: normal;
}

.summary-status.error {
  color: #ff6b6b;
  font-style: normal;
}

.summary-meta {
  color: #888;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.desc-cell {
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#no-summary {
  color: #888;
  font-style: italic;
  padding: 16px 0;
}

/* --- Export Personas --- */

.export-personas-section {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  margin-bottom: 24px;
}

.export-personas-section .section-desc {
  color: #555;
  font-size: 0.9rem;
  margin: 8px 0 16px;
  line-height: 1.5;
}

.export-personas-section .section-desc code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

.export-personas-controls {
  margin-bottom: 16px;
}

.export-file-list {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
}

.export-file-list li {
  font-family: monospace;
  font-size: 0.85rem;
  color: #333;
  padding: 3px 0;
}

/* --- Advanced Analysis --- */

.advanced-analysis-section {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  margin-bottom: 24px;
}

.advanced-analysis-section h2 {
  font-size: 1.15rem;
  color: #1a1a2e;
  margin-bottom: 6px;
}

.advanced-analysis-section .section-desc {
  color: #555;
  font-size: 0.9rem;
  margin: 0 0 20px;
  line-height: 1.5;
}

.advanced-analysis-section .section-desc code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

.adv-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.adv-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.adv-row label {
  width: 160px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #333;
  flex-shrink: 0;
}

.adv-row select,
.adv-row input[type="date"] {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #f8f9ff;
  color: #222;
  font-size: 0.9rem;
}

.adv-row-dates input[type="date"] {
  flex: 0 0 auto;
  width: 155px;
}

.adv-date-sep {
  color: #888;
  font-size: 0.85rem;
}

.adv-controls {
  margin-top: 4px;
  padding-left: 172px;
}

.adv-controls button {
  background: #1a1a2e;
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.adv-controls button:hover:not(:disabled) {
  background: #e94560;
}

.adv-controls button:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.advanced-analysis-section .summary-status {
  color: #555;
  background: #f5f5f5;
}

.advanced-analysis-section .summary-status.success { color: #2e7d32; }
.advanced-analysis-section .summary-status.error   { color: #c62828; }

.export-log {
  background: #1e1e1e;
  color: #d4d4d4;
  font-size: 0.78rem;
  line-height: 1.6;
  padding: 14px 16px;
  border-radius: 6px;
  margin-top: 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

/* --- Advanced Analysis Results --- */

.adv-results {
  margin-top: 24px;
  border-top: 1px solid #2a2a4a;
  padding-top: 20px;
}

.chart-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.chart-tab-btn {
  padding: 6px 14px;
  font-size: 0.82rem;
  background: #0f3460;
  border-radius: 4px;
  color: #bbb;
}

.chart-tab-btn:hover { background: #1a4a80; color: #e0e0e0; }
.chart-tab-btn.active { background: #e94560; color: #fff; }

.chart-panel {
  background: #16213e;
  border-radius: 8px;
  padding: 16px;
  min-height: 300px;
}

.chart-note {
  color: #888;
  font-size: 0.78rem;
  margin-bottom: 10px;
  font-style: italic;
}

.multi-chart-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.sub-chart-wrapper {
  background: #0f3460;
  border-radius: 6px;
  padding: 12px;
}

.sub-chart-wrapper h4 {
  color: #e94560;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.factor-finding {
  color: #aaa;
  font-size: 0.78rem;
  font-style: italic;
  margin-bottom: 8px;
}

.factor-note {
  color: #777;
  font-size: 0.74rem;
  margin-top: 8px;
}

.heatmap-scroll {
  overflow-x: auto;
}

.heatmap-scroll canvas {
  display: block;
}

/* --- Analysis Progress Tracker --- */

.adv-progress {
  margin: 16px 0 10px;
  background: #16213e;
  border-radius: 8px;
  padding: 16px 20px 14px;
}

.progress-stages {
  display: flex;
  align-items: flex-start;
  margin-bottom: 14px;
}

.stage-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 72px;
}

.stage-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #444;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
}

.stage-label {
  font-size: 0.7rem;
  color: #555;
  white-space: nowrap;
  text-align: center;
  transition: color 0.25s;
}

.stage-connector {
  flex: 1;
  height: 2px;
  background: #333;
  margin-top: 11px; /* vertically centres with dot */
  transition: background 0.3s;
}

/* pending — default, already handled by base styles */

/* active — orange pulse */
.stage-active .stage-dot {
  border-color: #ffb74d;
  background: rgba(255,183,77,0.15);
  box-shadow: 0 0 8px rgba(255,183,77,0.5);
  animation: stage-pulse 1.3s ease-in-out infinite;
}
.stage-active .stage-label { color: #ffb74d; }

/* done — green check */
.stage-done .stage-dot {
  border-color: #81c784;
  background: #81c784;
  color: #1a1a2e;
}
.stage-done .stage-dot::after { content: '✓'; }
.stage-done .stage-label { color: #81c784; }

/* error — red X */
.stage-error .stage-dot {
  border-color: #e94560;
  background: #e94560;
  color: #fff;
}
.stage-error .stage-dot::after { content: '✕'; }
.stage-error .stage-label { color: #e94560; }

/* Connector fills green when both adjacent stages are done */
.stage-done + .stage-connector { background: #81c784; }

@keyframes stage-pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(255,183,77,0.4); }
  50%       { box-shadow: 0 0 14px rgba(255,183,77,0.75); }
}

.adv-timer-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.timer-label {
  color: #666;
  font-size: 0.8rem;
}

.timer-value {
  color: #ffb74d;
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.stage-detail {
  color: #888;
  font-size: 0.76rem;
  font-style: italic;
  min-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.chart-panel-3d {
  min-height: 480px;
  padding: 8px;
}

/* Persona-export staleness banner */
.adv-staleness {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 2px 0 4px;
  margin-left: 172px;
}

.adv-staleness.stale-warn {
  background: #fff4e0;
  color: #7a4a00;
  border: 1px solid #f4c07a;
}

.adv-staleness.stale-missing {
  background: #fde4e4;
  color: #7a1a1a;
  border: 1px solid #e08a8a;
}

.adv-staleness.stale-ok {
  background: #e7f5ea;
  color: #1f5a33;
  border: 1px solid #9ad3ac;
}

/* Octave invocation disclosure */
.adv-command-box {
  background: #0f3460;
  border: 1px solid #1e3a6a;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 10px 0 12px;
  font-size: 0.82rem;
}

.adv-command-box > summary {
  cursor: pointer;
  color: #ffb74d;
  font-weight: 600;
  user-select: none;
  list-style: revert;
}

.adv-command-box[open] > summary {
  margin-bottom: 10px;
}

.adv-command-section {
  position: relative;
  margin-top: 8px;
}

.adv-command-label {
  color: #8aa;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.adv-command-pre {
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: 'Consolas', 'Menlo', 'Courier New', monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 10px 12px 10px 12px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
  margin: 0;
}

.adv-command-copy {
  position: absolute;
  top: 22px;
  right: 6px;
  background: #4a4a4a;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.72rem;
  cursor: pointer;
}

.adv-command-copy:hover {
  background: #666;
}

/* Data range info banner */
.data-range-info {
  background: #0f3460;
  border: 1px solid #1e3a6a;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.data-range-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px 18px;
}

.dr-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dr-label {
  color: #8aa;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.dr-value {
  color: #e0e0e0;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.dr-span {
  color: #888;
  font-size: 0.78rem;
}

.dr-user {
  color: #ffb74d;
  font-weight: 600;
}

.plotly-3d {
  width: 100%;
  height: 460px;
}
