/* ── HEIM ASSISTANT (floating button + chat drawer) ─────────────────────── */

.assistant-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 190;
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.12);
  background: linear-gradient(135deg, #4f8cff 0%, #7c5cff 100%);
  color: #fff; font-size: 1.35rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 30px rgba(79,140,255,0.35), 0 2px 6px rgba(0,0,0,0.4);
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s;
}
.assistant-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 36px rgba(79,140,255,0.45), 0 2px 6px rgba(0,0,0,0.4); }
.assistant-fab:active { transform: scale(0.95); }
.assistant-fab.is-open { opacity: 0; pointer-events: none; }
.assistant-fab-icon { line-height: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3)); }
.assistant-fab-badge {
  position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--amber); border: 2px solid var(--bg);
  animation: assistantPulse 1.4s ease-in-out infinite;
}
@keyframes assistantPulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.25); opacity: 0.7; } }

.assistant-backdrop {
  position: fixed; inset: 0; z-index: 210;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.18s ease;
}

.assistant-drawer {
  position: fixed; z-index: 211;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 100vw);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--surface) 0%, #0d0d15 100%);
  border-left: 1px solid var(--border-mid);
  box-shadow: -16px 0 48px rgba(0,0,0,0.55);
  animation: assistantSlideIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes assistantSlideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.assistant-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.assistant-header-icon {
  width: 36px; height: 36px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f8cff 0%, #7c5cff 100%);
  color: #fff; font-size: 1rem;
  box-shadow: 0 4px 14px rgba(79,140,255,0.35);
}
.assistant-header-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.assistant-title { font-size: 0.95rem; font-weight: 800; letter-spacing: -0.2px; }
.assistant-subtitle { font-size: 0.7rem; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.assistant-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px var(--green-dim); }
.assistant-dot.warn { background: var(--amber); box-shadow: 0 0 0 2px var(--amber-dim); }
.assistant-dot.pulsing { background: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); animation: assistantPulse 1s ease-in-out infinite; }
.assistant-dot.rec { background: #ef4444; box-shadow: 0 0 0 2px rgba(239,68,68,0.25); animation: assistantPulse 1s ease-in-out infinite; }

/* Header action: «Oppsummering» (icon-only on phones) */
.assistant-briefing {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; flex-shrink: 0;
  border-radius: 999px; background: var(--surface3); border: 1px solid var(--border-mid);
  color: var(--text); font-size: 0.72rem; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
.assistant-briefing:hover:not(:disabled) { background: var(--surface4); border-color: var(--accent); transform: translateY(-1px); }
.assistant-briefing:disabled { opacity: 0.4; cursor: default; }
.assistant-briefing-icon { font-size: 0.85rem; line-height: 1; }

.assistant-close, .assistant-reset {
  background: var(--surface3); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 50%; width: 32px; height: 32px;
  font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.12s; flex-shrink: 0;
}
.assistant-close:hover, .assistant-reset:hover:not(:disabled) { background: var(--surface4); color: var(--text); transform: scale(1.08); }
.assistant-reset:disabled { opacity: 0.4; cursor: default; }

.assistant-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }

/* Empty state */
.assistant-empty {
  margin: auto; padding: 28px 24px; text-align: center; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.assistant-empty p { font-size: 0.9rem; }
.assistant-empty-icon { font-size: 2rem; opacity: 0.6; }
.assistant-empty-hint { font-size: 0.75rem; color: var(--text-dim); line-height: 1.5; }
.assistant-empty-hint code { color: var(--text-muted); background: var(--surface3); padding: 1px 5px; border-radius: 4px; }
.assistant-suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.assistant-chip {
  background: var(--surface3); border: 1px solid var(--border-mid); color: var(--text);
  font-size: 0.78rem; font-weight: 600; padding: 8px 12px; border-radius: 999px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.assistant-chip:hover { background: var(--surface4); border-color: var(--accent); transform: translateY(-1px); }
.assistant-chip { max-width: 100%; text-align: left; line-height: 1.3; }

/* Typing indicator (model working) — first child of the column-reverse timeline = bottom */
.assistant-typing {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 5px;
  padding: 13px 14px; border-radius: 16px; border-bottom-left-radius: 6px;
  background: var(--surface3); border: 1px solid var(--border);
}
.assistant-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
  animation: assistantTyping 1.2s ease-in-out infinite;
}
.assistant-typing span:nth-child(2) { animation-delay: 0.15s; }
.assistant-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes assistantTyping { 0%, 80%, 100% { transform: translateY(0); opacity: 0.35; } 40% { transform: translateY(-4px); opacity: 1; } }

/* Timeline */
.assistant-timeline {
  display: flex; flex-direction: column-reverse; gap: 10px;
  padding: 16px 16px 8px; margin-top: auto;
}
.assistant-msg {
  position: relative;
  max-width: 88%; padding: 10px 14px; border-radius: 16px;
  font-size: 0.88rem; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere;
}
/* Timestamp on hover (data-time="HH:mm") */
.assistant-msg[data-time]:hover::after {
  content: attr(data-time); position: absolute; bottom: -15px; font-size: 0.62rem; font-weight: 600;
  color: var(--text-dim); white-space: nowrap; pointer-events: none; letter-spacing: 0.3px;
}
.assistant-msg.user[data-time]:hover::after { right: 6px; }
.assistant-msg.bot[data-time]:hover::after, .assistant-msg.error[data-time]:hover::after { left: 6px; }
/* Markdown-lite inside bot bubbles */
.assistant-msg.bot ul, .assistant-msg.bot ol { margin: 4px 0 4px 18px; display: flex; flex-direction: column; gap: 2px; }
.assistant-msg.bot ul { list-style: disc; }
.assistant-msg.bot ol { list-style: decimal; }
.assistant-msg.bot li::before { content: none; }
.assistant-msg.bot strong { font-weight: 700; color: #fff; }
.assistant-msg.bot code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8em;
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: 5px; padding: 1px 5px;
}
.assistant-msg.user {
  align-self: flex-end; color: #fff;
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  border-bottom-right-radius: 6px;
}
.assistant-msg.bot {
  align-self: flex-start; color: var(--text);
  background: var(--surface3); border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.assistant-msg.error {
  align-self: stretch; color: #fca5a5;
  background: var(--red-dim); border: 1px solid rgba(239,68,68,0.3);
  font-size: 0.8rem;
}
.assistant-activity {
  align-self: flex-start; font-size: 0.72rem; font-weight: 600; color: var(--text-muted);
  padding: 4px 10px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border-soft);
}
.assistant-activity.failed { color: #fca5a5; border-color: rgba(239,68,68,0.3); }

/* Proposal card */
.assistant-proposal {
  align-self: stretch;
  background: linear-gradient(180deg, rgba(245,158,11,0.10) 0%, rgba(245,158,11,0.04) 100%);
  border: 1px solid rgba(245,158,11,0.35);
  border-radius: 14px; padding: 12px 14px;
}
.assistant-proposal.pending { animation: assistantProposalPulse 2.2s ease-in-out infinite; }
@keyframes assistantProposalPulse {
  0%, 100% { border-color: rgba(245,158,11,0.35); box-shadow: 0 0 0 0 rgba(245,158,11,0); }
  50%      { border-color: rgba(245,158,11,0.75); box-shadow: 0 0 0 4px rgba(245,158,11,0.10); }
}
.assistant-proposal.confirmed { background: var(--green-dim); border-color: rgba(34,197,94,0.3); }
.assistant-proposal.rejected { opacity: 0.6; background: var(--surface2); border-color: var(--border); }
.assistant-proposal-title { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.4px; text-transform: uppercase; color: var(--amber); margin-bottom: 8px; }
.assistant-proposal.confirmed .assistant-proposal-title { color: var(--green); }
.assistant-proposal.rejected .assistant-proposal-title { color: var(--text-muted); }
.assistant-proposal-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.assistant-proposal-list li { font-size: 0.88rem; font-weight: 600; color: var(--text); display: flex; flex-direction: column; gap: 4px; }
.assistant-proposal-list li::before { content: none; }
.assistant-proposal-desc::before { content: '→ '; color: var(--amber); }
.assistant-proposal.confirmed .assistant-proposal-desc::before { content: '✓ '; color: var(--green); }
.assistant-proposal-detail summary { font-size: 0.72rem; color: var(--text-muted); cursor: pointer; font-weight: 500; }
.assistant-proposal-detail pre {
  margin-top: 6px; padding: 10px; border-radius: 8px; background: var(--bg);
  font-size: 0.68rem; line-height: 1.4; color: var(--text-muted); overflow-x: auto; max-height: 220px;
}
.assistant-proposal-actions { display: flex; gap: 8px; margin-top: 12px; }
.assistant-btn {
  flex: 1; padding: 10px 12px; border-radius: 10px; font-size: 0.85rem; font-weight: 700; cursor: pointer;
  background: var(--surface3); border: 1px solid var(--border-mid); color: var(--text);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.assistant-btn:hover:not(:disabled) { background: var(--surface4); }
.assistant-btn.primary { background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(34,197,94,0.3); }
.assistant-btn.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(34,197,94,0.4); }
.assistant-btn:disabled { opacity: 0.5; cursor: default; }

/* Input */
.assistant-input {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
}
.assistant-input-note { flex-basis: 100%; font-size: 0.72rem; font-weight: 600; color: var(--amber); padding: 0 2px; }
.assistant-input.is-listening input { border-color: rgba(239,68,68,0.6); box-shadow: 0 0 0 3px rgba(239,68,68,0.15); }

/* Microphone (Web Speech API) */
.assistant-mic {
  width: 46px; flex-shrink: 0; border-radius: 12px; cursor: pointer; font-size: 1rem;
  background: var(--surface3); border: 1px solid var(--border-mid); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.assistant-mic:hover:not(:disabled) { background: var(--surface4); border-color: var(--accent); transform: translateY(-1px); }
.assistant-mic:disabled { opacity: 0.35; cursor: default; }
.assistant-mic.listening {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); border-color: transparent; color: #fff;
  animation: assistantMicPulse 1.2s ease-out infinite;
}
@keyframes assistantMicPulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,0.55); }
  100% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
}
.assistant-input input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px;
  background: var(--surface3); border: 1px solid var(--border-mid); color: var(--text);
  font-size: 16px; /* prevents iOS zoom */ font-family: inherit; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.assistant-input input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.assistant-input input:disabled { opacity: 0.5; }
.assistant-input input::placeholder { color: var(--text-dim); }
.assistant-send {
  width: 46px; border-radius: 12px; border: none; cursor: pointer; font-size: 1rem; color: #fff;
  background: linear-gradient(135deg, #4f8cff 0%, #7c5cff 100%);
  display: flex; align-items: center; justify-content: center; transition: opacity 0.15s, transform 0.1s;
}
.assistant-send:hover:not(:disabled) { transform: translateY(-1px); }
.assistant-send:disabled, .assistant-send.is-empty { opacity: 0.35; }
.assistant-send:disabled { cursor: default; }

/* Phone: full-height sheet, bigger touch targets, FAB clear of the thumb zone */
@media (max-width: 600px) {
  .assistant-drawer { width: 100vw; border-left: none; }
  .assistant-fab { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 52px; height: 52px; }
  .assistant-msg { max-width: 92%; }
  .assistant-header { gap: 8px; padding: 14px 12px 12px 14px; }
  .assistant-briefing { width: 32px; padding: 0; justify-content: center; border-radius: 50%; }
  .assistant-briefing-label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .assistant-drawer, .assistant-backdrop, .assistant-fab-badge, .assistant-dot.pulsing, .assistant-dot.rec,
  .assistant-typing span, .assistant-proposal.pending, .assistant-mic.listening { animation: none; }
}

/* ── ENERGY PER DEVICE CARD ─────────────────────────────────────────────── */
.energy-per-device {
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
}
.epd-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.epd-title { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.epd-total { font-size: 1.05rem; font-weight: 800; color: var(--text); letter-spacing: -0.3px; }
.epd-total small { font-size: 0.65rem; font-weight: 600; color: var(--text-muted); margin-left: 4px; text-transform: uppercase; letter-spacing: 0.4px; }
.epd-total.stale { color: var(--amber); }
.epd-empty { font-size: 0.8rem; color: var(--text-dim); padding: 8px 0; }
.epd-list { display: flex; flex-direction: column; }
.epd-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
}
.epd-row:last-child { border-bottom: none; }
.epd-icon { font-size: 1.1rem; width: 28px; text-align: center; flex-shrink: 0; opacity: 0.9; }
.epd-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.epd-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.epd-name { font-size: 0.85rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.epd-bar { height: 4px; border-radius: 2px; background: var(--surface4); overflow: hidden; }
.epd-bar-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #f59e0b 0%, #fb923c 100%);
  transition: width 0.4s ease;
}
.epd-row.stale .epd-bar-fill { background: var(--surface5); }
.epd-row.stale .epd-name,
.epd-row.stale .epd-power { color: var(--text-muted); text-decoration: line-through; text-decoration-color: rgba(245,158,11,0.5); }
.epd-values { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; gap: 2px; }
.epd-power { font-size: 0.95rem; font-weight: 800; color: var(--text); letter-spacing: -0.3px; font-variant-numeric: tabular-nums; }
.epd-energy { font-size: 0.66rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }

/* Offline pill — shared look for any stale sensor */
.stale-pill {
  display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.3px; text-transform: uppercase;
  color: var(--amber); background: var(--amber-dim); border: 1px solid rgba(245,158,11,0.35);
  border-radius: 999px; padding: 2px 7px; line-height: 1.4; white-space: nowrap;
}
.epd-row.rest .epd-name, .epd-row.rest .epd-power { color: var(--text-muted); }
.epd-row.rest .epd-bar-fill { background: repeating-linear-gradient(90deg, var(--surface5) 0 6px, transparent 6px 9px); }
