/* Analytics base */
.analytics-hero { display: grid; gap: 18px; }
.analytics-focus {
  display: grid;
  gap: 18px;
  align-items: center;
  padding: 18px;
  border-radius: var(--r);
  background: linear-gradient(135deg,color-mix(in srgb,var(--cat) 10%,transparent),transparent);
  border: 1px solid color-mix(in srgb,var(--cat) 28%,var(--border));
}
.analytics-focus h1 { font-size: 26px; line-height: 1.1; letter-spacing: 0; }
.focus-title { margin: 8px 0 4px; font-size: 18px; font-weight: 750; color: var(--cat); }
.focus-copy { margin: 0; max-width: 680px; color: var(--text2); }
.focus-meter {
  display: grid;
  gap: 2px;
  justify-items: start;
  padding: 14px;
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.focus-meter span { color: var(--text3); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.focus-meter strong { color: var(--text); font-size: 24px; font-variant-numeric: tabular-nums; }
.focus-meter small { color: var(--text2); }
.analytics-kpis { display: grid; gap: 8px; }
.analytics-kpis span {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb,var(--text) 4%,transparent);
}
.analytics-kpis strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.analytics-kpis small { color: var(--text3); }
.insight-grid { display: grid; gap: 10px; }
.insight-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb,var(--text) 4%,transparent);
  border-left: 3px solid var(--cat);
}
.insight-card--warn { background: color-mix(in srgb,#f59e0b 8%,transparent); border-left-color: #f59e0b; }
.insight-card--alert { background: color-mix(in srgb,#ef4444 10%,transparent); border-left-color: #ef4444; }
.insight-card--warn .insight-status,
.insight-card--alert .insight-status { color: inherit; }
.insight-card p { margin: 0; color: var(--text2); }
.insight-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.insight-top .cat-dot { background: var(--cat); }
.insight-top h2 { min-width: 0; flex: 1; font-size: 16px; font-weight: 750; overflow-wrap: anywhere; }
.insight-status {
  color: var(--cat);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  white-space: nowrap;
}
.insight-role { font-weight: 700; color: var(--text) !important; }
.muted { color: var(--text3) !important; }
.insight-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
.insight-metrics span {
  display: grid;
  gap: 1px;
  padding: 8px;
  border-radius: var(--r-xs);
  background: var(--surface);
}
.insight-metrics strong { font-variant-numeric: tabular-nums; }
.insight-metrics small { color: var(--text3); font-size: 11px; }
.analytics-lab { display: grid; gap: 28px; }
.analytics-lab ul { margin: 0 0 16px; padding-left: 18px; color: var(--text2); font-size: .85rem; line-height: 1.6; }
.analytics-lab li + li { margin-top: 6px; }

.context-forms { display: flex; flex-direction: column; gap: 24px; }
.context-block { border-left: 3px solid var(--cat, var(--accent)); padding-left: 14px; }
.context-title { font-size: 1rem; font-weight: 600; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.context-block--collapsed .context-title { margin-bottom: 0; }
.context-summary { display: none; font-weight: 400; font-size: .8125rem; color: var(--text2); margin-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.context-block--collapsed .context-summary { display: inline !important; }
.context-form { display: flex; flex-direction: column; gap: 10px; }
.context-form textarea.control-input { resize: none; overflow: hidden; min-height: 2rem; }
.context-form .form-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.context-form-actions { display: flex; align-items: center; gap: 10px; }
.btn-collapse { background: none; border: none; cursor: pointer; padding: 2px 4px; color: var(--text2); line-height: 1; margin-left: auto; border-radius: 4px; transition: color .15s, background .15s; }
.btn-collapse:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.btn-collapse svg { display: block; transition: transform .2s; }
.btn-collapse[data-open="1"] svg { transform: rotate(180deg); }
.context-block--collapsed .context-form,
.context-block--collapsed .profile-history { display: none; }

.profile-status { font-size: .75rem; color: var(--text2); transition: color .15s; }
.profile-status--ok  { color: #16a34a; }
.profile-status--saving { color: var(--accent); }
.profile-status--err { color: #dc2626; }

.profile-history { margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--bg); }
.profile-history-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: .8125rem; font-weight: 600; color: var(--text2); }
.profile-history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; background: color-mix(in srgb, var(--surface) 80%, var(--bg)); }
.history-meta  { font-size: .75rem; color: var(--text2); white-space: nowrap; min-width: 70px; }
.history-preview { flex: 1; font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-ghost-sm { font-size: .75rem; padding: 3px 8px; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn-ghost-sm:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: var(--accent); }
.btn-ghost-sm.ai-refresh-due { position: relative; overflow: hidden; border-color: color-mix(in srgb,#14b8a6 48%,var(--border)); background: linear-gradient(110deg,transparent 0%,color-mix(in srgb,#14b8a6 13%,transparent) 38%,color-mix(in srgb,#f59e0b 16%,transparent) 50%,color-mix(in srgb,#14b8a6 13%,transparent) 62%,transparent 100%); background-size: 240% 100%; box-shadow: 0 0 0 1px color-mix(in srgb,#14b8a6 10%,transparent); animation: ai-refresh-sheen 3.8s var(--ease) infinite; }
.btn-ghost-sm.ai-refresh-due::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 3px; height: 1px; background: linear-gradient(90deg,transparent,#14b8a6,#f59e0b,transparent); opacity: .65; animation: ai-refresh-line 3.8s var(--ease) infinite; }
.btn-ghost-sm.ai-refresh-due:disabled { animation: none; }
.btn-ghost-sm.ai-generating {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  animation: ai-generating-pulse 1.4s var(--ease) infinite;
}
@keyframes ai-refresh-sheen { 0%, 35% { background-position: 125% 0; } 100% { background-position: -125% 0; } }
@keyframes ai-refresh-line { 0%, 28% { transform: translateX(-12%); opacity: .25; } 55% { opacity: .85; } 100% { transform: translateX(12%); opacity: .25; } }
@keyframes ai-generating-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.ai-main-rec { padding: 14px 16px; background: color-mix(in srgb, var(--cat, var(--accent)) 10%, var(--bg)); border-left: 3px solid var(--cat, var(--accent)); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.ai-main-rec .section-label { margin-bottom: 6px; }
.ai-main-rec-text { margin: 0; font-size: .9375rem; line-height: 1.55; color: var(--text); }
.ai-wellness-block { display: flex; align-items: flex-start; gap: 10px; margin-top: 10px; padding: 10px 14px; background: color-mix(in srgb, #22c55e 8%, var(--bg)); border-left: 3px solid #22c55e; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.ai-wellness-icon { font-size: 1.1rem; flex-shrink: 0; line-height: 1.5; }
.ai-wellness-body { flex: 1; min-width: 0; }
.ai-wellness-text { margin: 0; font-size: .875rem; line-height: 1.5; color: var(--text2); }
.wellness-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.wellness-option { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-pill); border: 1px solid color-mix(in srgb, #22c55e 40%, var(--border)); background: color-mix(in srgb, #22c55e 5%, var(--surface)); cursor: pointer; font-size: .8125rem; color: var(--text2); transition: background .15s, border-color .15s; user-select: none; }
.wellness-option:hover { background: color-mix(in srgb, #22c55e 12%, var(--surface)); border-color: #22c55e; }
.wellness-option--done { background: color-mix(in srgb, #22c55e 14%, var(--surface)); border-color: #22c55e; color: var(--text3); }
.wellness-option--done .wellness-option-label { text-decoration: line-through; }
.wellness-option-time { font-size: .75rem; color: #22c55e; font-variant-numeric: tabular-nums; margin-left: 2px; }
.wellness-delete-btn { width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--text3); font-size: 14px; line-height: 1; cursor: pointer; }
.wellness-delete-btn:hover { background: color-mix(in srgb,#ef4444 12%,transparent); color: #ef4444; }
.wellness-add-custom { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.wellness-custom-input { flex: 1; min-width: 0; padding: 4px 10px; border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .8125rem; outline: none; transition: border-color .15s; }
.wellness-custom-input:focus { border-color: #22c55e; box-shadow: 0 0 0 2px color-mix(in srgb,#22c55e 15%,transparent); }
.wellness-custom-input::placeholder { color: var(--text3); }
.wellness-custom-btn { flex-shrink: 0; width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 1px solid #22c55e; background: transparent; color: #22c55e; font-size: 1.1rem; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background .15s; }
.wellness-custom-btn:hover { background: color-mix(in srgb,#22c55e 12%,transparent); }

.insight-rec { margin: 0; font-size: .85rem; line-height: 1.5; color: var(--text); }
.ai-chat-section { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.chat-messages { flex: 1; min-height: 160px; max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); }
.chat-messages:empty::before { content: 'Ask about analytics or request advice'; display: block; color: var(--text3); font-size: .82rem; text-align: center; margin: auto; padding: 20px 0; }
.chat-msg { padding: 8px 12px; border-radius: var(--r-sm); }
.chat-msg p { margin: 0; white-space: pre-wrap; font-size: .85rem; line-height: 1.55; }
.chat-msg--user { background: var(--accent); color: #fff; align-self: flex-end; max-width: 85%; }
.chat-msg--assistant { background: color-mix(in srgb, var(--text) 5%, transparent); align-self: flex-start; color: var(--text); }
.chat-msg--assistant p { color: var(--text); }
.chat-typing { opacity: .5; }
.chat-input-row { display: flex; gap: 8px; align-items: flex-end; margin-top: 4px; }
.chat-input-row textarea { flex: 1; resize: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px; font-family: inherit; font-size: .9rem; line-height: 1.45; min-height: 38px; }
.chat-input-row textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb,var(--accent) 15%,transparent); }
.chat-send-btn { flex-shrink: 0; width: 36px; height: 36px; padding: 0; display: flex; align-items: center; justify-content: center; }

.ai-suggest-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
.ai-suggest-row textarea { flex: 1; min-height: 44px; resize: vertical; }
.ai-suggest-row .btn-sm { flex-shrink: 0; white-space: nowrap; padding: 6px 14px; }
.ai-suggest-result { margin-top: 12px; padding: 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--border); }
.ai-suggest-result .sug-verdict { font-weight: 600; margin-bottom: 6px; }
.ai-suggest-result .sug-reason { font-size: .82rem; color: var(--text2); margin-bottom: 10px; }
.ai-suggest-result .sug-create-btn { margin-top: 8px; }
.ai-suggest-result--loading { opacity: .6; pointer-events: none; }
.ai-suggest-result .sug-fields { font-size: .8rem; color: var(--text2); }
.ai-suggest-result .sug-fields strong { color: var(--text); }

/* Analytics screen refinements */
.analytics-lab {
  display: block;
  align-items: stretch;
}

.ai-chat-section {
  min-height: 440px;
}

.chat-messages {
  min-height: 290px;
  max-height: 560px;
}

.chat-msg {
  max-width: 88%;
}

.chat-msg--assistant {
  max-width: 92%;
}

.chat-msg--system {
  align-self: center;
  background: transparent;
  color: var(--text3);
  padding: 0;
}

.chat-msg--system p {
  font-size: .78rem;
  line-height: 1.4;
}

.chat-streaming p::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -2px;
  background: currentColor;
  animation: chat-caret 1s steps(1) infinite;
}

.chat-typing {
  opacity: 1;
}

.chat-typing p {
  display: inline-flex;
  gap: 4px;
  min-height: 1.2rem;
}

.chat-typing p::before,
.chat-typing p::after,
.chat-typing span {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .45;
  animation: chat-dot 1.2s infinite;
}

.chat-typing span {
  animation-delay: .2s;
}

.chat-typing p::after {
  animation-delay: .4s;
}

.ai-suggest-panel {
  margin: 0 0 22px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--text) 3%, transparent);
}

.ai-suggest-panel .section-label {
  margin-bottom: 10px;
}

.ai-suggest-row {
  margin-bottom: 0;
}

.ai-suggest-input {
  min-height: 42px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: 0;
  box-shadow: none;
}

.ai-suggest-input::placeholder {
  color: var(--text3);
  font-weight: 500;
}

@keyframes chat-caret {
  0%, 45% { opacity: .7; }
  46%, 100% { opacity: 0; }
}

@keyframes chat-dot {
  0%, 70%, 100% { transform: translateY(0); opacity: .35; }
  35% { transform: translateY(-4px); opacity: .9; }
}

@media (max-width: 900px) {
  .ai-chat-section {
    min-height: 360px;
  }
}
