/* The inspector and conversation have separate scroll areas; neither owns a second task. */
.layout {
  --task-panel-width: 420px;
}
.chat {
  min-block-size: 0;
  container: conversation / inline-size;
}

/* The active card is outside .chat; retain the shortcut suppression of the inline layout. */
.layout:has(#task-panel:not([hidden])[data-editing='true']) #quick,
.layout:has(#task-panel:not([hidden])[data-editing='true']) #task-forms {
  display: none;
}

/* An inspector can narrow the conversation on a desktop too. */
@container conversation (max-width: 620px) {
  .result-table thead {
    display: none;
  }
  .result-table table,
  .result-table tbody {
    display: block;
  }
  .result-table tr {
    display: grid;
    grid-template-columns: fit-content(40%) minmax(0, 1fr);
    gap: 0 12px;
    padding: 6px 10px;
    border-block-end: 1px solid var(--border);
  }
  .result-table tr:last-child {
    border-block-end: 0;
  }
  .result-table td {
    display: contents;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .result-table td::before {
    content: attr(data-label);
    color: var(--muted);
  }
  .result-table td:first-child::before {
    content: none;
  }
  .result-table td:first-child {
    display: block;
    grid-column: 1 / -1;
    font-weight: 600;
  }
  .result-table .num {
    text-align: start;
  }
}
.side {
  flex-shrink: 0;
}
.drawer-toggle {
  display: inline-flex;
}
.history-collapsed .side {
  display: none;
}
body:has(#app[hidden]) .drawer-toggle {
  display: none;
}

.task-panel {
  display: flex;
  flex: 0 0 var(--task-panel-width);
  flex-direction: column;
  inline-size: var(--task-panel-width);
  min-inline-size: 280px;
  min-block-size: 0;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 18px 10px;
}
.panel-heading > div {
  min-inline-size: 0;
}
.panel-heading h2 {
  margin: 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}
.panel-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: var(--text-xs);
}
.icon-button {
  inline-size: 32px;
  min-block-size: 32px;
  padding: 0;
  font-size: 22px;
}
.panel-heading .icon-button {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted);
}

.panel-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 12px;
  border-block-end: 1px solid var(--border);
}
.panel-marks:empty {
  display: none;
}
.panel-mark {
  min-block-size: 28px;
  padding: 2px 8px;
  font-size: var(--text-xs);
  color: var(--fg-soft);
  background: var(--surface-sunken);
  border-color: transparent;
  box-shadow: none;
}
.panel-mark.confirm {
  color: var(--warn);
  background: var(--warn-soft);
}
.panel-mark.error {
  color: var(--bad);
  background: var(--bad-soft);
}

.panel-content {
  flex: 1;
  min-block-size: 0;
  margin: 0;
  padding: 0 0 16px;
  overflow: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-gutter: stable;
}
.panel-content > .task-card {
  inline-size: 100%;
  max-inline-size: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 0;
  border-radius: 0;
  overflow-wrap: anywhere;
}
.panel-content > .task-card > strong {
  display: none;
}
.panel-content .task-field {
  grid-template-columns: minmax(5rem, 7rem) minmax(0, 1fr) auto;
  column-gap: 8px;
}
.panel-content .task-field:focus {
  outline: 2px solid var(--brand-blue);
  outline-offset: -2px;
}
.panel-content .task-field.field-updated {
  animation: field-update 2.4s ease-out;
}
.panel-content .task-field > .actions button {
  max-inline-size: 100%;
}
.panel-content .task-detail {
  overflow-wrap: anywhere;
}
.panel-content .task-main > * {
  min-inline-size: 0;
}

.panel-footer {
  flex: none;
  border-block-start: 1px solid var(--border);
  background: var(--surface-alt);
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
}
.panel-footer > .actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.panel-footer button:not(.ghost) {
  order: -1;
}
.panel-footer button.ghost:last-of-type {
  margin-inline-start: auto;
  border-color: transparent;
  background: transparent;
  color: var(--bad);
  box-shadow: none;
}

.messages > .task-reference {
  max-inline-size: 100%;
  inline-size: fit-content;
  padding: 0;
  background: transparent;
  box-shadow: none;
}
.task-reference-button {
  border-style: dashed;
  border-color: var(--border-strong);
  color: var(--link);
  font-size: var(--text-sm);
}
.task-reference-button::before {
  content: '↔';
}
.panel-resize {
  flex: 0 0 8px;
  cursor: col-resize;
  touch-action: none;
  background: var(--bg);
  position: relative;
}
.panel-resize::after {
  content: '';
  position: absolute;
  inset-block: 45%;
  inset-inline: 3px;
  border-radius: 2px;
  background: var(--border-strong);
}
.panel-resize:hover,
.panel-resize:focus {
  background: var(--brand-blue-soft);
  outline: 0;
}
.panel-resize:focus::after {
  background: var(--brand-blue);
}

@keyframes field-update {
  from {
    box-shadow: inset 3px 0 var(--brand-blue);
    background-color: var(--brand-blue-soft);
  }
  to {
    box-shadow: inset 0 0 transparent;
  }
}
@media (prefers-reduced-motion: reduce) {
  .panel-content .task-field.field-updated {
    animation: none;
    outline: 2px solid var(--brand-blue);
    outline-offset: -2px;
  }
}

/* Below a wide desktop the history remains available as its existing drawer. */
@media (min-width: 701px) and (max-width: 1100px) {
  .side {
    position: fixed;
    z-index: 20;
    inset-block: 0;
    inset-inline-start: 0;
    inline-size: 280px;
    visibility: hidden;
    transform: translateX(100%);
    box-shadow: var(--shadow);
  }
  [dir='ltr'] .side {
    transform: translateX(-100%);
  }
  .drawer-open .side {
    transform: none;
    visibility: visible;
    display: flex;
  }
  .drawer-open .drawer-backdrop {
    display: block;
    position: fixed;
    z-index: 19;
    inset: 0;
    background: rgb(15 27 45 / 0.35);
  }
}

@media (max-width: 700px) {
  .history-collapsed .side {
    display: flex;
  }
  .task-panel {
    position: fixed;
    z-index: 32;
    inset-inline: 0;
    inset-block-end: 0;
    inline-size: 100%;
    min-inline-size: 0;
    block-size: 80dvh;
    max-block-size: calc(100dvh - 48px);
    border-inline-start: 0;
    border-block-start: 1px solid var(--border-strong);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -8px 32px rgb(0 0 0 / 0.15);
  }
  .panel-heading {
    padding: 12px 14px 8px;
  }
  .panel-marks {
    padding-inline: 14px;
    padding-block-end: 8px;
  }
  .panel-heading h2 {
    font-size: 16px;
  }
  .panel-content .task-field {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  button.panel-backdrop,
  button.panel-backdrop:hover:not(:disabled),
  button.panel-backdrop:active,
  button.panel-backdrop:focus-visible {
    position: fixed;
    z-index: 31;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgb(15 27 45 / 0.35);
    box-shadow: none;
    outline: 0;
    transition: none;
  }
  #task-panel-toggle {
    min-block-size: 32px;
    padding-inline: 8px;
    font-size: var(--text-sm);
  }
}
