/* Artemii artifact panel. All styling lives here (CSP: style-src 'self').
   Uses the app theme variables (--bg, --panel, --text, --muted, --border, --accent ...) with fallbacks; light + dark via light-dark(). */

.af-root {
  --af-bg: var(--bg, light-dark(#ffffff, #121211));
  --af-chrome: var(--panel, light-dark(#faf9f5, #161614));
  --af-soft: var(--bg-soft, light-dark(#f4f4f2, #1a1a18));
  --af-soft2: var(--bg-soft2, light-dark(#eaeae6, #242422));
  --af-text: var(--text, light-dark(#0a0a0a, #f3f3f2));
  --af-muted: var(--muted, light-dark(#5f5f5a, #a5a59e));
  --af-border: var(--border, light-dark(#e4e4e0, #2f2f2c));
  --af-accent: var(--accent, #ffa800);
  --af-accent-text: var(--accent-text, light-dark(#8f5500, #ffa800));
  --af-ring: var(--focus, light-dark(#b36b00, #ffa800));
  --af-accent-soft: var(--accent-soft, light-dark(rgba(255, 168, 0, 0.16), rgba(255, 168, 0, 0.14)));
  --af-danger: var(--danger, light-dark(#c4262e, #ff7b7f));
  --af-danger-bg: var(--danger-bg, light-dark(#fdecec, #2d1416));
  --af-warn-bg: var(--warn-bg, light-dark(#fff4d9, #2b2208));
  --af-ok: var(--ok, light-dark(#1e7a3a, #6fd593));
  --af-ok-bg: var(--ok-bg, light-dark(#e4f4e9, #12301d));
  --af-code-bg: light-dark(#fbfbf9, #151514);
  --af-shadow: light-dark(0 1px 2px rgba(10, 10, 10, 0.06), 0 1px 2px rgba(0, 0, 0, 0.5));
  --af-pop-shadow: light-dark(0 1px 2px rgba(10, 10, 10, 0.06), 0 1px 2px rgba(0, 0, 0, 0.5)), light-dark(0 12px 32px rgba(10, 10, 10, 0.14), 0 12px 32px rgba(0, 0, 0, 0.55));
  --af-font: var(--font, "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
  --af-mono: var(--mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  --af-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  /* syntax colours (>= 4.5:1 on the code background in both themes) */
  --hl-k: light-dark(#8b3fbf, #d2a8ff);
  --hl-s: light-dark(#1a7f4b, #7ee0a4);
  --hl-n: light-dark(#a85400, #ffb86b);
  --hl-c: light-dark(#667085, #8b949e);
  --hl-f: light-dark(#1d5fd1, #7cb7ff);
  --hl-t: light-dark(#0e7490, #5fd4e6);
  --hl-a: light-dark(#8a4a14, #e5b27a);
  --hl-v: light-dark(#b4233c, #ff8f9d);
  --hl-m: light-dark(#6b48c8, #b9a3ff);
  --hl-g: light-dark(#bf1f58, #ff8fb1);
  --hl-o: light-dark(#5f5f5a, #a5a59e);

  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--af-bg);
  color: var(--af-text);
  border-left: 1px solid var(--af-border);
  font: 400 13.5px/1.5 var(--af-font);
  -webkit-font-smoothing: antialiased;
}
:root[data-theme="dark"] .af-root, :root.dark .af-root, :root.theme-dark .af-root { color-scheme: dark; }
:root[data-theme="light"] .af-root, :root.light .af-root, :root.theme-light .af-root { color-scheme: light; }
.af-root *, .af-root *::before, .af-root *::after { box-sizing: border-box; }
.af-root [hidden] { display: none !important; }
.af-root :focus-visible { outline: 2px solid var(--af-ring); outline-offset: 2px; border-radius: 8px; }
.af-root button { font: inherit; color: inherit; }

.af-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; container: afp / inline-size; position: relative; }

/* ---- resizer (left edge) ---- */
.af-resizer { position: absolute; left: 0; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 6; touch-action: none; }
.af-resizer::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: transparent; transition: background 0.15s; }
.af-resizer:hover::after, .af-resizer:focus-visible::after, .af-resizing .af-resizer::after { background: var(--af-accent); }
.af-resizer:focus-visible { outline: none; }
.af-resizing { user-select: none; }
.af-resizing iframe { pointer-events: none; }

/* ---- full screen + mobile sheet ---- */
.af-root.af-full { position: fixed; inset: 0; width: 100% !important; max-width: none !important; height: 100%; z-index: 80; border-left: 0; }
.af-root.af-mobile { position: fixed; inset: 0; width: 100% !important; max-width: none !important; height: 100%; z-index: 70; border-left: 0; }
.af-mobile .af-panel { padding-top: env(safe-area-inset-top); }
.af-mobile .af-ask { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.af-mobile .af-btn-icon { width: 40px; height: 40px; }
.af-mobile .af-tabrow { height: 48px; }
.af-mobile .af-tab { height: 40px; }
.af-mobile .af-tab-close { width: 28px; height: 28px; opacity: 1; }
.af-mobile .af-seg-btn { height: 34px; }
.af-mobile .af-btn-text-sm { height: 36px; }

/* ---- buttons ---- */
.af-btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; height: 32px; padding: 0 0.75rem; border-radius: 8px; border: 1px solid var(--af-border); background: transparent; color: var(--af-text); font-weight: 500; font-size: 13px; line-height: 1; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background 0.12s, color 0.12s, border-color 0.12s; }
.af-btn:hover { background: var(--af-soft2); }
.af-btn:disabled, .af-btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.af-btn-icon { width: 32px; padding: 0; border-color: transparent; color: var(--af-muted); }
.af-btn-icon:hover { color: var(--af-text); }
.af-btn-icon[aria-pressed="true"] { background: var(--af-accent-soft); color: var(--af-accent-text); }
.af-btn-text-sm { height: 28px; padding: 0 0.6rem; font-size: 12.5px; }
.af-btn-primary { background: var(--af-accent); border-color: var(--af-accent); color: #0a0a0a; font-weight: 600; }
.af-btn-primary:hover { background: color-mix(in srgb, var(--af-accent) 88%, white); }
.af-btn-danger { background: var(--af-danger); border-color: var(--af-danger); color: light-dark(#fff, #1a0507); font-weight: 600; }
.af-btn-danger:hover { background: var(--af-danger); filter: brightness(1.08); }
.af-ico { flex: none; }

/* ---- segmented ---- */
.af-seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--af-soft2); border-radius: 10px; }
.af-seg-btn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border: 0; border-radius: 8px; background: transparent; color: var(--af-muted); font-weight: 500; font-size: 12.5px; cursor: pointer; transition: background 0.12s, color 0.12s; }
.af-seg-btn:hover { color: var(--af-text); }
.af-seg-btn.on { background: var(--af-bg); color: var(--af-text); box-shadow: var(--af-shadow); }
.af-seg-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- tab row ---- */
.af-tabrow { display: flex; align-items: stretch; height: 42px; flex: none; padding: 0 6px 0 8px; gap: 4px; background: var(--af-chrome); border-bottom: 1px solid var(--af-border); }
.af-tabs-slot { flex: 1; min-width: 0; display: flex; }
.af-tablist { display: flex; align-items: stretch; gap: 2px; min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain; }
.af-tablist.overflow { mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); }
.af-tablist::-webkit-scrollbar { display: none; }
.af-tabwrap { position: relative; display: flex; align-items: center; flex: 0 0 auto; max-width: 210px; }
.af-tab { display: flex; align-items: center; gap: 7px; height: 32px; min-width: 0; padding: 0 30px 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--af-muted); font-weight: 500; font-size: 12.5px; cursor: pointer; }
.af-tab:hover { background: var(--af-soft2); color: var(--af-text); }
.af-tabwrap.active .af-tab { color: var(--af-text); }
.af-tabwrap.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; border-radius: 2px 2px 0 0; background: var(--af-accent); }
.af-tab-ico { display: inline-flex; flex: none; }
.af-tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-tab-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--af-accent); }
.af-tab-dot.live { animation: af-pulse 1.3s ease-in-out infinite; }
.af-tab-dot.dirty { background: var(--af-accent-text); }
.af-tab-close { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--af-muted); cursor: pointer; opacity: 0; transition: opacity 0.12s; }
.af-tabwrap:hover .af-tab-close, .af-tabwrap.active .af-tab-close, .af-tab-close:focus-visible { opacity: 1; }
.af-tab-close:hover { background: var(--af-soft2); color: var(--af-text); }
.af-tabrow-actions { display: flex; align-items: center; flex: none; gap: 0; }
.af-tabrow > .af-back { align-self: center; margin-left: -4px; }
.af-tabrow-actions .af-btn { align-self: center; }

/* ---- header ---- */
.af-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 10px 8px 14px; flex: none; min-height: 50px; }
.af-head-main { display: flex; align-items: center; gap: 9px; flex: 1 1 200px; min-width: 0; }
.af-title-ico { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--af-accent-soft); color: var(--af-accent-text); }
.af-title { margin: 0; min-width: 0; font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-badge { flex: none; padding: 2px 6px; border-radius: 6px; background: var(--af-soft2); font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--af-muted); }
.af-writing { display: inline-flex; flex: none; align-items: center; gap: 6px; font-size: 12px; color: var(--af-accent-text); font-weight: 500; }
.af-writing i { width: 6px; height: 6px; border-radius: 50%; background: var(--af-accent); animation: af-pulse 1.2s ease-in-out infinite; }
.af-head-actions { display: flex; align-items: center; gap: 2px; flex: none; margin-left: auto; }
.af-editbtn { margin: 0 4px 0 2px; }

/* version menu */
.af-menuwrap { position: relative; }
.af-menubtn { gap: 6px; padding: 0 8px 0 10px; height: 30px; font-size: 12.5px; color: var(--af-muted); border-color: var(--af-border); margin-right: 6px; }
.af-menubtn:hover { color: var(--af-text); }
.af-menubtn:disabled { opacity: 1; color: var(--af-muted); background: transparent; pointer-events: none; }
.af-menubtn[aria-expanded="true"] { background: var(--af-soft2); color: var(--af-text); }
.af-menubtn:disabled .af-ico { opacity: 0.35; }
.af-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 290px; max-height: 320px; overflow: auto; padding: 4px; background: var(--af-bg); border: 1px solid var(--af-border); border-radius: 12px; box-shadow: var(--af-pop-shadow); }
.af-menuitem { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.af-menuitem:hover, .af-menuitem:focus-visible { background: var(--af-soft2); outline: none; }
.af-menuitem.on { font-weight: 600; }
.af-menuitem-main { flex: 1; white-space: nowrap; }
.af-menuitem-hint { color: var(--af-muted); font-size: 12px; font-weight: 400; white-space: nowrap; }

/* ---- bar (view toggle + edit) ---- */
.af-bar { display: flex; align-items: center; gap: 8px; padding: 2px 14px 10px; flex: none; border-bottom: 1px solid var(--af-border); min-height: 0; }
.af-bar.empty { display: none; }
.af-bar-spacer { flex: 1; }
.af-edit-group { display: flex; align-items: center; gap: 6px; }
.af-dirty-note { font-size: 12px; color: var(--af-muted); font-weight: 500; }
.af-dirty-note.dirty { color: var(--af-accent-text); }

/* ---- notices ---- */
.af-banners:empty { display: none; }
.af-notice { display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 12.5px; border-bottom: 1px solid var(--af-border); background: var(--af-soft); }
.af-notice > span { flex: 1; min-width: 0; }
.af-notice.error { background: var(--af-danger-bg); color: var(--af-danger); }
.af-notice.old { background: var(--af-warn-bg); }
.af-notice.info { background: var(--af-ok-bg); color: var(--af-ok); }
.af-notice .af-btn { color: var(--af-text); }

/* ---- panes ---- */
.af-panes { flex: 1; min-height: 0; position: relative; display: flex; }
.af-pane { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; outline: none; }
.af-view { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; position: relative; }
.af-fill { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.af-view-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 10px; padding: 6px 10px 6px 14px; min-height: 40px; flex: none; border-bottom: 1px solid var(--af-border); background: var(--af-chrome); }
.af-view-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.af-lang { font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em; color: var(--af-muted); }
.af-note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; font-size: 12.5px; color: var(--af-muted); background: var(--af-soft); border-bottom: 1px solid var(--af-border); }

.af-empty, .af-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 32px; text-align: center; color: var(--af-muted); }
.af-empty p, .af-state p { margin: 0; }
.af-state { flex: 1; }
.af-state-title { font-weight: 600; color: var(--af-text); font-size: 15px; }
.af-state-msg { max-width: 34ch; margin-bottom: 8px !important; }

.af-skel { padding: 24px 6px; }
.af-skel i { display: block; height: 12px; margin: 16px 20px; border-radius: 6px; background: linear-gradient(90deg, var(--af-soft2), var(--af-soft), var(--af-soft2)); background-size: 200% 100%; animation: af-shimmer 1.4s linear infinite; }
.af-skel i:nth-child(1) { width: 48%; height: 20px; }
.af-skel i:nth-child(2) { width: 88%; }
.af-skel i:nth-child(3) { width: 76%; }
.af-skel i:nth-child(4) { width: 82%; }
.af-skel i:nth-child(5) { width: 54%; }

.af-spinner { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--af-border); border-top-color: var(--af-muted); animation: af-spin 1.5s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite; }
.af-overlay { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px; text-align: center; background: var(--af-bg); color: var(--af-muted); font-size: 13px; }
.af-overlay strong { color: var(--af-text); font-size: 14px; font-weight: 600; }
.af-overlay-err { color: var(--af-danger); }
.af-overlay-wait { background: var(--af-soft); }
.af-overlay-wait .af-ico { color: var(--af-accent-text); }

/* ---- code ---- */
.af-view-code { background: var(--af-code-bg); }
.af-code { flex: 1; min-height: 0; overflow: auto; padding: 10px 0 24px; font: 12.5px/1.65 var(--af-mono); tab-size: 2; color: var(--af-text); }
.af-code-lines { counter-reset: ln; min-width: max-content; padding-right: 18px; }
.af-view-code.wrap .af-code-lines { min-width: 0; }
.af-ln { display: block; white-space: pre; counter-increment: ln; min-height: 1.65em; }
.af-view-code.wrap .af-ln { white-space: pre-wrap; overflow-wrap: anywhere; padding-left: 4.4em; text-indent: -4.4em; }
.af-view-code.wrap .af-ln::before { text-indent: 0; }
.af-ln::before { content: counter(ln); display: inline-block; position: sticky; left: 0; width: 3.4em; margin-right: 1em; padding-right: 0.9em; text-align: right; color: var(--af-muted); opacity: 0.8; background: var(--af-code-bg); user-select: none; -webkit-user-select: none; font-variant-numeric: tabular-nums; }
.af-view-code.wrap .af-ln::before { position: static; }
.af-view-code .af-view-bar { background: var(--af-code-bg); }
.hl-k { color: var(--hl-k); } .hl-s { color: var(--hl-s); } .hl-n { color: var(--hl-n); } .hl-c { color: var(--hl-c); font-style: italic; }
.hl-f { color: var(--hl-f); } .hl-t { color: var(--hl-t); } .hl-a { color: var(--hl-a); } .hl-v { color: var(--hl-v); }
.hl-m { color: var(--hl-m); } .hl-g { color: var(--hl-g); } .hl-o, .hl-p { color: var(--hl-o); }
.hl-h { color: var(--hl-k); font-weight: 700; } .hl-b { font-weight: 700; } .hl-i { font-style: italic; } .hl-l { color: var(--hl-f); text-decoration: underline; text-underline-offset: 2px; }

/* ---- document ---- */
.af-view-doc { background: var(--af-bg); }
.af-doc-scroll { flex: 1; min-height: 0; overflow: auto; padding: 28px 24px 56px; }
.af-doc-page { max-width: 44rem; margin: 0 auto; font-family: var(--af-serif); font-size: 16.5px; line-height: 1.72; color: var(--af-text); overflow-wrap: break-word; }
.af-doc-page .md > :first-child { margin-top: 0; }
.af-doc-page h1, .af-doc-page h2, .af-doc-page h3, .af-doc-page h4 { font-family: var(--af-serif); font-weight: 650; letter-spacing: -0.012em; line-height: 1.25; margin: 1.7em 0 0.55em; }
.af-doc-page h1 { font-size: 1.9em; margin-top: 0.2em; }
.af-doc-page h2 { font-size: 1.4em; }
.af-doc-page h3 { font-size: 1.15em; }
.af-doc-page h4 { font-size: 1em; text-transform: uppercase; letter-spacing: 0.04em; color: var(--af-muted); }
.af-doc-page p { margin: 0 0 1em; }
.af-doc-page ul, .af-doc-page ol { margin: 0 0 1em; padding-left: 1.5em; }
.af-doc-page li { margin: 0.25em 0; }
.af-doc-page li::marker { color: var(--af-muted); }
.af-doc-page blockquote { margin: 1.2em 0; padding: 0.1em 0 0.1em 1.1em; border-left: 3px solid var(--af-accent); color: var(--af-muted); font-style: italic; }
.af-doc-page hr { border: 0; border-top: 1px solid var(--af-border); margin: 2em 0; }
.af-doc-page a { color: var(--af-accent-text); text-underline-offset: 2px; }
.af-doc-page code { font-family: var(--af-mono); font-size: 0.86em; padding: 0.12em 0.4em; border-radius: 6px; background: var(--af-soft2); }
.af-doc-page pre { margin: 0; padding: 14px 16px; overflow: auto; font-family: var(--af-mono); font-size: 13px; line-height: 1.6; background: var(--af-code-bg); }
.af-doc-page pre code { padding: 0; background: none; font-size: inherit; }
.af-doc-page .code-block { margin: 1.2em 0; border: 1px solid var(--af-border); border-radius: 10px; overflow: hidden; }
.af-doc-page .code-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 14px; background: var(--af-soft); border-bottom: 1px solid var(--af-border); font: 600 11.5px/1 var(--af-font); color: var(--af-muted); }
.af-doc-page .copy-btn { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 8px; border: 0; border-radius: 6px; background: transparent; color: var(--af-muted); cursor: pointer; font: 500 12px var(--af-font); }
.af-doc-page .copy-btn:hover { background: var(--af-soft2); color: var(--af-text); }
.af-doc-page .copy-btn.copied { color: var(--af-ok); }
.af-doc-page .table-wrap { margin: 1.2em 0; overflow: auto; border: 1px solid var(--af-border); border-radius: 10px; }
.af-doc-page table { border-collapse: collapse; width: 100%; font: 400 14px/1.5 var(--af-font); }
.af-doc-page th, .af-doc-page td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--af-border); }
.af-doc-page th { background: var(--af-soft); font-weight: 600; }
.af-doc-page tr:last-child td { border-bottom: 0; }
.af-doc-page .al-right { text-align: right; } .af-doc-page .al-center { text-align: center; }
.af-doc-page .md-plain { white-space: pre-wrap; font-family: var(--af-mono); font-size: 13px; }

/* ---- html / design preview ---- */
.af-html-canvas { flex: 1; min-height: 0; display: flex; justify-content: center; align-items: stretch; background: var(--af-soft); overflow: auto; }
.af-html-frame { width: 100%; min-height: 0; display: flex; background: #fff; }
.af-html-canvas.w-tablet, .af-html-canvas.w-phone { padding: 16px; }
.af-html-canvas.w-tablet .af-html-frame { width: 820px; max-width: 100%; border-radius: 14px; overflow: hidden; box-shadow: var(--af-pop-shadow); }
.af-html-canvas.w-phone .af-html-frame { width: 390px; max-width: 100%; border-radius: 22px; overflow: hidden; box-shadow: var(--af-pop-shadow); }
.af-frame-host { position: relative; width: 100%; height: 100%; min-height: 0; flex: 1; background: #fff; }
.af-iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.af-iframe.hidden { visibility: hidden; }

.af-design-bar .af-tools-l { gap: 6px; }
.af-zoom { display: inline-flex; align-items: center; margin-right: 4px; }
.af-zoom-label { min-width: 56px; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--af-muted); }
.af-stage { flex: 1; min-height: 0; overflow: auto; display: flex; padding: 20px; background: light-dark(#ecece8, #1f1f1d); }
.af-stage.dark { background: #0c0c0c; }
.af-dev-scaler { margin: auto; flex: none; position: relative; }
.af-dev { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #111; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.18); }
.af-dev-screen { position: absolute; left: var(--bezel); top: calc(var(--bezel) + var(--chrome)); overflow: hidden; background: #fff; }
.af-dev-desktop { background: light-dark(#f3f3f1, #2a2a28); border-radius: 12px; border: 1px solid light-dark(#d9d9d4, #3a3a37); }
.af-dev-desktop .af-dev-screen { left: 0; top: var(--chrome); border-radius: 0 0 11px 11px; }
.af-dev-bar { position: absolute; left: 0; right: 0; top: 0; height: var(--chrome); display: flex; align-items: center; gap: 7px; padding: 0 14px; }
.af-dev-bar i { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
.af-dev-bar i:nth-child(2) { background: #febc2e; } .af-dev-bar i:nth-child(3) { background: #28c840; }
.af-dev-url { margin: 0 auto; transform: translateX(-24px); min-width: 220px; max-width: 46%; padding: 3px 14px; border-radius: 7px; background: light-dark(#e6e6e2, #1c1c1a); color: var(--af-muted); font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-dev-phone, .af-dev-tablet { border-radius: 52px; border: 1px solid #333; }
.af-dev-phone .af-dev-screen { border-radius: 42px; }
.af-dev-tablet { border-radius: 34px; }
.af-dev-tablet .af-dev-screen { border-radius: 22px; }
.af-dev-phone.rotated { border-radius: 52px; }
.af-dev-bar, .af-dev-notch { display: none; }
.af-dev-desktop .af-dev-bar { display: flex; }
.af-dev-phone:not(.rotated) .af-dev-notch { display: block; position: absolute; z-index: 3; top: calc(var(--bezel) + 10px); left: 50%; width: 96px; height: 26px; margin-left: -48px; border-radius: 14px; background: #000; pointer-events: none; }
.af-view-design.full { position: fixed; inset: 0; z-index: 90; background: var(--af-bg); }

/* ---- svg ---- */
.af-svg-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.af-svg-stage { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 24px; }
.af-svg-img { display: block; max-width: 100%; max-height: 100%; min-width: 160px; min-height: 120px; object-fit: contain; }
.af-svg-stage.bg-checker { background: conic-gradient(light-dark(#f0f0ec, #1e1e1c) 25%, light-dark(#fff, #262624) 0 50%, light-dark(#f0f0ec, #1e1e1c) 0 75%, light-dark(#fff, #262624) 0) 0 0 / 20px 20px; }
.af-svg-stage.bg-light { background: #fff; }
.af-svg-stage.bg-dark { background: #121211; }

/* ---- sheet ---- */
.af-sheet-meta { display: flex; align-items: center; gap: 12px; min-width: 0; }
.af-cellref { min-width: 36px; padding: 2px 8px; border-radius: 6px; background: var(--af-soft2); font: 600 12px var(--af-mono); text-align: center; }
.af-dims { font-size: 12px; color: var(--af-muted); }
.af-sheet-scroll { flex: 1; min-height: 0; overflow: auto; background: var(--af-bg); }
.af-sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
.af-sheet th, .af-sheet td { border-right: 1px solid var(--af-border); border-bottom: 1px solid var(--af-border); }
.af-sheet th { background: var(--af-chrome); color: var(--af-muted); font-weight: 500; font-size: 12px; }
.af-colh { position: sticky; top: 0; z-index: 2; min-width: 96px; padding: 5px 10px; text-align: center; cursor: pointer; }
.af-corner { position: sticky; top: 0; left: 0; z-index: 4; min-width: 46px; }
.af-rowh { position: sticky; left: 0; z-index: 1; padding: 0 8px; min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; cursor: pointer; }
.af-sheet th.sel { background: var(--af-accent-soft); color: var(--af-text); }
.af-sheet td { padding: 6px 10px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; height: 32px; cursor: cell; background: var(--af-bg); }
.af-sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
.af-sheet tr.af-r0 td { font-weight: 600; background: var(--af-soft); }
.af-sheet td:focus { outline: none; }
.af-sheet td.sel { outline: 2px solid var(--af-ring); outline-offset: -2px; background: var(--af-accent-soft); }
.af-sheet td.editing { padding: 0; overflow: visible; background: var(--af-bg); }
.af-cell-input { display: block; width: 100%; min-width: 150px; height: 31px; padding: 0 10px; border: 0; border-radius: 0; background: var(--af-bg); color: var(--af-text); font: inherit; outline: 2px solid var(--af-ring); outline-offset: -2px; }
.af-more { margin: 12px; }

/* ---- editor ---- */
.af-editor { flex: 1; min-height: 0; display: flex; flex-direction: column; container: afed / inline-size; }
.af-fmtbar { display: flex; align-items: center; gap: 2px; padding: 6px 10px; flex: none; border-bottom: 1px solid var(--af-border); background: var(--af-chrome); }
.af-ed-split { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
.af-ed-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.af-ed-pane + .af-ed-pane { border-left: 1px solid var(--af-border); background: var(--af-bg); }
.af-ed-preview { padding: 0; }
.af-ed-pane.af-doc-scroll { display: block; overflow: auto; padding: 20px 20px 40px; }
.af-ta { display: block; flex: 1; width: 100%; min-height: 0; height: 100%; margin: 0; padding: 14px 16px; border: 0; border-radius: 0; resize: none; background: var(--af-bg); color: var(--af-text); font: 13px/1.65 var(--af-mono); tab-size: 2; outline: none; }
.af-ta:focus-visible { box-shadow: inset 0 0 0 2px var(--af-ring); border-radius: 0; outline: none; }
@container afed (max-width: 640px) {
  .af-ed-split { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .af-ed-pane + .af-ed-pane { border-left: 0; border-top: 1px solid var(--af-border); }
}

/* ---- ask AI ---- */
.af-ask { flex: none; padding: 10px 14px 14px; border-top: 1px solid var(--af-border); background: var(--af-chrome); }
.af-ask-box { display: flex; align-items: flex-end; gap: 6px; padding: 6px 6px 6px 14px; border: 1px solid var(--af-border); border-radius: 14px; background: var(--af-bg); box-shadow: var(--af-shadow); transition: border-color 0.12s, box-shadow 0.12s; }
.af-ask-box:focus-within { border-color: var(--af-ring); box-shadow: 0 0 0 3px var(--af-accent-soft); }
.af-ask-input { flex: 1; min-width: 0; max-height: 120px; padding: 6px 0; border: 0; border-radius: 0; background: transparent; color: var(--af-text); font: 400 13.5px/1.5 var(--af-font); resize: none; outline: none; }
.af-ask-input::placeholder { color: var(--af-muted); }
.af-ask-input:disabled { cursor: not-allowed; }
.af-ask-send { flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--af-accent); color: #0a0a0a; border-color: transparent; }
.af-ask-send:hover { color: #0a0a0a; background: color-mix(in srgb, var(--af-accent) 88%, white); }
.af-ask-send:disabled { background: var(--af-soft2); color: var(--af-muted); opacity: 1; }
.af-ask-note { margin: 6px 4px 0; font-size: 12px; color: var(--af-muted); }

/* ---- dialog ---- */
.af-dialog { width: min(380px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--af-border); border-radius: 16px; background: var(--af-bg); color: var(--af-text); box-shadow: var(--af-pop-shadow); }
.af-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.af-dialog-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.af-dialog-msg { margin: 0 0 18px; color: var(--af-muted); line-height: 1.5; }
.af-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@keyframes af-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.8); } }
@keyframes af-spin { to { transform: rotate(360deg); } }
@keyframes af-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .af-root *, .af-root *::before, .af-root *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .af-spinner { border-top-color: var(--af-border); border-right-color: var(--af-accent); }
}
@container afp (max-width: 600px) {
  .af-design-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .af-design-bar > * { flex: none; }
}
@container afp (max-width: 620px) {
  .af-editbtn .af-btn-text { display: none; }
  .af-editbtn { width: 32px; padding: 0; border-color: transparent; color: var(--af-muted); height: 32px; }
  .af-menubtn { margin-right: 2px; }
  .af-seg-btn { padding: 0 9px; }
}

/* ---- interactive tools: Edit text / Add note ---- */
.af-modes { display: inline-flex; gap: 4px; }
.af-mode-btn[aria-pressed="true"] { background: var(--af-accent-soft); border-color: var(--af-accent); color: var(--af-text); }
.af-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--af-accent); color: #0a0a0a; font: 700 11px/1 var(--af-font); }
.af-pane { position: relative; }
.af-pane.has-insp { flex-direction: column; }
.af-bar { flex-wrap: wrap; row-gap: 6px; }
.af-insp { flex: none; height: 52%; min-height: 210px; display: flex; flex-direction: column; min-width: 0; background: var(--af-chrome); border-top: 1px solid var(--af-border); box-shadow: 0 -6px 18px light-dark(rgba(10, 10, 10, 0.06), rgba(0, 0, 0, 0.35)); position: relative; z-index: 3; }
.af-insp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 4px 14px; }
.af-insp-title { margin: 0; font-size: 13.5px; font-weight: 600; }
.af-insp-body { flex: 1; min-height: 0; overflow: auto; padding: 0 14px 12px; }
.af-insp-hint { margin: 0 0 10px; font-size: 12.5px; color: var(--af-muted); line-height: 1.45; }
.af-insp-empty { margin: 6px 0; font-size: 12.5px; color: var(--af-muted); }
.af-sub { margin: 10px 0 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--af-muted); }
.af-insp-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.af-row { display: flex; align-items: flex-start; gap: 8px; width: 100%; padding: 6px 8px; border: 1px solid var(--af-border); border-radius: 10px; background: var(--af-bg); text-align: left; }
.af-row-pick { cursor: pointer; align-items: center; }
.af-row-pick:hover { border-color: var(--af-accent); }
.af-row-pick.on { border-color: var(--af-accent); background: var(--af-accent-soft); }
.af-row-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-chip { flex: none; min-width: 34px; padding: 2px 6px; border-radius: 6px; background: var(--af-soft2); color: var(--af-muted); font: 600 10.5px/1.5 var(--af-mono); text-align: center; text-transform: lowercase; }
.af-row-input { flex: 1; min-width: 0; padding: 2px 4px; border: 0; border-radius: 6px; background: transparent; color: var(--af-text); font: 400 13.5px/1.45 var(--af-font); resize: none; overflow: hidden; outline: none; }
.af-row:focus-within { border-color: var(--af-ring); box-shadow: 0 0 0 3px var(--af-accent-soft); }
.af-pin { display: inline-flex; flex: none; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--af-accent); color: #0a0a0a; font: 700 11px/1 var(--af-font); }
.af-composer { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; padding: 10px; border: 1px solid var(--af-accent); border-radius: 12px; background: var(--af-bg); }
.af-target { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; }
.af-target-k { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--af-accent-text); }
.af-target-v { color: var(--af-muted); overflow-wrap: anywhere; }
.af-note-input { width: 100%; padding: 8px 10px; border: 1px solid var(--af-border); border-radius: 8px; background: var(--af-bg); color: var(--af-text); font: 400 13.5px/1.45 var(--af-font); resize: vertical; min-height: 64px; outline: none; }
.af-note-input:focus-visible { border-color: var(--af-ring); box-shadow: 0 0 0 3px var(--af-accent-soft); }
.af-composer-actions { display: flex; justify-content: flex-end; gap: 6px; }
.af-whole { margin: 2px 0 6px; }
.af-note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.af-note-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px; border: 1px solid var(--af-border); border-radius: 10px; background: var(--af-bg); }
.af-note-item .af-pin { margin-top: 1px; }
.af-note-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.af-note-target { font-size: 11.5px; color: var(--af-muted); overflow-wrap: anywhere; }
.af-note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.af-note-actions { display: flex; flex: none; }
.af-note-actions .af-btn-icon { width: 28px; height: 28px; }
.af-note-item.applied { opacity: 0.7; } .af-note-item.applied .af-note-text { text-decoration: line-through; }
.af-note-item.applied .af-pin { background: var(--af-ok); color: #fff; }
.af-note-status { font-size: 11.5px; font-weight: 600; color: var(--af-ok); }
.af-note-status.wait { color: var(--af-accent-text); }
.af-insp-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--af-border); background: var(--af-chrome); }
.af-apply { height: 34px; }
/* pins shown on rendered documents and code lines */
[data-pin] { position: relative; }
.af-doc-page [data-pin] { box-shadow: -3px 0 0 var(--af-accent); }
.af-doc-page [data-pin]::before, .af-ln[data-pin]::after { content: attr(data-pin); position: absolute; left: -26px; top: 0.25em; min-width: 18px; height: 18px; border-radius: 9px; background: var(--af-accent); color: #0a0a0a; font: 700 11px/18px var(--af-font); text-align: center; text-indent: 0; }
.af-ln[data-pin]::after { left: auto; right: 6px; }
.af-ln[data-pin] { background: var(--af-accent-soft); }
.af-doc-page .md > *:hover { outline: 1px dashed var(--af-accent); outline-offset: 4px; cursor: pointer; }
.af-pane.has-insp .af-ln { cursor: pointer; }
@container afp (min-width: 900px) {
  .af-pane.has-insp { flex-direction: row; }
  .af-pane.has-insp > .af-view { flex: 1; }
  .af-insp { width: 340px; height: auto; min-height: 0; border-top: 0; border-left: 1px solid var(--af-border); box-shadow: none; }
}
.af-mobile .af-pane.has-insp .af-insp { position: absolute; left: 0; right: 0; bottom: 0; height: auto; max-height: 64%; min-height: 0; border-radius: 16px 16px 0 0; border: 1px solid var(--af-border); border-bottom: 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25); }
.af-mobile .af-insp-head::before { content: ""; position: absolute; left: 50%; top: 6px; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--af-border); }
.af-mobile .af-insp-head { padding-top: 16px; }
.af-mobile .af-row, .af-mobile .af-note-item { padding: 10px; }
@container afp (max-width: 430px) { .af-mode-btn .af-btn-text { display: none; } .af-mode-btn { width: auto; padding: 0 8px; } }
