/* ==========================================================================
   energylog AI: the chat panel

   Built only from the tokens in ui.css, so it follows all four looks, light
   and dark, and wall mode without a rule of its own for any of them beyond
   the corner shapes. Loaded after ui.css.
   ========================================================================== */

/* ------------------------------------------------------- top bar button */

.ai-btn {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 14px;
  border: 1px solid var(--line-firm); border-radius: 999px;
  background: var(--surface); color: var(--brand);
  font-size: var(--t-small); font-weight: 680; white-space: nowrap;
  cursor: pointer;
  transition: background var(--speed), color var(--speed), border-color var(--speed);
}
.ai-btn:hover { background: var(--brand-soft); }
.ai-btn[aria-expanded="true"] {
  background: var(--brand); color: var(--brand-ink); border-color: var(--brand);
}
.ai-btn-ic { font-size: 1.05em; line-height: 1; }
.ai-btn-brand { font-weight: 600; }

:root[data-look="console"] .ai-btn { border-radius: var(--radius-sm); font-family: var(--mono); }
:root[data-look="bold"] .ai-btn { border-width: 2px; }

@media (pointer: coarse) {
  .ai-btn { min-height: var(--tap); }
}

/* On a phone the title shares its row with the button instead of taking the
   whole row, so the button does not push the look switch onto a third. */
@media (max-width: 620px) {
  .topbar.has-ai h1 { flex: 1 1 0; }
}
@media (max-width: 420px) {
  .ai-btn { padding: 0 12px; }
  .ai-btn-brand { display: none; }
}

/* ----------------------------------------------------------------- panel */

.ai-panel {
  position: fixed; z-index: 70;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink);
  border-left: 1px solid var(--line);
  box-shadow: var(--lift);
  font-family: var(--font);
  transform: translateX(104%);
  visibility: hidden;
  transition: transform .22s ease, visibility 0s linear .22s;
}
.ai-panel.is-open {
  transform: none;
  visibility: visible;
  transition: transform .22s ease, visibility 0s;
}

@media (max-width: 620px) {
  .ai-panel {
    width: 100vw; height: 100dvh; border-left: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-panel, .ai-panel.is-open { transition: none; }
}

.ai-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px var(--pad);
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.ai-head .brand-dot { flex: none; }
.ai-title {
  flex: 1; min-width: 0; margin: 0;
  font-family: var(--display); font-size: var(--t-head); font-weight: 720;
  letter-spacing: -.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ai-new {
  flex: none; min-height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: none; color: var(--ink-2);
  font-size: var(--t-small); font-weight: 620; cursor: pointer;
}
.ai-new:hover { background: var(--sunk); color: var(--ink); }
.ai-new[disabled] { opacity: .5; cursor: default; }
.ai-x { font-size: 1.25rem; line-height: 1; }

@media (pointer: coarse) {
  .ai-new, .ai-x { min-height: var(--tap); min-width: var(--tap); }
}

.ai-scope {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  padding: 8px var(--pad);
  font-size: var(--t-small); color: var(--ink-muted);
  border-bottom: 1px solid var(--line);
}
.ai-scope span { font-weight: 620; color: var(--ink-2); overflow-wrap: anywhere; }
.ai-scope-btn {
  border: 0; padding: 4px 0; background: none; cursor: pointer;
  color: var(--brand); font-size: var(--t-small); font-weight: 620;
  text-decoration: underline; text-underline-offset: 2px;
}

/* ----------------------------------------------------------- messages */

.ai-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px var(--pad);
}
.ai-msg {
  max-width: 90%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--t-body); line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.ai-me {
  align-self: flex-end;
  background: var(--brand); color: var(--brand-ink);
}
.ai-bot {
  align-self: flex-start;
  background: var(--sunk); color: var(--ink);
}
.ai-err {
  align-self: flex-start;
  background: var(--sunk); color: var(--ink);
  border-left: 3px solid var(--high);
}
.ai-wait {
  align-self: flex-start;
  padding-inline: 2px;
  color: var(--ink-muted); font-size: var(--t-small);
  font-variant-numeric: tabular-nums;
}
.ai-wait[data-note]::after {
  content: attr(data-note);
  display: block; margin-top: 4px; white-space: pre-wrap;
}

:root[data-look="bold"] .ai-msg { border-radius: var(--radius); }
:root[data-look="console"] .ai-msg { border-radius: var(--radius-sm); }

/* a change the chat proposed: made only after "Apply change" and the OK box */
.ai-card {
  align-self: flex-start;
  width: 90%;
  margin-top: -4px;
  padding: 10px 12px 11px;
  border: 1px solid var(--line-firm);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--t-small); line-height: 1.5;
  overflow-wrap: anywhere;
}
.ai-card-title { margin: 0 0 6px; font-weight: 680; color: var(--ink); }
.ai-card ul { margin: 0 0 8px; padding-left: 18px; color: var(--ink-2); }
.ai-card-warn { margin: 0 0 10px; color: var(--ink-2); }
.ai-card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-card-actions .btn { width: auto; min-height: 32px; padding: 0 12px; font-size: var(--t-small); }
.ai-card-state { margin: 2px 0 0; font-weight: 620; color: var(--ink-muted); }
.ai-card.is-done { border-left-color: var(--ok); }
.ai-card.is-done .ai-card-state { color: var(--ok); }
.ai-card.is-off { opacity: .75; }
@media (pointer: coarse) {
  .ai-card-actions .btn { min-height: var(--tap); }
}

/* --------------------------------------------------------- starter chips */

.ai-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 var(--pad) 10px;
}
.ai-chips:empty { display: none; }
.ai-chip {
  max-width: 100%;
  padding: 7px 12px; min-height: 34px;
  border: 1px solid var(--line-firm); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-size: var(--t-small); text-align: left; cursor: pointer;
}
.ai-chip:hover { border-color: var(--brand); color: var(--brand); }
.ai-chip-lang { color: var(--brand); font-weight: 620; }
:root[data-look="console"] .ai-chip,
:root[data-look="console"] .ai-new { border-radius: var(--radius-sm); }

@media (pointer: coarse) {
  .ai-chip { min-height: var(--tap); }
}

/* ------------------------------------------------------------- composer */

.ai-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px var(--pad);
  border-top: 1px solid var(--line);
}
.ai-form textarea {
  flex: 1; min-width: 0;
  min-height: var(--tap); max-height: 132px;
  padding: 10px 12px; resize: none;
  font: inherit; font-size: max(16px, var(--t-body));   /* 16px stops iOS zooming in */
  color: var(--ink); background: var(--sunk);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.ai-form textarea::placeholder { color: var(--ink-muted); }
.ai-form textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.ai-send { width: auto; flex: none; padding: 0 18px; }

.ai-note {
  margin: 0; padding: 0 var(--pad) 12px;
  font-size: var(--t-micro); color: var(--ink-muted);
}
