/* Builder UI — monochrome editorial look: white paper, #111 ink, hairline borders, square black
   action buttons with small spaced capitals, grey preview stage, Instrument Sans (Vazirmatn for
   Persian). Light/dark via html[data-theme]; English/Persian via html[dir] (logical properties). */
:root {
  --paper: #fff; --panel: #f7f7f7; --fill: #f3f3f3; --fill-2: #f0f0f0; --stage: #f7f7f7; --page: #fff;
  --ink: #111; --ink-body: #222; --ink-2: #333; --ink-soft: #555; --ink-mute: #767676; --ink-faint: #9a9a9a; --ink-rgb: 17, 17, 17;
  --line: #ebebeb; --line-card: #e3e3e3; --line-btn: #d5d5d5; --line-input: #dbdbdb; --line-row: #efefef;
  --on-ink: #fff; --accent: #0f6bf5; --accent-soft: #e7f0fe; --live: #3e8e4f; --live-soft: #e7f0e9; --danger: #b0382b; --danger-soft: #f8e9e7; --warn: #a9762d; --warn-soft: #f7efe2;
  --shadow-pop: 0 18px 40px -12px rgba(0, 0, 0, .18);
  --brand: linear-gradient(120deg, #7c5cff 0%, #3b82f6 55%, #14b8a6 100%);
  --brand-glow: rgba(91, 92, 255, .16); --fill-btn: rgba(120, 120, 128, .12); --fill-btn-hover: rgba(120, 120, 128, .2);
  --ease: cubic-bezier(.2, .8, .2, 1); --spring: cubic-bezier(.2, .9, .25, 1.1);
  --font: 'Instrument Sans', 'Vazirmatn', 'Helvetica Neue', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  --left-w: 400px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #161616; --panel: #0f0f0f; --fill: #222; --fill-2: #262626; --stage: #0c0c0c; --page: #161616;
  --ink: #f2f2f2; --ink-body: #e4e4e4; --ink-2: #d4d4d4; --ink-soft: #b0b0b0; --ink-mute: #8f8f8f; --ink-faint: #6f6f6f; --ink-rgb: 242, 242, 242;
  --line: #262626; --line-card: #2c2c2c; --line-btn: #3a3a3a; --line-input: #353535; --line-row: #222;
  --on-ink: #111; --accent-soft: #10223f; --live: #5fb873; --live-soft: #15261a; --danger: #e0705f; --danger-soft: #2c1714; --warn: #d6a55a; --warn-soft: #2b2112;
  --shadow-pop: 0 18px 40px -12px rgba(0, 0, 0, .7);
  --brand-glow: rgba(124, 92, 255, .22); --fill-btn: rgba(120, 120, 128, .24); --fill-btn-hover: rgba(120, 120, 128, .34);
  color-scheme: dark;
}
:root[dir="rtl"] { --font: 'Vazirmatn', 'Instrument Sans', system-ui, Tahoma, sans-serif; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { opacity: .45; cursor: default; }
a { color: inherit; }
::selection { background: rgba(var(--ink-rgb), .12); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { min-width: 0; }
input:not([type='checkbox']), select { height: 38px; padding: 0 12px; background: var(--paper); border: 1px solid var(--line-input); border-radius: 8px; outline: none; transition: border-color .15s; }
input:not([type='checkbox']):focus, select:focus, textarea:focus { border-color: var(--ink-soft); }
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input[type='checkbox'] { accent-color: var(--ink); width: 15px; height: 15px; margin: 0; }
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.logo { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; }
:root[dir="rtl"] .flipx, :root[dir="rtl"] .chev { transform: scaleX(-1); }
.spacer { flex: 1; }
.muted { color: var(--ink-mute); } .small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
code { font-family: var(--mono); font-size: .9em; background: var(--fill); padding: 1px 5px; border-radius: 4px; }

/* small spaced capitals for tiny labels (English only — Persian has no case) */
.caps, .grouplabel > span { text-transform: uppercase; letter-spacing: .12em; }
:root[dir="rtl"] .caps, :root[dir="rtl"] .grouplabel > span { text-transform: none; letter-spacing: 0; }

/* buttons — Apple-style: pill shape, sentence case, soft press */
.btn-ink, .btn-line { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 20px; border-radius: 999px; font-size: 14px; font-weight: 500; letter-spacing: -.005em; white-space: nowrap; text-decoration: none; transition: transform .25s var(--spring), background .2s, box-shadow .25s, opacity .2s; -webkit-tap-highlight-color: transparent; }
.btn-ink { background: var(--ink); color: var(--on-ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .18), inset 0 1px 0 rgba(255, 255, 255, .08); }
.btn-ink:hover { transform: translateY(-1px); box-shadow: 0 8px 22px -8px rgba(0, 0, 0, .45), 0 0 0 4px var(--brand-glow); }
.btn-line { background: var(--fill-btn); color: var(--ink); }
.btn-line:hover { background: var(--fill-btn-hover); }
.btn-ink:active, .btn-line:active, .roundbtn:active, .iconbtn:active { transform: scale(.96); transition-duration: .08s; }
.btn-ink:disabled, .btn-line:disabled { transform: none; box-shadow: none; }
.btn-line.off { color: var(--ink-faint); opacity: .6; cursor: not-allowed; }
.btn-ink.sm, .btn-line.sm { height: 32px; padding: 0 14px; font-size: 13px; }
.btn-ink.lg { height: 52px; padding: 0 30px; font-size: 16px; }
.btn-ink.block { width: 100%; height: 50px; font-size: 15px; }
.btn-ink .i, .btn-line .i { width: 16px; height: 16px; }
.iconbtn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 999px; color: var(--ink-soft); transition: background .2s, color .2s, transform .25s var(--spring); position: relative; flex: none; }
.iconbtn:hover { background: var(--fill-btn); color: var(--ink); }
.iconbtn.sm { width: 28px; height: 28px; }
.iconbtn.txt { width: auto; min-width: 34px; padding: 0 10px; font-size: 12.5px; font-weight: 600; }
.roundbtn { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: var(--on-ink); flex: none; transition: transform .25s var(--spring), box-shadow .25s; }
.roundbtn:hover { transform: scale(1.06); box-shadow: 0 0 0 4px var(--brand-glow); }
.roundbtn.stop { background: var(--danger); color: #fff; }
.ulink { font-size: 13px; text-decoration: underline; text-underline-offset: 3px; color: var(--ink); }
.dot { position: absolute; top: 6px; inset-inline-end: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.badge { background: var(--ink); color: var(--on-ink); border-radius: 999px; padding: 0 6px; font-size: 10.5px; line-height: 17px; min-width: 17px; text-align: center; font-weight: 600; }
.badge.warn { background: var(--danger); color: #fff; }
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 999px; background: var(--fill-btn); }
.seg button { height: 28px; min-width: 32px; padding: 0 10px; border-radius: 999px; font-size: 12px; color: var(--ink-mute); display: inline-grid; place-items: center; transition: background .2s, color .2s, box-shadow .2s; }
.seg button.on { background: var(--paper); color: var(--ink); font-weight: 500; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg .i { width: 14px; height: 14px; }
.mark { width: 26px; height: 26px; flex: none; }

/* ================================================================== dashboard */
#app, .dash, .ed { height: 100%; }
.dash { display: grid; grid-template-columns: 260px minmax(0, 1fr); background: var(--page); }
.dside { display: flex; flex-direction: column; gap: 0; padding: 24px 22px; border-inline-end: 1px solid var(--line); overflow-y: auto; }
.dlogo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.02em; padding-inline: 8px; }
.dnav { display: flex; flex-direction: column; align-items: stretch; gap: 4px; margin-top: 40px; }
.dnav a { position: relative; text-decoration: none; font-size: 15px; color: var(--ink-body); display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; transition: background .2s, color .2s; }
.dnav a .i { width: 18px; height: 18px; color: var(--ink-mute); transition: color .2s; }
.dnav a:hover { background: var(--fill-btn); color: var(--ink); }
.dnav a.on { background: var(--paper); color: var(--ink); font-weight: 500; box-shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 0 0 1px var(--line); }
.dnav a.on .i { color: #5b5cff; }
.dnav .count { margin-inline-start: auto; font-size: 11.5px; color: var(--ink-faint); }
.dfoot { margin-top: auto; display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding-top: 24px; }
.dfoot .row { justify-content: space-between; }
.acct { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--panel); }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 14px; background: var(--brand); background-size: cover; background-position: center; overflow: hidden; }
.acct .who { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.acct .who b { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct .who small { font-size: 11.5px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: start; }
.aistat { font-size: 11.5px; font-weight: 500; color: var(--live); display: flex; align-items: center; gap: 7px; padding-inline: 8px; }
.aistat::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 20%, transparent); }
.aistat.off { color: var(--warn); }

.dmain { overflow-y: auto; padding: 64px 40px 90px; position: relative; }
.dmain::before { content: ''; position: absolute; inset: 0 0 auto; height: 420px; pointer-events: none; background: radial-gradient(60% 70% at 50% 0%, var(--brand-glow), transparent 70%); }
.dview { position: relative; max-width: 880px; margin-inline: auto; animation: rise .5s var(--ease) both; }
.dview.center { text-align: center; }
.dtitle { margin: 0; font-size: clamp(30px, 4.4vw, 44px); font-weight: 600; letter-spacing: -.03em; line-height: 1.1; }
:root[dir="rtl"] .dtitle { letter-spacing: 0; line-height: 1.35; font-weight: 700; }
.dsub { margin: 12px auto 34px; color: var(--ink-mute); font-size: 16px; max-width: 560px; }
.panel { background: var(--panel); border-radius: 22px; padding: 16px; text-align: start; }
.herocard { position: relative; background: var(--paper); border-radius: 18px; padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 18px 40px -26px rgba(40, 40, 120, .35); transition: box-shadow .3s; }
.herocard:focus-within { box-shadow: 0 0 0 4px var(--brand-glow), 0 18px 40px -22px rgba(40, 40, 120, .4); }
.pillseg { display: inline-flex; align-self: flex-start; padding: 3px; border-radius: 999px; background: var(--fill-btn); }
.pillseg button { height: 30px; padding: 0 16px; border-radius: 999px; font-size: 13px; color: var(--ink-mute); transition: background .2s, color .2s, box-shadow .2s; }
.pillseg button.on { background: var(--paper); color: var(--ink); font-weight: 500; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
#heroInput { width: 100%; border: 0; background: transparent; resize: none; outline: none; font-size: 17px; line-height: 1.55; min-height: 80px; color: var(--ink); }
.herorow { display: flex; align-items: center; gap: 10px; }
.herorow .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#heroGo { height: 44px; padding: 0 24px; }
.secthead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 54px 0 14px; text-align: start; }
.secthead.top { margin-top: 0; align-items: center; margin-bottom: 26px; }
.secthead h2 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.applist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.applist li { display: flex; align-items: center; gap: 14px; padding: 12px 16px; background: var(--paper); border-radius: 14px; cursor: pointer; transition: transform .3s var(--ease), box-shadow .3s; animation: rise .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); }
.applist li:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -16px rgba(0, 0, 0, .35); }
.applist li.empty { cursor: default; color: var(--ink-mute); justify-content: center; font-size: 13px; }
.applist li.empty:hover { transform: none; box-shadow: none; }
.applist .nm { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: isolate; }
.applist .tg { font-size: 12px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; unicode-bidi: isolate; }
.applist .st { font-size: 12px; color: var(--ink-faint); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.applist .st::before { content: ''; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; }
.applist .st.live { color: var(--live); } .applist .st.live::before { background: currentColor; }
.applist .ago { font-size: 12px; color: var(--ink-faint); white-space: nowrap; min-width: 52px; text-align: end; }
.appicon { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; font-weight: 600; font-size: 14px; color: #fff; background: hsl(var(--h, 220) 55% 45%); background-size: cover; background-position: center; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.appicon.lg { width: 44px; height: 44px; border-radius: 12px; font-size: 18px; }
.search { width: 100%; max-width: 420px; margin-bottom: 16px; border-radius: 999px !important; padding-inline: 16px !important; }
.examples { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; text-align: start; }
.examples button { display: flex; flex-direction: column; align-items: stretch; text-align: start; padding: 0; border-radius: 18px; overflow: hidden; background: var(--paper); border: 1px solid var(--line-card); transition: transform .35s var(--ease), box-shadow .35s, border-color .3s; animation: rise .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms); }
.examples button:hover { transform: translateY(-4px); border-color: transparent; box-shadow: 0 18px 36px -20px rgba(40, 40, 120, .4); }
.examples .em { display: grid; place-items: center; height: 100px; font-size: 40px; background: var(--panel); transition: transform .4s var(--spring); }
.examples button:hover .em { transform: scale(1.06); }
.examples .tt { padding: 12px 14px 2px; font-weight: 600; font-size: 14px; }
.examples .ds { padding: 0 14px 14px; font-size: 12px; color: var(--ink-mute); line-height: 1.45; }

/* agent page */
.agcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; text-align: start; }
.agcard { position: relative; padding: 22px; border-radius: 22px; background: var(--paper); border: 1px solid var(--line-card); display: flex; flex-direction: column; gap: 12px; overflow: hidden; transition: transform .35s var(--ease), box-shadow .35s; }
.agcard:hover { transform: translateY(-2px); box-shadow: 0 18px 36px -22px rgba(0, 0, 0, .3); }
.agcard::after { content: ''; position: absolute; inset: auto -40% -60% auto; width: 220px; height: 220px; border-radius: 50%; background: var(--agc); opacity: .12; filter: blur(30px); }
.agcard.tg { --agc: #2aabee; } .agcard.bl { --agc: #19a17a; }
.aglogo { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: #fff; background: var(--agc); }
.aglogo .i { width: 24px; height: 24px; }
.agcard h3 { margin: 0; font-size: 18px; font-weight: 600; }
.agcard p { margin: 0; color: var(--ink-mute); font-size: 13.5px; line-height: 1.5; min-height: 2.6em; }
.agcard .btn-ink { align-self: flex-start; }
.agstate { font-size: 12px; color: var(--live); display: inline-flex; align-items: center; gap: 6px; }
.agstate.off { color: var(--ink-faint); }
.aghow { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; counter-reset: h; text-align: start; }
.aghow li { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; color: var(--ink-soft); line-height: 1.5; }
.aghow li::before { counter-increment: h; content: counter(h); flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #fff; background: var(--brand); }

/* ================================================================== editor */
.ed { display: flex; flex-direction: column; background: var(--paper); position: relative; }
.edhead { height: 56px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 16px 0 14px; border-bottom: 1px solid var(--line); background: var(--paper); position: relative; z-index: 20; }
.appcard { display: flex; align-items: center; gap: 10px; min-width: 0; width: 280px; padding: 5px 12px 5px 6px; border: 1px solid var(--line-card); border-radius: 9px; background: var(--paper); transition: border-color .15s; }
.appcard:hover, .appcard:focus-within { border-color: var(--ink); }
.appcard .appicon { width: 28px; height: 28px; border-radius: 7px; font-size: 12px; }
.appmeta { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
#projectName { height: auto; padding: 0; border: 0; background: transparent; font-size: 13.5px; font-weight: 500; width: 100%; border-radius: 0; }
.appurl { font-size: 10.5px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: start; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; }
.status.live { color: var(--live); } .status.live::before { background: currentColor; }
#publish .cnt { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; background: var(--on-ink); color: var(--ink); font-size: 10px; letter-spacing: 0; }

.edbody { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--left-w) minmax(0, 1fr); }
.leftcol { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; background: var(--paper); border-inline-end: 1px solid var(--line); }
.ltabs { height: 48px; flex: none; display: flex; align-items: stretch; gap: 22px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.ltabs button { position: relative; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-mute); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.ltabs button:hover { color: var(--ink); }
.ltabs button.on { color: var(--ink); font-weight: 500; border-bottom-color: var(--ink); }
.ltabs .dot { position: static; }
.mobonly { display: none !important; }
.lview { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.lview.scroll { overflow-y: auto; }

/* chat */
#messages { flex: 1; overflow-y: auto; padding: 20px 16px 16px; display: flex; flex-direction: column; gap: 14px; scrollbar-width: thin; }
.msg { overflow-wrap: anywhere; unicode-bidi: plaintext; font-size: 14px; }
.msg.user { align-self: flex-end; max-width: 85%; padding: 11px 14px; border-radius: 10px; background: var(--fill); color: var(--ink); white-space: pre-wrap; line-height: 1.5; }
.msg.assistant { align-self: stretch; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink-2); line-height: 1.55; white-space: pre-wrap; }
.msg.assistant::before { content: attr(data-who); display: block; margin: -2px 0 6px; font-size: 13px; font-weight: 700; color: var(--ink); }
.msg.md { white-space: normal; }
.msg.md p { margin: 0 0 7px; } .msg.md p:last-child { margin-bottom: 0; }
.msg.md ul, .msg.md ol { margin: 4px 0 8px; padding-inline-start: 20px; }
.msg.md li { margin: 3px 0; }
.msg.md h4 { margin: 10px 0 4px; font-size: 14px; color: var(--ink); }
.msg.md pre { margin: 6px 0; padding: 8px 10px; background: var(--fill); border-radius: 6px; font: 12px/1.5 var(--mono); white-space: pre-wrap; direction: ltr; text-align: left; }
.msg.md strong { font-weight: 600; color: var(--ink); }
.msg.error { border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); color: var(--danger); }
.msg.tool { align-self: stretch; font: 11px/1.7 var(--mono); color: var(--ink-mute); padding: 6px 12px; border-inline-start: 2px solid var(--line-card); white-space: pre-wrap; direction: ltr; text-align: left; }
.stage { align-self: flex-start; font-size: 9.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-mute); display: inline-flex; align-items: center; gap: 8px; unicode-bidi: plaintext; }
.stage::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); }
.stage.fix { color: var(--warn); } .stage.fix::before { background: var(--warn); }
:root[dir="rtl"] .stage { text-transform: none; letter-spacing: 0; font-size: 12px; }
details.detail { align-self: stretch; font-size: 11px; color: var(--ink-mute); margin-top: -8px; }
details.detail summary { cursor: pointer; width: fit-content; }
details.detail pre { white-space: pre-wrap; margin: 4px 0 0; font-family: var(--mono); background: var(--fill); padding: 8px 10px; border-radius: 6px; direction: ltr; text-align: left; }
.working { align-self: flex-start; font-size: 9.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-mute); display: inline-flex; align-items: center; gap: 8px; }
.working::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
:root[dir="rtl"] .working { text-transform: none; letter-spacing: 0; font-size: 12px; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }
#errorBanner { display: flex; gap: 6px; align-items: center; margin: 0 12px 8px; padding: 6px 6px 6px 12px; border-radius: 8px; background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
#errorText { flex: 1; min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--danger); }

#composer { padding: 8px 12px 12px; flex: none; }
.composer-pill { border: 1px solid var(--line-input); border-radius: 8px; background: var(--paper); padding: 4px 14px 8px; transition: border-color .15s; }
.composer-pill:focus-within { border-color: var(--ink-soft); }
#input { width: 100%; min-height: 36px; max-height: 160px; resize: none; border: 0; outline: none; background: transparent; padding: 8px 0; font-size: 14px; line-height: 1.45; color: var(--ink); field-sizing: content; }
.crow { display: flex; align-items: center; gap: 4px; }
#modelChoice { height: 28px; padding: 0 22px 0 8px; border: 0; border-radius: 8px; background: transparent; font-size: 12.5px; font-weight: 500; cursor: pointer; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-mute) 50%), linear-gradient(135deg, var(--ink-mute) 50%, transparent 50%);
  background-position: calc(100% - 11px) 55%, calc(100% - 7px) 55%; background-size: 4px 4px; background-repeat: no-repeat; }
:root[dir="rtl"] #modelChoice { padding: 0 8px 0 22px; background-position: 11px 55%, 7px 55%; }
#modelChoice:hover { background-color: var(--fill-2); }
.toggle { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; border-radius: 8px; font-size: 12px; color: var(--ink-mute); cursor: pointer; white-space: nowrap; }
.toggle:hover { background: var(--fill-2); }
#micBtn.rec { background: var(--danger); color: #fff; }
.attachrow { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 8px; }
.attachrow .chip { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; padding: 3px 4px 3px 8px; background: var(--fill); border-radius: 6px; }
.attachrow .chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }
.attachrow .chip button { padding: 0 5px; }

.media { align-self: flex-start; display: flex; flex-direction: column; gap: 4px; max-width: 85%; }
.media img { max-width: 220px; max-height: 260px; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; object-fit: cover; }
.media .cap { font-size: 11px; color: var(--ink-faint); }
.shots { align-self: stretch; display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.shots img { height: 150px; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.ask { align-self: stretch; padding: 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); display: flex; flex-direction: column; gap: 10px; }
.ask .q { font-size: 13.5px; font-weight: 700; unicode-bidi: plaintext; }
.ask .opts { display: flex; flex-direction: column; gap: 6px; }
.ask .opts button { text-align: start; padding: 10px 12px; border: 1px solid var(--line-card); border-radius: 8px; font-size: 14px; font-weight: 600; transition: border-color .15s; unicode-bidi: plaintext; }
.ask .opts button:hover { border-color: var(--ink); }
.ask .opts button.else { font-weight: 400; color: var(--ink-mute); border-style: dashed; }

/* App tab */
.appstack { display: flex; flex-direction: column; gap: 14px; padding: 18px 18px 40px; max-width: 460px; width: 100%; margin: 0 auto; }
.rowcard { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 1px solid var(--line-card); border-radius: 10px; background: var(--paper); text-align: start; transition: border-color .15s; }
.rowcard:hover { border-color: var(--ink); }
.rtext { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.35; }
.rtext b { font-size: 13.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: isolate; }
.rtext small { font-size: 11.5px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--ink-faint); width: 14px; height: 14px; }
.statrow { display: flex; gap: 10px; }
.rowcard.stat { flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px 13px; }
.rowcard.stat .big { font-size: 20px; font-weight: 500; }
.rowcard.stat small { font-size: 11.5px; color: var(--ink-faint); }
.grouplabel { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 6px 2px 0; }
.grouplabel > span { font-size: 10.5px; font-weight: 500; letter-spacing: .14em; color: var(--ink-faint); }
.grouplabel small { font-size: 10px; color: var(--ink-faint); }
:root[dir="rtl"] .grouplabel > span { font-size: 12px; }
.group { border: 1px solid var(--line-card); border-radius: 10px; background: var(--paper); overflow: hidden; }
.grow { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: start; transition: background .15s; }
.grow + .grow { border-top: 1px solid var(--line-row); }
.grow:hover { background: color-mix(in srgb, var(--ink) 3%, var(--paper)); }
.grow > .i:first-child { width: 18px; height: 18px; color: var(--ink-soft); margin-inline: 4px 6px; }

/* work area (preview + app pages) */
.work { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--stage); }
.pane { display: none; flex: 1; min-height: 0; flex-direction: column; position: relative; }
.pane.on { display: flex; }
.pvbar { display: flex; align-items: center; gap: 12px; padding: 20px 28px 0; flex-wrap: wrap; position: relative; z-index: 5; }
.pvbar .caps { font-size: 10px; letter-spacing: .16em; font-weight: 500; color: var(--ink-faint); }
:root[dir="rtl"] .pvbar .caps { font-size: 12px; }
.devseg { display: flex; align-items: center; gap: 2px; padding: 2px; background: var(--paper); border: 1px solid var(--line-btn); border-radius: 999px; }
.devseg button { padding: 5px 13px; border-radius: 999px; font-size: 11.5px; color: var(--ink-mute); }
.devseg button.on { background: var(--fill-2); color: var(--ink); font-weight: 500; }
:root[dir="rtl"] .devseg button { font-size: 12.5px; }
.dims { font-size: 10px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
#stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; position: relative; padding: 16px; }
#device { transform-origin: center center; background: var(--paper); position: absolute; left: 50%; top: 50%; box-shadow: 0 0 0 1px rgba(var(--ink-rgb), .1); overflow: hidden; }
#device.phone { border-radius: 26px; }
#device.tablet { border-radius: 18px; }
#device.desktop { border-radius: 10px; }
#frame { display: block; border: 0; background: #fff; width: 100%; height: 100%; }
.histbar { display: flex; gap: 8px; align-items: center; margin: 12px 28px 0; padding: 8px 8px 8px 14px; background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 8px; }
.histbar span { flex: 1; font-size: 13px; }

.panehead { display: flex; align-items: center; gap: 16px; padding: 16px 28px; border-bottom: 1px solid var(--line); background: var(--paper); }
.panehead h2 { margin: 0; font-size: 18px; font-weight: 500; }
.backpv { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-mute); padding: 6px 8px 6px 4px; border-radius: 8px; }
.backpv:hover { background: var(--fill-2); color: var(--ink); }
.padded { padding: 22px 28px 40px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; max-width: 900px; width: 100%; }
.card { background: var(--paper); border: 1px solid var(--line-card); border-radius: 10px; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; scroll-margin-top: 16px; }
.card.flash { animation: flash 1.4s ease; }
@keyframes flash { 0%, 40% { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(var(--ink-rgb), .08); } }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card p { margin: 0; line-height: 1.55; }
.cardhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12px; font-weight: 500; color: var(--ink-mute); }
.settings .row > input:not([type='checkbox']) { flex: 1; min-width: 200px; }
.settings .field input[type='number'] { width: 130px; }
.settings .row > .end { align-self: flex-end; }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.affix { display: flex; align-items: center; border: 1px solid var(--line-input); border-radius: 8px; padding-inline-end: 12px; background: var(--paper); flex: 1; min-width: 240px; }
.affix:focus-within { border-color: var(--ink-soft); }
.affix input { border: 0 !important; flex: 1; }
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cards li { border: 1px solid var(--line-card); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.cards li.muted { border-style: dashed; text-align: center; padding: 16px; font-size: 13px; }
.vtitle { display: flex; justify-content: space-between; gap: 8px; font-weight: 500; overflow-wrap: anywhere; }
.vmsg { color: var(--ink-mute); font-size: 12px; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.vbtns { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 10px; font-weight: 600; color: var(--live); background: var(--live-soft); padding: 1px 8px; border-radius: 3px; text-transform: uppercase; letter-spacing: .06em; align-self: flex-start; white-space: nowrap; }
.tag.pending { color: var(--warn); background: var(--warn-soft); }
:root[dir="rtl"] .tag { text-transform: none; letter-spacing: 0; }
.split { display: grid; grid-template-columns: minmax(170px, 240px) minmax(0, 1fr); flex: 1; min-height: 0; background: var(--paper); }
.filelist { list-style: none; margin: 0; padding: 10px; overflow: auto; border-inline-end: 1px solid var(--line); background: var(--panel); }
.filelist li { padding: 6px 10px; border-radius: 6px; cursor: pointer; font: 12px/1.4 var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist li:hover { background: var(--fill-2); }
.filelist li.on { background: var(--ink); color: var(--on-ink); }
.filelist li.platform { color: var(--ink-faint); }
.code { margin: 0; padding: 16px 20px; overflow: auto; font: 12.5px/1.65 var(--mono); white-space: pre; tab-size: 2; text-align: left; }
.settings .code { border-radius: 8px; border: 1px solid var(--line); background: var(--panel); white-space: pre-wrap; max-height: 360px; }
.rows { overflow: auto; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; align-content: start; grid-auto-rows: max-content; }
.rows > .muted { grid-column: 1 / -1; text-align: center; padding: 40px 0; }
.rows .rowcard2 { border: 1px solid var(--line-card); border-radius: 8px; padding: 10px 12px; background: var(--paper); font: 11.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; position: relative; max-height: 320px; overflow-y: auto; }
.rows .rowcard2 button { position: absolute; top: 8px; right: 8px; font: 500 10.5px var(--font); padding: 3px 9px; border: 1px solid var(--line-btn); background: var(--paper); }
.rows .rowcard2 button:hover { border-color: var(--danger); color: var(--danger); }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 8px; border-bottom: 1px solid var(--line); position: relative; }
.chart.empty .bar { visibility: hidden; }
.chart.empty::after { content: attr(data-empty); position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-faint); font-size: 13px; font-family: var(--font); }
.chart .bar { flex: 1; background: var(--ink); border-radius: 2px 2px 0 0; min-height: 2px; position: relative; opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .bar:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--on-ink); font-size: 11px; padding: 3px 8px; white-space: nowrap; z-index: 2; }

/* version history drawer */
#versionsPanel { position: absolute; top: 56px; inset-inline-end: 0; bottom: 0; width: min(380px, 100%); background: var(--paper); border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; z-index: 30; box-shadow: var(--shadow-pop); }
.vhead { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
#versionList { list-style: none; margin: 0; padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
#versionList li { border: 1px solid var(--line-card); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
#versionList li.live { border-color: color-mix(in srgb, var(--live) 50%, transparent); }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .82); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 10px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(8px); background: var(--ink); color: var(--on-ink); padding: 10px 18px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 70; box-shadow: var(--shadow-pop); }
#toast.show { opacity: 1; transform: translateX(-50%); }
* { scrollbar-color: var(--line-btn) transparent; }

/* ================================================================== small screens */
@media (max-width: 1100px) { :root { --left-w: 360px; } .pvbar { padding: 16px 18px 0; } .padded, .panehead { padding-inline: 18px; } }
@media (max-width: 860px) {
  .dash { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .dside { flex-direction: row; align-items: center; gap: 18px; padding: 12px 16px; border-inline-end: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .dlogo span { display: none; }
  .dnav { flex-direction: row; margin: 0; gap: 18px; }
  .dnav a { font-size: 14px; }
  .dfoot { margin: 0 0 0 auto; margin-inline-start: auto; flex-direction: row; align-items: center; padding: 0; gap: 8px; }
  .aistat { display: none; }
  .dmain { padding: 28px 16px 60px; }
  .herorow .hint { display: none; }
  .applist .tg, .applist .ago { display: none; }

  .edhead { gap: 8px; padding: 0 10px; }
  .edhead > .logo, .status, #edTheme { display: none; }
  .appcard { width: auto; flex: 1; }
  .edbody { grid-template-columns: 1fr; }
  .mobonly { display: inline-flex !important; }
  .leftcol { border: 0; }
  .work { display: none; }
  .ed[data-mpanel="preview"] .leftcol .lview { display: none !important; }
  .ed[data-mpanel="preview"] .leftcol { flex: none; }
  .ed[data-mpanel="preview"] .edbody { grid-template-rows: auto 1fr; }
  .ed[data-mpanel="preview"] .work { display: flex; }
  .pvbar .caps, .dims, #shareBtn { display: none; }
  .split { grid-template-columns: 1fr; grid-template-rows: 150px 1fr; }
  .filelist { border-inline-end: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 480px) {
  #publish { padding: 0 14px; }
  .appurl, #edLang, #versionsBtn { display: none; }
  .devseg button { padding: 5px 10px; }
}

/* ================================================================== soul: softer shapes + motion */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { background-position: -200% 0; } }
input:not([type='checkbox']), select { border-radius: 12px; }
.appcard { border-radius: 14px; }
.composer-pill { border-radius: 18px; padding: 6px 14px 8px; transition: border-color .2s, box-shadow .25s; }
.composer-pill:focus-within { border-color: color-mix(in srgb, #5b5cff 40%, var(--line-input)); box-shadow: 0 0 0 4px var(--brand-glow); }
.card { border-radius: 18px; }
.group, .rowcard, .msg.assistant, .ask, .cards li { border-radius: 14px; }
.msg.user { border-radius: 18px; border-end-end-radius: 6px; }
:root[dir="rtl"] .msg.user { border-end-end-radius: 18px; border-end-start-radius: 6px; }
.msg, .stage, .media, .shots, .ask, .detail { animation: rise .35s var(--ease) both; }
.pane.on > * { animation: fadein .3s var(--ease) both; }
.lview:not([hidden]) { animation: fadein .25s var(--ease) both; }
#device { animation: fadein .45s var(--ease) both; } /* opacity only: the inline transform places it */
.edhead .mark { width: 26px; height: 26px; }
.working { background: linear-gradient(90deg, var(--ink-mute) 0%, var(--ink-mute) 40%, #5b5cff 50%, var(--ink-mute) 60%, var(--ink-mute) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
.working::before { background: var(--brand); }
#toast { border-radius: 999px; padding: 11px 20px; }
#versionsPanel { animation: rise .3s var(--ease) both; }
.grow, .rowcard { transition: background .2s, border-color .2s, transform .25s var(--ease); }
.rowcard:hover { transform: translateY(-1px); }
.grow > .i:first-child { color: #5b5cff; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
@media (max-width: 860px) {
  .dnav { flex-direction: row; margin: 0; gap: 2px; }
  .dnav a { padding: 7px 10px; font-size: 14px; white-space: nowrap; }
  .dnav a .i, .dnav .count, .acct .who, .aistat, #themeSeg { display: none; }
  .dside { overflow-x: auto; scrollbar-width: none; }
  .acct { padding: 0; background: none; }
  .dmain { padding: 34px 16px 70px; }
}