/**
 * Phase 4 of reorg-solver-correctness — zone-layout chat panel styles.
 * Uses CSS variables only (no literal hex codes) per #42 design tokens.
 */

.zone-layout-chat-modal {
  width: min(960px, 95vw);
  /* `.modal` (modals.css:38) caps max-width at 400px. The layout chat
   * needs much more room for the before/after tables — override here. */
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.zone-layout-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.zone-layout-chat-header h2 {
  margin: 0;
  font-size: var(--font-h4);
}

.zone-layout-chat-body {
  flex: 1;
  overflow: auto;
  padding: var(--space-md);
}

.zone-layout-chat-footer {
  padding: var(--space-md);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.zone-layout-chat-loading,
.zone-layout-chat-empty,
.zone-layout-chat-accepted {
  text-align: center;
  padding: var(--space-lg);
}

.zone-layout-chat-empty h3,
.zone-layout-chat-accepted h3 {
  margin: 0 0 var(--space-sm) 0;
}

.zone-layout-chat-empty .btn {
  margin-top: var(--space-md);
}

/* Split-pane: layout table left, chat right (desktop). The layout pane is
 * given more room than the chat because it now contains the before/after
 * grid (two tables side-by-side internally — needs the space). */
.zone-layout-chat-split {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: var(--space-md);
  align-items: start;
}

.zone-layout-chat-layout,
.zone-layout-chat-chat {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.zone-layout-chat-layout h3,
.zone-layout-chat-chat h3 {
  margin: 0;
  font-size: var(--font-h5);
}

.zone-layout-chat-rationale {
  margin: 0 0 var(--space-sm) 0;
  font-size: var(--font-body-sm);
  color: var(--color-text-muted);
}

.zone-layout-chat-rationale__summary {
  cursor: pointer;
  list-style: revert;
}

.zone-layout-chat-rationale__summary:hover {
  color: var(--color-text);
}

.zone-layout-chat-rationale__more {
  margin: var(--space-xs) 0 0 var(--space-md);
  padding-left: var(--space-md);
  font-size: var(--font-caption);
}

.zone-layout-chat-rationale__more li {
  margin-bottom: var(--space-xxs);
}

.zone-layout-chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-body-sm);
}

.zone-layout-chat-table th,
.zone-layout-chat-table td {
  text-align: left;
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--color-border-light);
}

.zone-layout-chat-table thead th {
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: var(--font-caption);
}

.zone-layout-chat-cell-count {
  text-align: right;
}

.zone-layout-chat-total {
  margin: var(--space-sm) 0 0 0;
  font-size: var(--font-caption);
  color: var(--color-text-muted);
}

/* Chat thread */
.zone-layout-chat-thread {
  min-height: 200px;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  background: var(--color-surface-subtle);
}

.zone-layout-chat-msg {
  margin-bottom: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
}

.zone-layout-chat-msg__role {
  font-size: var(--font-caption);
  color: var(--color-text-muted);
  font-weight: 600;
}

.zone-layout-chat-msg__body {
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  white-space: pre-wrap;
  word-break: break-word;
}

.zone-layout-chat-msg--user .zone-layout-chat-msg__body {
  background: var(--color-accent-subtle);
  align-self: flex-end;
  max-width: 90%;
}

.zone-layout-chat-msg--assistant .zone-layout-chat-msg__body {
  background: var(--color-surface);
  max-width: 90%;
}

/* Input area */
.zone-layout-chat-input {
  display: flex;
  gap: var(--space-sm);
  align-items: stretch;
}

.zone-layout-chat-input__field {
  flex: 1;
  resize: vertical;
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font: inherit;
}

/* Converged-hint accent for the Accept button (SD-4) */
.btn--converged-hint {
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
  animation: converged-pulse 2s ease-in-out infinite;
}

@keyframes converged-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--color-accent-subtle); }
  50% { box-shadow: 0 0 0 4px var(--color-accent-subtle); }
}

/* Mobile: stack panels vertically */
@media (max-width: 768px) {
  .zone-layout-chat-split {
    grid-template-columns: 1fr;
  }

  .zone-layout-chat-thread {
    max-height: 280px;
  }

  .zone-layout-chat-modal {
    max-height: 100vh;
    width: 100vw;
    border-radius: 0;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ─── Unified variance view (plan: zone-layout-advisor-before-after-surface) ──
 *
 * Replaces the original two-pane Now/After grid. One table, one row per
 * cellar row. Unchanged rows render in muted styling; changed rows pop
 * with an accent tint + From → To zone-name pair. Gestalt similarity:
 * the eye lands on the highlighted variance, not on duplicated information.
 * One layout for every breakpoint — no mobile/desktop divergence. */

.zlc-changed-count {
  font-weight: 600;
  font-size: var(--font-body);
  color: var(--color-text);
  margin: 0 0 var(--space-sm) 0;
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-accent-subtle);
  border-radius: var(--radius-sm);
}

.zlc-diff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-body-sm);
}

.zlc-diff-table thead th {
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: var(--font-caption);
  letter-spacing: 0.04em;
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--color-border-light);
}

.zlc-row {
  border-bottom: 1px solid var(--color-border-light);
}

.zlc-row__label {
  font-weight: 600;
  width: 3.5em;
  white-space: nowrap;
  padding: var(--space-xs) var(--space-sm);
  vertical-align: middle;
}

.zlc-row__zone {
  padding: var(--space-xs) var(--space-sm);
  vertical-align: middle;
  /* Word-boundary wrapping only — never mid-character. "Cabernet Sauvignon"
   * wraps as "Cabernet\nSauvignon", never "Sauvigno\nn Blanc". */
  overflow-wrap: break-word;
  word-break: normal;
}

/* Stay row — muted; the eye should skim past these to find the changes. */
.zlc-row--stay .zlc-row__label,
.zlc-row--stay .zlc-row__zone-name {
  color: var(--color-text-muted);
  font-weight: 400;
}

/* Changed row — accent tint background + bold label so the row pops. */
.zlc-row--changed {
  background: var(--color-accent-subtle);
}

.zlc-row--changed .zlc-row__label {
  color: var(--color-accent);
  font-weight: 700;
}

/* Assigned (was empty, now filled) — success tint. */
.zlc-row--assigned {
  background: color-mix(in srgb, var(--color-success, #4ade80) 12%, transparent);
}

.zlc-row--assigned .zlc-row__label {
  font-weight: 700;
}

/* Unassigned (was filled, now empty) — warning tint. */
.zlc-row--unassigned {
  background: color-mix(in srgb, var(--color-warning, #f59e0b) 12%, transparent);
}

.zlc-row--unassigned .zlc-row__label {
  font-weight: 700;
}

/* From / arrow / To inline composition inside the zone cell. */
.zlc-row__zone-from,
.zlc-row__zone-to {
  display: inline;
}

.zlc-row__zone-from {
  color: var(--color-text-muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--color-text-muted);
}

.zlc-row__zone-from--empty {
  font-style: italic;
  text-decoration: none;
}

.zlc-row__zone-to {
  color: var(--color-text);
  font-weight: 600;
}

.zlc-row__zone-to--empty {
  color: var(--color-text-muted);
  font-style: italic;
  font-weight: 400;
}

.zlc-row__zone-arrow {
  display: inline-block;
  margin: 0 var(--space-xs);
  color: var(--color-text-muted);
  user-select: none;
}

/* Narrow viewports: stack the chat-split (layout + chat) vertically so the
 * diff table gets full modal width and the chat thread sits below it. */
@media (max-width: 1100px) {
  .zone-layout-chat-split {
    grid-template-columns: 1fr;
  }
}
