/* Task window: tags, fields and includes on the left, the text on the right. */

.panel {
  position: relative;
  width: min(1040px, calc(100vw - 48px)); height: min(700px, calc(100dvh - 64px));
  padding: 20px 26px 22px;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--field-border); border-radius: var(--radius);
}
.panel[open] { display: flex; flex-direction: column; }
.panel::backdrop { background: var(--backdrop); }

/* Слева — поля и инклюды, справа — текст. Без колонки слева панель становится прежней. */
.panel-grid {
  flex-grow: 1; min-height: 0;
  display: grid; grid-template-columns: 260px minmax(0, 1fr);
}
.panel-grid--bare { grid-template-columns: minmax(0, 1fr); }

.panel-side {
  display: flex; flex-direction: column; gap: 30px;
  min-height: 0; overflow-y: auto;
  padding-right: 26px; border-right: 1px solid var(--rule-col);
  scrollbar-width: thin; scrollbar-color: var(--field-border) transparent;
}

.panel-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; min-height: 0; padding-left: 30px; }
.panel-grid--bare .panel-main { padding-left: 0; }

/* Подписи колонок стоят на одной высоте с крестиком. */
.side-head {
  display: flex; align-items: center; height: 32px; margin: 0;
  font-family: var(--mono); font-size: 11px; font-weight: 400;
  letter-spacing: .14em; text-transform: uppercase; color: var(--label);
}

/* Task / Preview tabs in place of the text column's title; the text under them lines up with the tab labels. */
.panel-modes { flex-shrink: 0; align-items: center; height: 32px; margin-left: -12px; }

.panel-close {
  position: absolute; top: 14px; right: 8px;
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  background: none; border: 0; color: var(--muted); cursor: pointer;
}
.panel-close:hover { color: var(--fg-strong); }

/* The agent report and the text in one scroll; without a report the text fills it and scrolls itself. */
.panel-content {
  flex-grow: 1; min-height: 0; display: flex; flex-direction: column; gap: 16px; margin-top: -10px;
  overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--field-border) transparent;
}

.prompt-box { position: relative; flex-grow: 1; min-height: 0; display: flex; flex-direction: column; }

#prompt-text {
  flex-grow: 1; min-width: 0; min-height: 0; padding: 16px 0;
  background: none; border: 0;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  font-family: var(--sans); font-size: 15px; line-height: 1.65; color: var(--fg-prompt);
  resize: none; outline: none;
}
#prompt-text::placeholder { color: var(--tick); }
[data-task-font="mono"] #prompt-text { font-family: var(--mono); font-size: 14px; }

/* Row under the text: length near the limit and the save state on the left, the dictation buttons on the right. */
.prompt-foot { display: flex; align-items: center; gap: 8px; padding-top: 8px; }
.field-limit { align-self: flex-end; }

/* Dictation (PRO): a quiet button under the text; the recording itself is a layer over the whole window. */
/* On a narrow phone the save state and the dictation label share the row by shortening, not by wrapping. */
.prompt-tools { display: flex; gap: 8px; min-width: 0; margin-left: auto; }

.dictation, .tidy, .tidy-more {
  display: inline-flex; align-items: center; height: 34px; padding: 0 9px;
  background: none;
  border: 1px solid var(--field-border); border-radius: var(--radius);
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; white-space: nowrap;
  color: var(--muted); cursor: pointer; opacity: .5;
  transition: opacity .18s ease, color .18s ease, border-color .18s ease;
}
.prompt-box:hover :is(.dictation, .tidy), .prompt-box:focus-within :is(.dictation, .tidy) { opacity: 1; }
.dictation:hover, .tidy:hover { color: var(--fg-strong); border-color: var(--rule-head); }
.dictation-mic { flex-shrink: 0; }
.dictation { min-width: 0; }
.dictation-label { max-width: 0; overflow: hidden; text-overflow: ellipsis; transition: max-width .22s ease, margin-left .22s ease; }
.dictation:hover .dictation-label, .dictation:focus-visible .dictation-label { max-width: 200px; margin-left: 9px; }
.prompt-box .dictation.dictation--used-up { opacity: .3; cursor: default; }
.dictation--used-up:hover { color: var(--muted); border-color: var(--field-border); }
.dictation--used-up .dictation-label { display: none; }

/* The layer blurs the window under it, so only the wave, the time and stop are in focus. */
.dictation-layer {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px;
  padding: 40px 48px;
  background: color-mix(in srgb, var(--bg) 58%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(.85); backdrop-filter: blur(16px) saturate(.85);
  opacity: 0; visibility: hidden; transition: opacity .28s ease, visibility 0s linear .28s;
}
.dictation-layer--open { opacity: 1; visibility: visible; transition: opacity .28s ease; }
.dictation-wave { display: block; width: min(100%, 720px); height: 160px; }
.dictation-status {
  min-height: 20px; margin: 0; text-align: center;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.dictation-layer--failed .dictation-status { color: var(--fg-strong); }
.dictation-bar { display: flex; align-items: center; gap: 18px; }
.dictation-bar [hidden] { display: none; }
.dictation-time {
  min-width: 48px; text-align: right;
  font-family: var(--mono); font-size: 13px; letter-spacing: .06em; font-variant-numeric: tabular-nums; color: var(--muted);
}
.dictation-time--ending { color: var(--fg-strong); }
.dictation-stop { min-width: 150px; }
.dictation-stop:disabled { opacity: .45; cursor: default; }

@media (prefers-reduced-motion: reduce) {
  .dictation-layer { transition: none; }
}

/* Tidying (PRO): one button left of the dictation; after tidying it puts the original back and stays in sight.
   The styles float above it: hover opens them, a phone has the arrow next to the button. */
.tidy { gap: 9px; padding: 0 10px; }
.tidy svg { flex-shrink: 0; }
.tidy-group[hidden], .tidy svg[hidden], .prompt-box--tidying .dictation { display: none; }
.prompt-box--tidying #prompt-text { border-bottom-color: var(--rule-head); color: var(--muted); }
.prompt-box .tidy--working { opacity: 1; color: var(--muted); border-color: var(--rule-head); cursor: default; }
.prompt-box .tidy--revert { opacity: 1; color: var(--fg-strong); border-color: var(--rule-head); }
.prompt-box .tidy.tidy--used-up { opacity: .3; cursor: default; }
.tidy--used-up:hover { color: var(--muted); border-color: var(--field-border); }
.tidy-group { position: relative; display: flex; flex-shrink: 0; }
.tidy-more { display: none; justify-content: center; width: 36px; margin-left: -1px; padding: 0; border-radius: 0 var(--radius) var(--radius) 0; }
.tidy-group--open .tidy-more { color: var(--fg-strong); border-color: var(--rule-head); }
.tidy-group--open .tidy-more svg { transform: rotate(180deg); }
.tidy-styles {
  position: absolute; z-index: 45; right: 0; bottom: calc(100% + 6px);
  width: max-content; padding: 6px;
  background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .42);
  visibility: hidden;
}
/* Covers the gap, so the pointer reaches the list without leaving the group. */
.tidy-styles::after { content: ""; position: absolute; top: 100%; right: 0; left: 0; height: 7px; }
.tidy-group--ready.tidy-group--open .tidy-styles { visibility: visible; }
@media (hover: hover) {
  .tidy-group--ready:hover .tidy-styles, .tidy-group--ready:has(:focus-visible) .tidy-styles { visibility: visible; }
}
.tidy-styles button {
  display: block; width: 100%; padding: 9px 10px;
  background: none; border: 0; border-radius: var(--radius);
  text-align: left; white-space: nowrap; color: var(--fg-row); cursor: pointer;
}
.tidy-styles button:hover { background: var(--bg); color: var(--fg-strong); }

/* Preview: the prompt as Markdown in place of the text; the side column stays editable and the preview follows it.
   Notes: the project notes as written, read-only, in the same place. */
.prompt-preview, .project-notes {
  flex-grow: 1; min-width: 0; min-height: 0; overflow-y: auto; padding: 16px 0;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  font-size: 15px; line-height: 1.65; color: var(--fg-prompt); overflow-wrap: anywhere;
  scrollbar-width: thin; scrollbar-color: var(--field-border) transparent;
}
.project-notes { white-space: pre-wrap; }
.prompt-preview[hidden], .project-notes[hidden], .prompt-box--preview :is(#prompt-text, .prompt-foot) { display: none; }

/* Agent report: read-only, above the text; the text under it grows to its full length and scrolls along with it. */
.agent-report {
  display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; margin-top: 10px; padding: 14px 16px 16px;
  background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius);
}
.agent-report[hidden] { display: none; }
.agent-report:not([hidden]) + .prompt-box { flex-shrink: 0; }
.agent-report:not([hidden]) + .prompt-box :is(.prompt-preview, .project-notes) { overflow: visible; }
/* Without field-sizing the text keeps a usable height and scrolls itself. */
.agent-report:not([hidden]) + .prompt-box #prompt-text { flex-shrink: 0; min-height: 240px; field-sizing: content; }
.agent-report-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.agent-report-title {
  margin: 0; font-family: var(--mono); font-size: 10px; font-weight: 400;
  letter-spacing: .12em; text-transform: uppercase; color: var(--label);
}
.agent-report-date { font-family: var(--mono); font-size: 10.5px; color: var(--tick); }
.agent-report-body { font-size: 14.5px; line-height: 1.6; color: var(--fg-prompt); overflow-wrap: anywhere; }

/* Markdown comes from the server, so its elements are styled without classes; the agent report looks the same. */
:is(.prompt-preview, .agent-report-body) > :first-child { margin-top: 0; }
:is(.prompt-preview, .agent-report-body) :is(p, ul, ol, pre, blockquote, table) { margin: 0 0 12px; }
:is(.prompt-preview, .agent-report-body) :is(h1, h2, h3, h4, h5, h6) { margin: 22px 0 10px; font-size: 15px; font-weight: 600; line-height: 1.4; color: var(--fg-strong); }
:is(.prompt-preview, .agent-report-body) h1 { font-size: 19px; }
:is(.prompt-preview, .agent-report-body) h2 { font-size: 17px; }
:is(.prompt-preview, .agent-report-body) :is(ul, ol) { padding-left: 22px; }
:is(.prompt-preview, .agent-report-body) li + li { margin-top: 3px; }
:is(.prompt-preview, .agent-report-body) strong { font-weight: 600; color: var(--fg-strong); }
:is(.prompt-preview, .agent-report-body) a { color: var(--fg-strong); }
:is(.prompt-preview, .agent-report-body) hr { margin: 24px 0; border: 0; border-top: 1px solid var(--rule-head); }
:is(.prompt-preview, .agent-report-body) code { padding: 1px 4px; background: var(--field); border-radius: var(--radius); font-family: var(--mono); font-size: .87em; }
:is(.prompt-preview, .agent-report-body) pre { padding: 12px 14px; overflow-x: auto; background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius); }
:is(.prompt-preview, .agent-report-body) pre code { padding: 0; background: none; }
:is(.prompt-preview, .agent-report-body) blockquote { padding-left: 14px; border-left: 2px solid var(--rule-head); color: var(--muted); }
:is(.prompt-preview, .agent-report-body) table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 14px; }
:is(.prompt-preview, .agent-report-body) :is(th, td) { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
:is(.prompt-preview, .agent-report-body) th { border-bottom-color: var(--rule-head); font-weight: 500; color: var(--label); }
.agent-report-body > :is(p, ul, ol, pre, blockquote, table):last-child { margin-bottom: 0; }
.agent-report-body :is(code, pre) { background: var(--bg); }
.agent-report-body pre code { background: none; }

.panel-actions { display: flex; gap: 10px; }
.panel-actions .btn-ghost { flex-grow: 1; flex-basis: 0; }
.panel-actions [data-copy][hidden] { display: none; }
.panel-actions .btn-icon { flex: 0 0 48px; width: 48px; padding: 0; color: var(--muted); }
.panel-actions .btn-icon:hover { color: var(--fg-strong); border-color: var(--rule-head); }

.side-group { display: flex; flex-direction: column; }
.side-group > .panel-add { align-self: flex-start; margin-top: 6px; }
.side-group .side-head { margin-bottom: 6px; }

.field { display: flex; flex-direction: column; gap: 6px; padding: 8px 0 12px; }
.field[hidden] { display: none; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }

.field-key {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.combo { position: relative; display: flex; }

/* Room on the right for the values toggle. */
.field-input { width: 100%; padding-right: 30px; }

.combo-toggle {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: none; border: 0; border-radius: var(--radius);
  color: var(--muted); cursor: pointer;
}
.combo-toggle:hover { color: var(--fg-strong); }
.combo-toggle[hidden] { display: none; }

/* Value lists and pickers are fixed: they float over the window, placed by floating-list.js. */
.combo-list {
  position: fixed; z-index: 40;
  max-height: 208px; overflow-y: auto; overscroll-behavior: contain;
  margin: 0; padding: 4px; list-style: none;
  background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.42);
  scrollbar-width: thin; scrollbar-color: var(--field-border) transparent;
}
.combo-list[hidden] { display: none; }

.combo-option {
  padding: 8px 10px; border-radius: var(--radius);
  font-size: 13px; line-height: 1.35; color: var(--fg-row); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.combo-option[aria-selected="true"] { background: var(--hover); color: var(--fg-strong); }
.combo-option--own { margin-top: 4px; border-top: 1px solid var(--rule); border-radius: 0; color: var(--muted); }

/* What the task has: include rows and tag chips with ×, and "+ …" under them. */
.incl-list { list-style: none; margin: 0; padding: 0; }

.picked-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 13.5px; line-height: 1.4; color: var(--fg-row);
}
.picked-row[hidden] { display: none; }
.picked-row-title { flex-grow: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tag-picked { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-chip--picked { padding-right: 6px; color: var(--fg-row); border-color: var(--field-border); }
.tag-chip--picked svg { flex-shrink: 0; color: var(--tick); }
.tag-chip--picked:hover svg { color: var(--fg-strong); }

.panel-add {
  height: 28px; padding: 0 4px; background: none; border: 0; cursor: pointer;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.panel-add:hover, .panel-add[aria-expanded="true"] { color: var(--fg-strong); }

.picker {
  position: fixed; z-index: 40;
  display: flex; flex-direction: column; gap: 4px; padding: 4px;
  background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.42);
}
.picker[hidden] { display: none; }
.picker-search { background: var(--bg); }
.picker-list {
  list-style: none; margin: 0; padding: 0; max-height: 244px; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--field-border) transparent;
}
.picker-list .incl-group { margin: 8px 8px 4px; }
.picker-list .incl-group:first-child { margin-top: 4px; }
.picker-option {
  display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: var(--radius);
  font-size: 13px; line-height: 1.35; color: var(--fg-row); cursor: pointer;
}
.picker-option[hidden] { display: none; }
.picker-option--active { background: var(--hover); color: var(--fg-strong); }
.picker-option-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-option[aria-selected="true"] .incl-box { background: var(--solid); border-color: var(--solid); color: var(--solid-fg); }
.picker .pane-empty--small { padding: 8px; }

.incl-box {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 15px; height: 15px;
  border: 1px solid var(--field-border); border-radius: 2px; color: transparent;
}

/* Подгруппы «Проекта» / «Общие» — тише заголовка колонки, но той же монотипографикой. */
.incl-group {
  margin: 14px 0 2px;
  font-family: var(--mono); font-size: 10px; font-weight: 400;
  letter-spacing: .1em; text-transform: uppercase; color: var(--tick);
}

/* Phone only: the tabs that put tags, fields or includes in place of the text. */
.side-tab { display: none; }
.side-tab-count { margin-left: 4px; color: var(--tick); }

/* Without hover the dictation button would stay dim and unlabelled; list rows are tall enough for a finger. */
@media (hover: none) {
  .dictation, .tidy, .tidy-more { height: 40px; opacity: 1; }
  .tidy-group--ready .tidy { border-radius: var(--radius) 0 0 var(--radius); }
  .tidy-group--ready .tidy-more { display: inline-flex; }
  .tidy-styles button { padding-block: 13px; font-size: 15px; }
  .dictation-label { max-width: 200px; margin-left: 9px; }
  .picker-option, .combo-option { padding-block: 11px; font-size: 15px; }
}

/* Phone: the window takes the whole screen; tags, fields and includes take the text's place behind their own tabs. */
@media (max-width: 768px) {
  .panel {
    width: 100%; height: 100%; max-width: none; max-height: none; margin: 0;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 16px calc(12px + env(safe-area-inset-bottom, 0px));
    border: 0; border-radius: 0;
  }
  /* The title row holds only the tabs: no line under it, × goes first in the actions row. */
  .panel-modes { height: 36px; margin-left: -4px; }
  .panel-modes button { padding-block: 11px; }
  #prompt-text, .prompt-preview, .project-notes { padding-top: 4px; border-top: 0; }
  .prompt-preview, .project-notes { font-size: 16px; }
  .panel-close { position: static; flex: 0 0 48px; height: 48px; border: 1px solid var(--ghost-border); border-radius: var(--radius); }
  .panel-grid { display: flex; flex-direction: column; gap: 12px; }
  .panel-main { display: contents; }
  .panel-content { flex: 1 1 auto; margin-top: 0; }
  .agent-report { margin-top: 0; }
  .prompt-box { flex: 1 1 auto; min-height: 140px; }
  #prompt-text, [data-task-font="mono"] #prompt-text { font-size: 16px; }

  /* Five tabs fit a 360px screen in most languages; longer translations scroll sideways instead of wrapping. */
  .panel-modes { overflow-x: auto; scrollbar-width: none; }
  .panel-modes button { flex: 1 0 auto; padding-inline: 5px; font-size: 10px; letter-spacing: .06em; white-space: nowrap; }
  .side-tab { display: block; }
  .panel:not(.panel--side) .panel-side, .panel--side .panel-content, .side-group:not(.side-group--shown), .side-head { display: none; }
  .panel-side { order: 1; flex: 1 1 auto; padding: 4px 0 0; border-right: 0; }
  .panel-add { height: 40px; }
  .picked-row { padding-block: 9px; font-size: 15px; }

  .panel-actions { order: 2; }
  .panel-actions [data-copy] { flex: 0 0 48px; padding: 0; color: var(--muted); }
  .panel-actions [data-copy] .btn-label { display: none; }
  .panel-actions .btn-solid { min-width: 0; padding: 0 12px; }
  [data-primary-label] { min-width: 0; overflow: hidden; text-overflow: ellipsis; text-wrap: balance; line-height: 1.4; }

  /* The wave takes the screen; stop is a wide button at the bottom, under the thumb. */
  .dictation-layer {
    justify-content: flex-start; gap: 22px;
    padding: calc(120px + env(safe-area-inset-top, 0px)) 16px calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .dictation-wave { height: 150px; }
  .dictation-bar { width: 100%; margin-top: auto; flex-direction: column; gap: 12px; }
  .dictation-time { min-width: 0; text-align: center; }
  .dictation-bar .btn { width: 100%; }
  .dictation-stop { height: 56px; }
}
