/*
 * ASL v2 studio (docs/asl-v2.md §7). Builds on app.css — the same "reading room" tokens: ink
 * ground, cool paper type, hairlines for structure, and the logo's azure spent only on the measure
 * (token counts, the chosen mode, the Send commitment). Logical properties throughout, with two
 * deliberate physical exceptions the specification asks for: the ⋮ menu and its drawer sit on the
 * LEFT in both languages.
 */

.studio { display: grid; grid-template-rows: auto 1fr; min-block-size: 100dvh; }

/* ---------------------------------------------------------------- top bar */
.studio-top { position: sticky; inset-block-start: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: var(--space-4); padding: var(--space-2) var(--space-4); background: color-mix(in srgb, var(--background) 92%, transparent);
  backdrop-filter: blur(8px); border-block-end: 1px solid var(--border); direction: ltr; }
[dir="rtl"] .studio-top > * { direction: rtl; }
.studio-top .kebab { justify-self: start; inline-size: 40px; padding: 0; }
.studio-top .kebab svg.i { inline-size: 22px; block-size: 22px; stroke-width: 2.6; }
.studio-brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--fg-strong); text-decoration: none; font-weight: 600; font-size: 18px; }
.studio-brand .mark { inline-size: 26px; block-size: 26px; color: var(--fg-strong); }
.balance-chip { justify-self: end; display: inline-flex; align-items: center; gap: 6px; padding: 2px 12px; min-block-size: 32px; border-radius: 999px;
  border: 1px solid var(--border); background: transparent; color: var(--accent); cursor: pointer; font-weight: 600; }
.balance-chip:hover { border-color: var(--line-active); background: var(--surface-raised); }
.studio-menu { min-inline-size: 200px; }

/* ---------------------------------------------------------------- the stage */
.studio-main { inline-size: 100%; max-inline-size: 52rem; margin-inline: auto; padding: var(--space-6) var(--space-4) var(--space-8);
  display: flex; flex-direction: column; min-block-size: calc(100dvh - 57px); }
.studio-main:not(.has-mode) { justify-content: center; }

/* the modes (Research · Image generation · Decision · Deep research), in the middle.
   The count varies — Level 5 is only drawn for an account that has been granted it — so the row
   fits whatever it is given rather than assuming three. */
.modes { display: grid; justify-items: center; gap: var(--space-6); }
.studio-title { text-align: center; max-inline-size: 22ch; }
.mode-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 14rem)); gap: var(--space-4); justify-content: center; inline-size: 100%; }
.mode-tile { display: grid; justify-items: center; align-content: center; gap: var(--space-2); padding: var(--space-6) var(--space-4); min-block-size: 11rem;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text); cursor: pointer; text-align: center; }
.mode-tile strong { color: var(--fg-strong); font-size: 18px; font-weight: 600; }
.mode-tile .caption { max-inline-size: 22ch; }
.mode-ico { display: grid; place-items: center; inline-size: 56px; block-size: 56px; border-radius: 50%; background: var(--surface-sunken); color: var(--text-muted); }
.mode-ico svg.i { inline-size: 28px; block-size: 28px; }
.mode-tile:hover { border-color: var(--line-active); background: var(--surface-hover); }
.mode-tile:hover .mode-ico { color: var(--fg-strong); }
.mode-tile.on { border-color: var(--accent); background: var(--accent-wash); }
.mode-tile.on .mode-ico { background: var(--accent); color: var(--background); }

/* once a mode is chosen the tiles step back into a compact switcher */
.has-mode .modes { gap: 0; }
.has-mode .mode-row { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.has-mode .mode-tile strong { white-space: nowrap; }
.has-mode .mode-tile { display: flex; justify-content: center; align-items: center; min-block-size: 0; padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); gap: var(--space-2); }
.has-mode .mode-tile .caption { display: none; }
.has-mode .mode-tile strong { font-size: 15px; }
.has-mode .mode-ico { inline-size: 32px; block-size: 32px; }
.has-mode .mode-ico svg.i { inline-size: 18px; block-size: 18px; }

/* ---------------------------------------------------------------- composer */
.v2-composer { margin-block-start: var(--space-6); display: grid; gap: var(--space-2); }
.prompt-box { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-raised); padding: var(--space-2) var(--space-4) var(--space-2); }
.prompt-box:focus-within { border-color: var(--line-active); }
.prompt { display: block; inline-size: 100%; min-block-size: 5.5rem; max-block-size: 45vh; resize: none; border: 0; outline: none; background: transparent;
  color: var(--fg-strong); padding: var(--space-2) 0; field-sizing: content; }
.prompt::placeholder { color: var(--text-muted); }
.attach-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding-block-start: var(--space-1); border-block-start: 1px solid var(--border); }
.attach-btn { min-block-size: 30px; padding-inline: var(--space-2); color: var(--text-muted); font-size: 14px; }
.attach-row .chip { cursor: default; border-style: solid; }
.chip-x { display: grid; place-items: center; inline-size: 20px; block-size: 20px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--text-muted); cursor: pointer; }
.chip-x:hover { background: var(--surface-hover); color: var(--fg-strong); }
.chip-x svg.i { inline-size: 14px; block-size: 14px; }

/* decision (v2.1): answer type, options or scale levels, optional context — inside the prompt box */
.decide { display: grid; gap: var(--space-2); padding-block: var(--space-2) var(--space-1); border-block-start: 1px solid var(--border); }
.decide-label { font-size: 14px; color: var(--text-muted); }
.decide .seg { justify-self: start; flex-wrap: wrap; }   /* the shared segmented control (app.css) */
.decide .seg button { padding-inline: var(--space-4); line-height: 28px; }
.opt-list { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.opt-row { display: grid; grid-template-columns: 2ch minmax(0, 1fr) auto; align-items: center; gap: var(--space-2); }
.opt-row .num { color: var(--text-muted); font-size: 13px; text-align: center; }
.opt-row input, .decide-context { inline-size: 100%; min-block-size: 34px; padding: var(--space-1) var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-sunken); color: var(--fg-strong); font: inherit; }
.decide-context { min-block-size: 3.2rem; resize: vertical; field-sizing: content; max-block-size: 30vh; }
.opt-add { justify-self: start; min-block-size: 30px; padding-inline: var(--space-2); color: var(--text-muted); font-size: 14px; }

/* decision result: the answer large, then how sure, then every option's probability */
.verdict { display: grid; gap: var(--space-2); }
.verdict-answer { margin: 0; color: var(--fg-strong); font-size: 28px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.verdict-answer.yes { color: var(--accent); }
.prob-list { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.prob { display: grid; grid-template-columns: minmax(6rem, 14rem) minmax(0, 1fr) 4ch; align-items: center; gap: var(--space-2); font-size: 14px; }
.prob.top .prob-name { color: var(--fg-strong); font-weight: 600; }
.prob meter { inline-size: 100%; block-size: 8px; appearance: none; border: 0; border-radius: 999px; background: var(--surface-sunken); }
.prob meter::-webkit-meter-bar { border: 0; border-radius: 999px; background: var(--surface-sunken); block-size: 8px; }
.prob meter::-webkit-meter-optimum-value, .prob meter::-webkit-meter-suboptimum-value, .prob meter::-webkit-meter-even-less-good-value { border-radius: 999px; background: var(--text-muted); }
.prob meter::-moz-meter-bar { border-radius: 999px; background: var(--text-muted); }
.prob.top meter::-webkit-meter-optimum-value, .prob.top meter::-webkit-meter-suboptimum-value, .prob.top meter::-webkit-meter-even-less-good-value { background: var(--accent); }
.prob.top meter::-moz-meter-bar { background: var(--accent); }
.prob .num { text-align: end; color: var(--text-muted); }

/* model selection row: label · Auto ⇄ Manual · list or auto hint · Send (inline end) */
.model-row { display: flex; align-items: center; gap: var(--space-2) var(--space-4); flex-wrap: wrap; }
.model-sel { flex: 1; display: flex; align-items: center; gap: var(--space-2) var(--space-4); flex-wrap: wrap; min-inline-size: 0; }
.model-label { color: var(--text-muted); font-size: 14px; }
.switch { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; user-select: none; }
.switch-side { color: var(--text-muted); font-size: 14px; }
.switch-side.on { color: var(--fg-strong); font-weight: 600; }
.switch-input { appearance: none; -webkit-appearance: none; position: relative; flex: none; inline-size: 42px; block-size: 24px; margin: 0; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-sunken); cursor: pointer; }
.switch-input::before { content: ""; position: absolute; top: 3px; left: 3px; inline-size: 16px; block-size: 16px; border-radius: 50%; background: var(--text-muted); }
/* The thumb travels toward "Manual", which follows the switch in reading order: rightward in
   English, leftward in Arabic. Physical offsets, because a form control's pseudo-element does not
   take the page direction reliably across engines. */
[dir="rtl"] .switch-input::before { left: auto; right: 3px; }
.switch-input:checked { border-color: var(--line-active); background: var(--fill-deep); }
.switch-input:checked::before { translate: 18px 0; background: var(--fg-strong); }
[dir="rtl"] .switch-input:checked::before { translate: -18px 0; }
@media (prefers-reduced-motion: no-preference) { .switch-input::before { transition: translate .15s ease, background-color .15s ease; } }
.v2-model-pick { min-block-size: 36px; max-inline-size: 100%; padding-inline: var(--space-2); background: var(--background); color: var(--fg-strong);
  border: 1px solid var(--border); border-radius: var(--radius-sm); }
.auto-pick { color: var(--text); font-size: 14px; }
.v2-send { min-block-size: 44px; padding-inline: var(--space-6); border-radius: var(--radius-md); }
.cost-line { margin: 0; min-block-size: 18px; font-variant-numeric: tabular-nums; }
.notice.needs { border-color: var(--line-active); background: var(--accent-wash); justify-content: flex-start; }
.notice.needs::before { content: "?"; display: grid; place-items: center; inline-size: 22px; block-size: 22px; border-radius: 50%; background: var(--accent); color: var(--background); font-weight: 700; flex: none; }

/* ---------------------------------------------------------------- result */
.result-slot:empty { display: none; }
.run-card { margin-block-start: var(--space-6); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-raised); display: grid; gap: var(--space-4); }
.run-card.state-failed { border-color: var(--alert); }
.run-head { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.run-head .grow { flex: 1; }
.run-ico { display: grid; place-items: center; inline-size: 28px; block-size: 28px; border-radius: 50%; background: var(--surface-sunken); color: var(--text-muted); flex: none; }
.run-ico svg.i { inline-size: 16px; block-size: 16px; }
.run-model { color: var(--fg-strong); font-weight: 600; }
.run-cost { color: var(--accent); font-weight: 600; }
.state-failed .run-cost { color: var(--text-muted); font-weight: 400; }
.run-prompt { margin: 0; padding-inline-start: var(--space-4); border-inline-start: 2px solid var(--fill-deep); color: var(--fg-strong); white-space: pre-wrap; overflow-wrap: anywhere; }
.run-note { margin: 0; }
.run-wait { display: flex; align-items: center; gap: var(--space-2); color: var(--text-muted); }
.spinner { inline-size: 16px; block-size: 16px; border-radius: 50%; border: 2px solid var(--border); border-block-start-color: var(--accent); flex: none; }
@media (prefers-reduced-motion: no-preference) { .spinner { animation: spin .8s linear infinite; } }
@keyframes spin { to { rotate: 1turn; } }
.run-images { display: grid; gap: var(--space-4); }
.run-images figure { margin: 0; display: grid; gap: var(--space-2); }
.run-images img { inline-size: 100%; max-inline-size: 40rem; justify-self: center; block-size: auto; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface-sunken); }
.run-images figcaption { display: flex; justify-content: center; }
.run-foot { display: flex; justify-content: flex-end; }

/* ---------------------------------------------------------------- drawer (left, both languages) */
.drawer { margin: 0; padding: 0; inset: 0 auto 0 0; inline-size: min(26rem, 92vw); block-size: 100dvh; max-block-size: 100dvh; max-inline-size: 92vw;
  border: 0; border-right: 1px solid var(--border); background: var(--surface-raised); color: var(--text); overflow: hidden; }
.drawer[open] { display: grid; grid-template-rows: auto 1fr; }
.drawer::backdrop { background: rgb(0 0 0 / .5); }
@media (prefers-reduced-motion: no-preference) {
  .drawer[open] { animation: drawer-in .18s ease-out; }
  @keyframes drawer-in { from { translate: -100% 0; } }
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-block-end: 1px solid var(--border); }
.drawer-head .sub { margin: 0; display: inline-flex; align-items: center; gap: var(--space-2); font-size: 18px; }
.drawer-body { overflow-y: auto; padding: var(--space-4); display: grid; gap: var(--space-4); align-content: start; }
.drawer-body .form { max-inline-size: none; }
.drawer-sub { margin: var(--space-2) 0 0; font-size: 15px; font-weight: 600; color: var(--fg-strong); }
.drawer-links { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.signout { justify-self: start; }

.profile-card { display: flex; align-items: center; gap: var(--space-4); }
.profile-card p { margin: 0; }
.avatar.big { inline-size: 48px; block-size: 48px; font-size: 20px; }

.token-balance { display: grid; gap: 2px; padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--background); }
.token-balance .big { font-size: 40px; line-height: 48px; color: var(--accent); font-family: var(--font-en); }
.price-list { display: grid; gap: var(--space-1); }
.price-h { margin: 0; display: inline-flex; align-items: center; gap: var(--space-2); font-size: 14px; font-weight: 500; color: var(--text-muted); }
.price-list .table td:last-child { text-align: end; color: var(--accent); }
.packs { display: grid; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: var(--space-2); }
.pack { padding: var(--space-2) var(--space-4); gap: 0; }
.pack strong { font-size: 20px; }

.history { list-style: none; margin: 0; padding: 0; display: grid; }
.history-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-2) var(--space-4); inline-size: 100%;
  padding: var(--space-2); border: 0; border-block-end: 1px solid var(--border); background: none; color: var(--text); text-align: start; cursor: pointer; border-radius: var(--radius-sm); }
.history-item:hover { background: var(--surface-hover); }
.history-main { display: grid; min-inline-size: 0; }
.history-prompt { color: var(--fg-strong); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.history-item.state-failed .history-cost { color: var(--alert); }

/* ---------------------------------------------------------------- Level 5: deep research (ASL v3)
   The mode costs minutes and tokens, so the composer says so before the prompt is written and the
   card says where the pipeline has got to while it runs. The answer's citations, its sources and
   the account of how it was researched sit under the prose, foldable, so they are there to check
   without crowding the thing the person came for. */
.deep-intro { display: grid; gap: var(--space-1); padding: var(--space-2) var(--space-4); border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface-sunken); }
.deep-allowance { color: var(--accent); font-weight: 600; }
.deep-allowance.spent { color: var(--alert); }

.deep-progress { display: grid; gap: var(--space-2); }
.deep-phases { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin: 0; padding: 0; list-style: none; }
.deep-phase { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.deep-phase .dot { inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--border); flex: none; }
.deep-phase.done .dot { background: var(--text-muted); }
.deep-phase.on .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.deep-phase.on .caption { color: var(--accent); font-weight: 600; }

.deep-h { display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-1); font-size: 15px; color: var(--fg-strong); }
.deep-h svg.i { inline-size: 16px; block-size: 16px; }
.deep-sources, .deep-gaps { margin-block-start: var(--space-4); padding-block-start: var(--space-2); border-block-start: 1px solid var(--border); }
.source-list { display: grid; gap: var(--space-1); margin: 0; padding-inline-start: var(--space-6); }
.source-list li { color: var(--text-muted); }
.source-list a { color: var(--text); overflow-wrap: anywhere; }
.source-list a:hover { color: var(--accent); }
.src-host { display: block; }
.deep-gaps ul { display: grid; gap: 2px; margin: 0; padding-inline-start: var(--space-6); }

.deep-how { margin-block-start: var(--space-4); padding: var(--space-2) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-sunken); }
.deep-how > summary { cursor: pointer; color: var(--fg-strong); font-weight: 600; }
.deep-how > summary::marker { color: var(--text-muted); }
.deep-how > * + * { margin-block-start: var(--space-2); }
.deep-steps { display: grid; gap: var(--space-1); margin: 0; padding-inline-start: var(--space-6); }
.deep-step { color: var(--text-muted); }
.deep-step .q { display: block; color: var(--text); overflow-wrap: anywhere; }
.deep-step.state-failed .q, .deep-step.state-skipped .q { color: var(--text-muted); text-decoration: line-through; }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 600px) {
  .studio-main { padding-inline: var(--space-4); }
  .mode-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .mode-tile { min-block-size: 8rem; padding: var(--space-4) var(--space-1); }
  .mode-tile strong { font-size: 15px; }
  .mode-tile .caption { display: none; }
  .has-mode .mode-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .has-mode .mode-tile strong { white-space: normal; }
  .has-mode .mode-tile { padding-inline: var(--space-1); }
  .has-mode .mode-tile .mode-ico { display: none; }
  .opt-row { grid-template-columns: minmax(0, 1fr) auto; }
  .model-row { align-items: stretch; }
  .model-sel { flex-basis: 100%; }
  .v2-send { flex: 1; }
  .studio-brand span { display: none; }
}
