/* =============================================================================
   LoomPilot wave 2 · Trade Desk (td-): floating pill + command sheet
   ============================================================================= */

/* ---------------------------------------------------------------- the pill (bottom-left; the mini line sheet is bottom-right) */
.td-pill { position: fixed; left: 18px; bottom: 18px; z-index: 108; display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; border-radius: 999px; cursor: pointer;
    color: var(--text); background: color-mix(in srgb, var(--bg2) 82%, transparent); -webkit-backdrop-filter: blur(14px) saturate(1.3); backdrop-filter: blur(14px) saturate(1.3);
    border: 1px solid var(--line2); box-shadow: 0 18px 44px -16px rgba(0, 0, 0, .6), inset 0 0 0 3px color-mix(in srgb, var(--accent) 7%, transparent);
    font: 700 13px/1.15 var(--f-ui); text-align: left; transition: transform .45s var(--ease), opacity .3s, border-color .25s, bottom .5s var(--ease); animation: tdIn .9s var(--ease) .6s both; }
.td-pill:hover { border-color: var(--accent); transform: translateY(-2px); }
.td-pill.td-away { opacity: 0; transform: translateY(14px) scale(.96); pointer-events: none; }
.td-pill-ico { position: relative; width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 16px; }
.td-pill-ico::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; border: 1px dashed rgba(0, 0, 0, .28); }
html[data-mode="retail"] .td-pill-ico::after { border-color: rgba(255, 255, 255, .45); }
.td-pill-ico::before { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 1px solid var(--accent); opacity: 0; animation: tdPing 3.6s ease-out 2.2s 3; }
.td-pill-t { display: grid; gap: 1px; max-width: 200px; overflow: hidden; white-space: nowrap; transition: max-width .45s var(--ease), opacity .3s; }
.td-pill > kbd { transition: opacity .3s, max-width .45s var(--ease), padding .45s var(--ease), border-width .45s; max-width: 30px; overflow: hidden; }
/* icon-only (after the first screen, and always on small screens): the label moves into a tooltip */
.td-pill.td-mini { gap: 0; padding: 5px; }
.td-pill.td-mini .td-pill-t { max-width: 0; opacity: 0; }
.td-pill.td-mini > kbd { max-width: 0; opacity: 0; padding-left: 0; padding-right: 0; border-width: 0; }
.td-tip { position: absolute; left: calc(100% + 10px); top: 50%; display: flex; align-items: center; gap: 8px; padding: 7px 10px 7px 12px; border-radius: 10px; white-space: nowrap; background: var(--paper); color: var(--paper-ink); font: 800 12.5px var(--f-ui); box-shadow: 0 12px 26px -10px rgba(0, 0, 0, .5); opacity: 0; transform: translate(-6px, -50%); pointer-events: none; transition: opacity .2s, transform .3s var(--ease); }
.td-tip kbd { color: var(--paper-ink) !important; background: rgba(0, 0, 0, .06) !important; border-color: rgba(0, 0, 0, .2) !important; }
.td-pill.td-mini:hover .td-tip, .td-pill.td-mini:focus-visible .td-tip { opacity: 1; transform: translate(0, -50%); }
.td-pill-t b { font: 600 15px/1.1 var(--f-display); letter-spacing: -.005em; }
.td-pill-t small { font: 600 10.5px var(--f-ui); color: var(--muted); letter-spacing: .02em; }
.td-pill kbd, .td kbd { font: 800 11px/1 var(--f-ui); padding: 4px 7px; border-radius: 6px; border: 1px solid var(--line2); border-bottom-width: 2px; color: var(--muted); background: var(--surface); }
@keyframes tdIn { from { opacity: 0; transform: translateY(30px); } }
@keyframes tdPing { 0% { opacity: .9; transform: scale(.85); } 80%, 100% { opacity: 0; transform: scale(1.5); } }
/* keep clear of the full-width mini line sheet on phones */
@media (max-width: 720px) {
    .td-pill { gap: 0; padding: 5px; }
    .td-pill .td-pill-t, .td-pill > kbd { display: none; }
    .td-pill-ico { width: 44px; height: 44px; font-size: 18px; }
    .td-pill.td-mini:hover .td-tip { opacity: 0; }
}
@media (max-width: 520px) {
    .td-pill { left: 12px; bottom: 12px; }
    body:has(#miniSheet.show) .td-pill { bottom: 78px; }
}
/* the toast sits bottom-centre; on narrow screens lift the pill above it while it shows */
@media (max-width: 720px) { body:has(#toast.show) .td-pill { bottom: 84px; } body:has(#miniSheet.show):has(#toast.show) .td-pill { bottom: 148px; } }
@media (hover: none) { .td-pill kbd { display: none; } }

/* ---------------------------------------------------------------- the dialog */
.td { position: fixed; inset: 0; z-index: 330; display: flex; justify-content: center; align-items: flex-start; padding: min(11vh, 96px) 16px 16px; }
.td-scrim { position: absolute; inset: 0; background: rgba(5, 8, 20, .62); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); opacity: 0; transition: opacity .3s; }
html[data-mode="retail"] .td-scrim { background: rgba(40, 28, 16, .42); }
.td.open .td-scrim { opacity: 1; }
.td-sheet { position: relative; width: min(760px, 100%); max-height: calc(100svh - min(11vh, 96px) - 24px); display: flex; flex-direction: column; overflow: hidden; border-radius: 26px;
    background: var(--bg2); color: var(--text); border: 1px solid var(--line2); box-shadow: 0 50px 120px -30px rgba(0, 0, 0, .8), inset 0 0 0 6px color-mix(in srgb, var(--accent) 5%, transparent);
    opacity: 0; transform: translateY(-14px) scale(.985); transition: opacity .28s, transform .45s var(--ease); }
.td.open .td-sheet { opacity: 1; transform: none; }
.td-sheet::before { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none; background-color: var(--accent); opacity: .04; -webkit-mask: var(--jaal) 0 0 / 90px 90px repeat; mask: var(--jaal) 0 0 / 90px 90px repeat; }
.td-sheet > * { position: relative; z-index: 1; }
.td-thread { height: 18px; flex: none; background: var(--accent); opacity: .7; -webkit-mask: var(--bp) repeat-x center / 18px 18px; mask: var(--bp) repeat-x center / 18px 18px; margin-top: 8px; }
.td-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: 8px 22px 4px; }
.td-kick { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font: 800 11.5px var(--f-ui); letter-spacing: .2em; text-transform: uppercase; color: var(--accent); }
.td-deva { font: 400 17px/1 var(--f-deva); letter-spacing: 0; text-transform: none; opacity: .85; }
.td-head h2 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); }
.td-x { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line2); background: var(--surface2); color: var(--text); cursor: pointer; }
.td-x:hover { border-color: var(--accent); color: var(--accent); }

.td-field { position: relative; display: flex; align-items: center; gap: 8px; margin: 12px 22px 0; padding: 6px 8px 6px 16px; border-radius: 18px; background: var(--bg); border: 1px solid var(--line2); transition: border-color .2s, box-shadow .2s; }
.td-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.td-fi { color: var(--accent); font-size: 18px; flex: none; }
.td-field input { flex: 1; min-width: 0; border: 0; background: none; padding: 12px 4px; font: 500 clamp(16px, 2.1vw, 19px)/1.3 var(--f-ui); box-shadow: none; border-radius: 0; }
.td-field input:focus { box-shadow: none; }
.td-field input::placeholder { font-family: var(--f-display); font-style: italic; }
.td-mic { position: relative; flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line2); background: var(--surface2); color: var(--text); cursor: pointer; font-size: 18px; transition: background-color .2s, color .2s, border-color .2s; }
.td-mic:hover { border-color: var(--accent); color: var(--accent); }
.td-mic.on { background: var(--madder); border-color: var(--madder); color: #fff; }
.td-ring { position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--madder); opacity: 0; pointer-events: none; }
.td-mic.on .td-ring { animation: tdRing 1.3s ease-out infinite; }
@keyframes tdRing { 0% { opacity: .8; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.45); } }
.td-listening .td-field { border-color: var(--madder); box-shadow: 0 0 0 4px rgba(168, 50, 42, .18); }
.td-enter { flex: none; }
.td-help { margin: 8px 24px 0; font-size: 12.5px; color: var(--muted); }

.td-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px 22px 18px; }
.td-lab { margin: 14px 0 8px; font: 800 10.5px var(--f-ui); letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.td-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.td-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 9px; border-radius: 999px; border: 1px solid var(--line2); background: var(--surface2); font: 700 12.5px/1.2 var(--f-ui); animation: tdChip .4s var(--ease) both; }
.td-chip:nth-child(2) { animation-delay: .04s; } .td-chip:nth-child(3) { animation-delay: .08s; } .td-chip:nth-child(4) { animation-delay: .12s; } .td-chip:nth-child(5) { animation-delay: .16s; } .td-chip:nth-child(6) { animation-delay: .2s; }
.td-chip i { color: var(--accent); }
.td-chip.td-intent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.td-chip.td-intent i { color: inherit; }
@keyframes tdChip { from { opacity: 0; transform: translateY(6px) scale(.96); } }

.td-card { margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.td-dcard { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 16px; align-items: start; }
.td-dg { width: 104px; }
.td-dg svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 14px 14px rgba(0, 0, 0, .35)); transform-origin: 50% 0; animation: tdSway 4.5s ease-in-out infinite; }
@keyframes tdSway { 0%, 100% { transform: rotate(-1.6deg); } 50% { transform: rotate(1.6deg); } }
.td-dcode { margin: 0 0 2px; font: 800 11px var(--f-ui); letter-spacing: .08em; color: var(--muted); }
.td-dinfo h3 { margin: 0 0 4px; font-size: 1.45rem; }
.td-cw { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin: 0 0 8px; font-size: 13px; font-weight: 700; }
.td-cw .muted { font-weight: 500; }
.td-facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.td-facts div { display: grid; gap: 1px; padding-top: 6px; border-top: 1px dashed var(--line); }
.td-facts dt { font: 800 10px var(--f-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.td-facts dd { margin: 0; font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.td-facts dd small { font-weight: 500; color: var(--muted); }
.td-facts .td-hl dd b { font: 500 1.3rem var(--f-display); color: var(--accent); }
.td-dest { display: flex; gap: 14px; align-items: center; }
.td-dest-ico { width: 50px; height: 50px; flex: none; display: grid; place-items: center; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-size: 22px; }
.td-dest h3 { margin: 0 0 2px; font-size: 1.25rem; }
.td-dest p { margin: 0; font-size: 13.5px; color: var(--muted); }
.td-dest p b { color: var(--text); }
.td-plan > div:first-child { display: grid; gap: 2px; }
.td-date { font: 500 clamp(1.8rem, 4vw, 2.4rem)/1.05 var(--f-display); color: var(--accent); }
.td-plan small { font-size: 12.5px; color: var(--muted); }
.td-stages { list-style: none; margin: 12px 0 8px; padding: 0; display: flex; gap: 3px; }
.td-stages li { min-width: 0; height: 26px; display: flex; align-items: center; padding: 0 6px; border-radius: 6px; background: var(--k, var(--accent)); color: #1d1f27; font: 800 9.5px var(--f-ui); letter-spacing: .04em; text-transform: uppercase; overflow: hidden; transform-origin: left; animation: grow .7s var(--ease) both; }
.td-stages li span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-stages li:nth-child(2) { animation-delay: .08s; } .td-stages li:nth-child(3) { animation-delay: .16s; } .td-stages li:nth-child(4) { animation-delay: .24s; } .td-stages li:nth-child(5) { animation-delay: .32s; } .td-stages li:nth-child(6) { animation-delay: .4s; }
.td-picks { display: flex; gap: 10px; flex-wrap: wrap; }
.td-pick { width: 132px; display: grid; justify-items: center; gap: 2px; padding: 10px; border: 1px solid var(--line2); border-radius: 16px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 12px; transition: border-color .2s, transform .25s var(--ease); }
.td-pick:hover { border-color: var(--accent); transform: translateY(-2px); }
.td-pick span { width: 70px; }
.td-pick span svg { width: 100%; height: auto; display: block; }
.td-pick small { color: var(--muted); text-align: center; }
.td-none { display: flex; gap: 14px; align-items: flex-start; }
.td-none > i { font-size: 26px; color: var(--accent); }
.td-none h3 { margin: 0 0 4px; font-size: 1.2rem; }
.td-none p { margin: 0; font-size: 13.5px; color: var(--muted); }
.td-sugg { display: flex; gap: 8px; flex-wrap: wrap; }
.td-gram h3 { margin: 0 0 8px; font-size: 1.2rem; }
.td-gram ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13px; }
.td-gram b { display: inline-block; min-width: 86px; }
.td-gram code, .td-exb { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; }
.td-gram code { display: inline-block; margin: 2px 2px; padding: 1px 7px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; }
.td-warn, .td-notes { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.td-warn li { color: var(--text); padding: 7px 10px; border-radius: 10px; background: color-mix(in srgb, var(--haldi) 16%, transparent); border: 1px solid color-mix(in srgb, var(--haldi) 40%, transparent); }
html[data-mode="retail"] .td-warn li { background: rgba(181, 101, 45, .1); border-color: rgba(181, 101, 45, .35); }
.td-warn i { color: var(--haldi); }
html[data-mode="retail"] .td-warn i { color: #b5652d; }
.td-notes li { color: var(--muted); }
.td-notes i { color: var(--accent); }
.td-act { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.td-go kbd { margin-left: 4px; color: inherit; background: rgba(0, 0, 0, .12); border-color: rgba(0, 0, 0, .2); }
.td-fine { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); }
.td-done { display: flex; gap: 14px; align-items: flex-start; border-color: var(--accent); animation: tdChip .5s var(--ease) both; }
.td-done > i { font-size: 30px; color: var(--accent); }
.td-done h3 { margin: 0 0 4px; font-size: 1.3rem; }
.td-done p { margin: 0 0 4px; font-size: 13.5px; }
.td-done a { color: var(--accent); font-weight: 800; }

.td-exs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.td-exb { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--line2); background: transparent; color: var(--text); font-size: 13px; text-align: left; cursor: pointer; transition: border-color .2s, background-color .2s; }
.td-exb i { color: var(--accent); }
.td-exb:hover, .td-exb:focus-visible { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.td-exs.more { display: flex; flex-wrap: wrap; }
.td-exs.more .chip { font-weight: 600; }
.td-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 22px 14px; border-top: 1px dashed var(--line2); font-size: 11.5px; color: var(--muted); }
.td-foot i { color: var(--accent); }

@media (max-width: 640px) {
    .td { align-items: flex-end; padding: 0; }
    .td-sheet { width: 100%; max-height: 92svh; border-radius: 24px 24px 0 0; transform: translateY(30px); }
    .td-head { padding: 6px 16px 2px; }
    .td-field { margin: 10px 14px 0; padding-left: 12px; }
    .td-enter, .td-keys { display: none; }
    .td-help { margin: 8px 16px 0; }
    .td.td-has .td-help { display: none; }
    .td-body { padding: 4px 14px 14px; }
    .td-foot { padding: 10px 16px 14px; }
    .td-exs { grid-template-columns: 1fr; }
    .td-dcard { grid-template-columns: 72px minmax(0, 1fr); gap: 12px; }
    .td-dg { width: 72px; }
    .td-facts { grid-template-columns: 1fr; }
    .td-act .btn { width: 100%; }
}
@media print { .td-pill, .td, #tdLive { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
    .td-pill, .td-pill-ico::before, .td-dg svg, .td-mic.on .td-ring, .td-chip, .td-stages li, .td-done { animation: none !important; }
}
