/* Kyana v2 mockups: layout helpers and the run flow, on top of the Tortola Express
   bundle (ds/tortolaexpress/components/bundle.css). Every class starts with ky-. */

:where(.te-root) a { color: inherit; text-decoration: none; }
:where(.te-root) p, :where(.te-root) h1, :where(.te-root) h2, :where(.te-root) h3 { margin: 0; }

/* App shell: sidebar beside the page from 900px, slide-out menu below */
.ky-shell { display: flex; flex-wrap: wrap; align-items: stretch; min-height: 100vh; background: var(--background); }
.ky-side { flex: 1 0 var(--sidebar-width); width: auto; height: auto; }
.ky-main { display: flex; flex: 999 1 560px; flex-direction: column; min-width: 0; }
/* Every page grows with a big screen; its columns and cards grow with it. */
.ky-page { container-type: inline-size; display: flex; flex-direction: column; gap: var(--space-4); width: 100%; max-width: 1840px; margin: 0 auto; padding: var(--space-6); }
.ky-phone, .ky-scrim { display: none; }
@media (max-width: 899px) {
  .ky-side { display: none; }
  .ky-side.is-open { display: flex; position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; flex: none; width: var(--sidebar-width); overflow-y: auto; box-shadow: var(--shadow-lg); }
  .ky-scrim.is-open { display: block; position: fixed; z-index: 39; top: 0; right: 0; bottom: 0; left: 0; width: 100%; padding: 0; border: 0; background: var(--overlay); }
  .ky-phone { display: flex; }
  .ky-desk { display: none; }
  .ky-page { padding: var(--space-3); }
}
/* A page heading that says what the top bar says: seen on a phone, where the top bar shows the logo instead, and
   from 900px only read out, so the title is not shown twice. */
@media (min-width: 900px) {
  .ky-topbar-twin { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .ky-head:has(.ky-topbar-twin) { align-items: center; }
}

/* Page pieces */
.ky-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
.ky-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.ky-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; line-height: 16px; color: var(--muted-foreground); }
.ky-crumbs a:hover { color: var(--foreground); text-decoration: underline; }
.ky-crumbs .te-icon { width: 12px; height: 12px; }
.ky-grid { display: grid; align-items: start; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.ky-split { display: grid; align-items: start; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
@container (min-width: 880px) {
  .ky-split { grid-template-columns: minmax(0, 5fr) minmax(0, 3fr); }
  .ky-split--even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ky-split--list { grid-template-columns: 340px minmax(0, 1fr); }
}
.ky-stack { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.ky-list { margin: 0; padding: 0; list-style: none; }
.ky-item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.ky-item:first-child { padding-top: 0; border-top: 0; }
.ky-item:last-child { padding-bottom: 0; }
.ky-grow { flex: 1 1 240px; min-width: 0; }
.ky-title { font-weight: 500; }
.ky-meta { font-size: 12px; line-height: 16px; color: var(--muted-foreground); }
.ky-label { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--muted-foreground); }
.ky-link { color: var(--primary); font-weight: 500; text-underline-offset: 4px; }
.ky-link:hover { text-decoration: underline; }
.ky-rowlink { font-weight: 500; }
.te-person .ky-rowlink { white-space: nowrap; }
/* A search box in a column keeps its own height (the bundle sizes it for a toolbar row) */
.te-field > .te-search, .te-card__header:not(.te-card__header--row) > .te-search { flex: 0 0 auto; }
/* Mode switch inside a table cell: one line, a little tighter */
.ky-modes { flex-wrap: nowrap; }
.ky-modes .te-tab { padding: 4px 8px; font-size: 13px; }
.ky-rowlink:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 4px; }
.ky-link:focus-visible, .ky-rowlink:focus-visible { outline: none; border-radius: var(--radius-sm); box-shadow: var(--focus-ring); }
.ky-code { display: inline-block; padding: 0 6px; border-radius: var(--radius-sm); background: var(--muted); color: var(--secondary-foreground); font-size: 12px; line-height: 20px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ky-kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px var(--space-4); margin: 0; }
.ky-kv dt { color: var(--muted-foreground); }
.ky-kv dd { margin: 0; overflow-wrap: anywhere; }
.ky-raw { margin-top: 6px; }
.ky-raw > summary { cursor: pointer; color: var(--muted-foreground); font-size: 13px; font-weight: 500; }
.ky-raw > summary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
.ky-raw[open] { display: flex; flex-direction: column; gap: 6px; }
.ky-raw__call { display: flex; flex-direction: column; gap: 4px; }
.ky-json { margin: 0; max-height: 320px; overflow: auto; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--muted); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.ky-thread > summary { cursor: pointer; color: var(--muted-foreground); font-weight: 500; }
.ky-thread > summary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
/* A card folded to its header until opened, like the look-ups on a run. */
.ky-fold > summary { cursor: pointer; list-style: none; }
.ky-fold > summary::-webkit-details-marker { display: none; }
.ky-fold > summary > div { flex: 1 1 320px; min-width: 0; }
.ky-fold > summary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-xl); }
.ky-fold__hint { flex: none; display: inline-flex; align-items: center; gap: 6px; color: var(--muted-foreground); font-size: 13px; font-weight: 500; white-space: nowrap; }
.ky-fold__hint .te-icon { width: 16px; height: 16px; transition: transform .15s; }
.ky-fold[open] .ky-fold__hint .te-icon { transform: rotate(180deg); }
.ky-fold__filter { margin-bottom: var(--space-3); }
.ky-letter { display: flex; flex-direction: column; gap: 10px; padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--sidebar); overflow-wrap: anywhere; }
.ky-del { border-radius: 3px; background: var(--danger-bg); color: var(--danger-text); text-decoration: line-through; }
.ky-ins { border-radius: 3px; background: var(--success-bg); color: var(--success-text); text-decoration: none; }
.ky-hide { display: none !important; }
.ky-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Choices and pickable rows */
.ky-choice { display: inline-flex; align-items: center; gap: 6px; min-height: var(--control-height); padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-full); background: var(--background); color: var(--foreground); font: 500 13px/20px var(--font-sans); cursor: pointer; transition: background-color .15s, border-color .15s; }
.ky-choice:hover { background: var(--muted); }
.ky-choice[aria-pressed="true"] { border-color: var(--primary); background: var(--accent); color: var(--accent-foreground); }
.ky-pick { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: 10px 12px; border: 0; border-radius: var(--radius-lg); background: none; color: var(--foreground); font: inherit; text-align: left; cursor: pointer; }
.ky-pick:hover { background: var(--muted); }
.ky-pick[aria-current="true"] { background: var(--accent); color: var(--accent-foreground); }
.ky-choice:focus-visible, .ky-pick:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Source families: fixed chart order from the brand book */
.ky-f0 { --ky-c: #71717a; --ky-t: #f4f4f5; }
.ky-f1 { --ky-c: var(--chart-1); --ky-t: #f1f6e6; }
.ky-f2 { --ky-c: var(--chart-2); --ky-t: #eff6ff; }
.ky-f3 { --ky-c: var(--chart-3); --ky-t: #fff7ed; }
.ky-f4 { --ky-c: var(--chart-4); --ky-t: #f0fdfa; }
.ky-f5 { --ky-c: var(--chart-5); --ky-t: #f5f3ff; }
.ky-fill { background: var(--ky-c); }
.ky-dot { display: inline-block; width: 8px; height: 8px; flex-shrink: 0; border-radius: var(--radius-full); background: var(--ky-c, var(--muted-foreground)); }
.ky-legend { display: flex; flex-wrap: wrap; gap: 6px var(--space-4); font-size: 12px; line-height: 16px; color: var(--muted-foreground); }
.ky-legend > span { display: inline-flex; align-items: center; gap: 6px; }

/* Meters and bars */
.ky-meter { display: block; height: 8px; overflow: hidden; border-radius: var(--radius-full); background: var(--accent); }
.ky-meter > span { display: block; height: 100%; border-radius: var(--radius-full); background: var(--primary); }
.ky-meter--warn { background: var(--warning-bg); }
.ky-meter--warn > span { background: var(--warning-strong); }
.ky-bar { display: flex; gap: 2px; height: 28px; }
.ky-bar > span { display: flex; align-items: center; min-width: 3px; border-radius: 4px; background: var(--ky-c); color: #fff; font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap; }
.ky-bar--thin { height: 8px; }
.ky-bar--thin > span { border-radius: var(--radius-full); }

/* Charts: plot area with HTML gridlines and labels over a stretched SVG */
.ky-plot { position: relative; height: 220px; margin: 12px 0 0 44px; }
.ky-plot svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: visible; }
.ky-plot svg * { fill: none; vector-effect: non-scaling-stroke; }
.ky-gl { position: absolute; right: 0; left: 0; border-top: 1px solid var(--border); }
.ky-gl > span { position: absolute; top: -8px; right: 100%; margin-right: 8px; font-size: 11px; line-height: 16px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ky-ref { position: absolute; right: 0; left: 0; border-top: 1px dashed var(--muted-foreground); }
.ky-ref > span { position: absolute; left: 8px; bottom: 3px; padding: 0 4px; border-radius: 3px; background: var(--card); font-size: 11px; line-height: 14px; color: var(--muted-foreground); white-space: nowrap; }
.ky-pt { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--ky-c, var(--chart-1)); box-shadow: 0 0 0 2px var(--card); }
.ky-ptl { position: absolute; transform: translate(-100%, -50%); margin-left: -10px; padding: 0 4px; border-radius: 3px; background: var(--card); font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; }
.ky-xt { display: flex; justify-content: space-between; margin-left: 44px; padding-top: 6px; font-size: 11px; line-height: 16px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.ky-cols { position: relative; display: flex; align-items: flex-end; justify-content: space-around; height: 200px; margin: 12px 0 0 44px; border-bottom: 1px solid var(--border); }
.ky-col { position: relative; display: flex; flex-direction: column-reverse; gap: 2px; width: 24px; }
.ky-col > span { display: block; background: var(--ky-c); }
.ky-col > span:last-child { border-radius: 4px 4px 0 0; }

@media (prefers-reduced-motion: reduce) { .ky-choice, .ky-fold__hint .te-icon { transition: none; } }
/* A receipt uses more of a big screen; its flow lives in run.css. */
.ky-page--wide { max-width: 2400px; }
.ky-email-frame { display: block; width: 100%; height: 520px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: #fff; }
.ky-files { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: var(--space-2); }
.ky-file { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); color: inherit; text-decoration: none; }
a.ky-file:hover { border-color: var(--ring); }
a.ky-file:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ky-file__thumb { display: block; width: 100%; height: 96px; border-radius: var(--radius-md); background: var(--muted); object-fit: cover; }
.ky-file__thumb--icon { display: flex; align-items: center; justify-content: center; color: var(--muted-foreground); }
.ky-file__name { font-size: 13px; line-height: 18px; font-weight: 500; overflow-wrap: anywhere; }
.ky-file__meta { font-size: 12px; line-height: 16px; color: var(--muted-foreground); }

/* The Prompt page: the text Kyana is sent, edited as it is. */
.ky-prompt-edit { min-height: 420px; resize: vertical; font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
/* Its saved versions, newest first: one line each, like a table, opened to see what changed. On a phone a line
   folds to two: number, date and words, then what changed and how; who is in the details. */
.ky-vlist { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.ky-vrow { border-top: 1px solid var(--border); }
.ky-vrow__line { display: grid; grid-template-columns: 92px 150px 128px minmax(0, 1fr) 140px 72px 16px; gap: 12px; align-items: center; min-height: 40px; padding: 6px 12px; font-size: 14px; line-height: 20px; list-style: none; cursor: pointer; transition: background-color .15s; }
.ky-vrow__line::-webkit-details-marker { display: none; }
.ky-vrow__line > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ky-vrow__line:hover, .ky-vrow[open] > .ky-vrow__line { background: color-mix(in srgb, var(--muted) 50%, transparent); }
.ky-vrow__line .te-icon { width: 16px; height: 16px; color: var(--muted-foreground); transition: transform .15s; }
.ky-vrow[open] > .ky-vrow__line .te-icon { transform: rotate(180deg); }
.ky-vlist__head { min-height: 36px; background: color-mix(in srgb, var(--muted) 60%, var(--card)); font-size: 13px; font-weight: 600; cursor: default; }
.ky-vlist__head:hover { background: color-mix(in srgb, var(--muted) 60%, var(--card)); }
.ky-vrow__n { font-weight: 600; font-variant-numeric: tabular-nums; }
.ky-vrow__when, .ky-vrow__by, .ky-vrow__how { color: var(--muted-foreground); }
.ky-vrow__what--none { color: var(--muted-foreground); font-style: italic; }
.ky-vrow__words { text-align: right; font-variant-numeric: tabular-nums; }
.ky-vrow__plus { color: var(--success-text); }
.ky-vrow__minus { color: var(--danger-text); }
.ky-vrow__body { display: flex; flex-direction: column; gap: 12px; padding: 12px 12px 16px; border-top: 1px dashed var(--border); }
.ky-vrow__body .ky-track { max-height: 480px; overflow-y: auto; }
.ky-track .ky-line--gap { color: var(--muted-foreground); font-style: italic; }
@media (max-width: 899px) {
  .ky-vlist__head { display: none; }
  .ky-vlist .ky-vrow:first-of-type { border-top: 0; }
  .ky-vrow__line { grid-template-columns: auto minmax(0, 1fr) auto 16px; grid-template-areas: "n when words icon" "what what how how"; gap: 2px 12px; padding: 8px 12px; }
  .ky-vrow__n { grid-area: n; }
  .ky-vrow__when { grid-area: when; }
  .ky-vrow__words { grid-area: words; }
  .ky-vrow__line .te-icon { grid-area: icon; }
  .ky-vrow__what { grid-area: what; }
  .ky-vrow__how { grid-area: how; text-align: right; }
  .ky-vrow__by { display: none; }
}
@media (prefers-reduced-motion: reduce) { .ky-vrow__line, .ky-vrow__line .te-icon { transition: none; } }
.ky-json--tall { max-height: 640px; }
