/* Nio · Pissarra */
.board-root { position: relative; height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none; --bd-bg: var(--bg); --bd-blue: #2b5bd8; --chat-w: 360px; --bd-ease: cubic-bezier(.22,1,.36,1); }
.bd { container: stage / inline-size; position: relative; display: block; height: 100%; min-height: 0; overflow: hidden; }
.bd-stage { position: absolute; inset: 0; overflow: hidden; overscroll-behavior: none; touch-action: none; background-color: var(--bg); background-image: radial-gradient(circle, color-mix(in srgb, var(--fg) 16%, transparent) 1px, transparent 1.3px); user-select: none; -webkit-user-select: none; }
.bd-stage.nogrid { background-image: none; }
.bd-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.bd-stage[data-tool="select"] .bd-svg { cursor: default; }
.bd-stage[data-tool="select"] g[data-id] { cursor: move; }
.bd-stage[data-tool="hand"] .bd-svg, .bd-stage.space .bd-svg { cursor: grab; }
.bd-stage.panning .bd-svg { cursor: grabbing; }
.bd-stage[data-tool="text"] .bd-svg { cursor: text; }
.bd-stage[data-tool="eraser"] .bd-svg { cursor: cell; }
.bd-svg .hit { fill: transparent; stroke: none; pointer-events: all; }
.bd-svg .hit.line { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; }
.bd-svg g[data-id] { transition: opacity .15s; }
.bd-svg g.erasing { opacity: .22; }
.bd-svg g.editing text { opacity: 0; }
.bd-selg .selbox { fill: none; stroke: var(--bd-blue); }
.bd-selg .marq { fill: color-mix(in srgb, var(--bd-blue) 7%, transparent); stroke: var(--bd-blue); }
.bd-selg .bindhint { fill: none; stroke: var(--bd-blue); opacity: .45; }
.bd-selg .hdl { fill: #fff; stroke: var(--bd-blue); }
.bd-selg [data-h="nw"], .bd-selg [data-h="se"] { cursor: nwse-resize; }
.bd-selg [data-h="ne"], .bd-selg [data-h="sw"] { cursor: nesw-resize; }
.bd-selg [data-h="n"], .bd-selg [data-h="s"] { cursor: ns-resize; }
.bd-selg [data-h="e"], .bd-selg [data-h="w"] { cursor: ew-resize; }
.bd-selg [data-ep] { cursor: grab; }

.bd .ico { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.bd-bar { position: absolute; z-index: 4; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--border) 80%, transparent); background: color-mix(in srgb, var(--white) 80%, transparent); -webkit-backdrop-filter: blur(16px) saturate(160%); backdrop-filter: blur(16px) saturate(160%); box-shadow: 0 10px 30px -18px color-mix(in srgb, var(--fg) 40%, transparent); }
.bd-bar .sep { width: 1px; align-self: stretch; margin: 6px 4px; background: var(--border); }
.bd-tools { top: 14px; left: 50%; transform: translateX(-50%); transition: transform .34s var(--bd-ease); }
.chat-open .bd-tools { transform: translateX(calc(-50% - var(--chat-w) / 2)); }
.bd .tb, .bd .ib { position: relative; display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 10px; background: none; color: var(--fg); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color .15s, color .15s, transform .12s; }
.bd .ib { width: 34px; height: 34px; }
.bd .tb:hover, .bd .ib:hover { background: color-mix(in srgb, var(--bg-2) 85%, transparent); }
.bd .tb:active, .bd .ib:active { transform: scale(.94); }
.bd .tb[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.bd .tb small { position: absolute; right: 4px; bottom: 2px; font-size: 9px; font-weight: 600; opacity: .5; line-height: 1; }
.bd .ib.danger { color: var(--red); }
.bd .pct { min-width: 54px; height: 34px; border: 0; border-radius: 10px; background: none; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; }
.bd .pct:hover { background: color-mix(in srgb, var(--bg-2) 85%, transparent); }
.bd-zoom { left: 14px; bottom: 14px; }
.bd-right { top: 14px; right: 14px; transition: transform .34s var(--bd-ease); }
.chat-open .bd-right { transform: translateX(calc(-1 * var(--chat-w))); }
.bd .chat-t { width: auto; display: flex; gap: 8px; padding: 0 12px 0 9px; font-size: 13px; font-weight: 600; }
.bd .chat-t .tbbot { --s: 20px; --bw: .15; }
.only-m { display: none !important; }

.bd-menuwrap { position: relative; }
.bd-menu { position: absolute; top: 44px; right: 0; z-index: 8; min-width: 230px; padding: 6px; display: grid; border-radius: 14px; border: 1px solid var(--border); background: color-mix(in srgb, var(--white) 92%, transparent); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); box-shadow: 0 16px 40px -20px color-mix(in srgb, var(--fg) 45%, transparent); animation: bd-pop .16s cubic-bezier(.22,1,.36,1); }
.bd-menu[hidden] { display: none; }
.bd-menu button, .bd-menu label { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 0; border-radius: 9px; background: none; font-size: 13px; font-weight: 500; text-align: left; cursor: pointer; color: var(--fg); }
.bd-menu button:hover, .bd-menu label:hover { background: var(--bg-2); }
.bd-menu .danger { color: var(--red); }
.bd-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 6px; }
.bd kbd { font: 600 10px var(--font); padding: 2px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--white); color: var(--fg-muted); white-space: nowrap; }
@keyframes bd-pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

.bd-style { position: absolute; z-index: 4; left: 14px; top: 70px; width: 216px; padding: 14px; display: grid; gap: 14px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--border) 80%, transparent); background: color-mix(in srgb, var(--white) 84%, transparent); -webkit-backdrop-filter: blur(16px) saturate(160%); backdrop-filter: blur(16px) saturate(160%); box-shadow: 0 10px 30px -18px color-mix(in srgb, var(--fg) 40%, transparent); animation: bd-pop .18s cubic-bezier(.22,1,.36,1); }
.bd-style[hidden] { display: none; }
.bd-style .grp { display: grid; gap: 7px; }
.bd-style .grp > span { font-size: 11px; font-weight: 600; color: var(--fg-muted); }
.bd-style .row { display: flex; gap: 6px; flex-wrap: wrap; }
.bd-style .sw-c { width: 26px; height: 26px; padding: 0; border-radius: 8px; border: 1px solid color-mix(in srgb, var(--fg) 14%, transparent); background: var(--c); cursor: pointer; transition: transform .12s; }
.bd-style .sw-c:hover { transform: scale(1.08); }
.bd-style .sw-c[aria-pressed="true"] { outline: 2px solid var(--fg); outline-offset: 2px; }
.bd-style .sw-c.none { background: linear-gradient(135deg, transparent 45%, var(--red) 46%, var(--red) 54%, transparent 55%), var(--white); }
.bd-style .seg2 { display: flex; padding: 2px; border-radius: 9px; background: var(--bg-2); }
.bd-style .seg2 button { flex: 1; display: grid; place-items: center; height: 28px; border: 0; border-radius: 7px; background: none; font-size: 12px; font-weight: 600; color: var(--fg-muted); cursor: pointer; }
.bd-style .seg2 button[aria-pressed="true"] { background: var(--white); color: var(--fg); }
.bd-style .seg2 i { display: block; width: 20px; border-radius: 2px; background: currentColor; }
.bd-style .acts { gap: 2px; }

.bd-empty { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(380px, calc(100% - 48px)); display: grid; gap: 6px; text-align: center; color: var(--fg-muted); pointer-events: none; }
.bd-empty b { font-size: 17px; font-weight: 600; color: var(--fg); }
.bd-empty[hidden] { display: none; }
.bd-edit { position: absolute; left: 0; top: 0; z-index: 5; margin: 0; padding: 0; border: 0; outline: none; background: transparent; resize: none; overflow: hidden; white-space: pre-wrap; word-break: break-word; caret-color: var(--accent); }

.bd-help { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: color-mix(in srgb, var(--fg) 22%, transparent); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.bd-help[hidden] { display: none; }
.bd-help-in { width: min(820px, 100%); max-height: 100%; overflow: auto; padding: 22px; border-radius: 18px; background: var(--bg); box-shadow: 0 30px 80px -30px color-mix(in srgb, var(--fg) 60%, transparent); animation: bd-pop .2s cubic-bezier(.22,1,.36,1); }
.bd-help header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.bd-help h3 { font-size: 20px; font-weight: 500; letter-spacing: -.04em; }
.bd-help .cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.bd-help dt { font-size: 12px; font-weight: 600; color: var(--fg-muted); margin-bottom: 8px; }
.bd-help dl div { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent); font-size: 13px; }
.bd-help dd { flex: 1; }

.bd-chat { position: absolute; z-index: 6; top: 0; right: 0; bottom: 0; display: flex; flex-direction: column; width: var(--chat-w); min-height: 0; overflow: hidden; border-left: 1px solid var(--border); background: var(--panel); transform: translateX(100%); visibility: hidden; transition: transform .34s var(--bd-ease), visibility 0s linear .34s; }
.chat-open .bd-chat { transform: none; visibility: visible; transition: transform .34s var(--bd-ease), visibility 0s; }
.bd-chat header { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--border); }
.bd-chat .who { display: flex; align-items: center; gap: 10px; }
.bd-chat .hbot { --s: 30px; --bw: .14; }
.bd-chat .who b { display: block; font-size: 15px; font-weight: 600; }
.bd-chat .who small { display: block; font-size: 12px; color: var(--fg-muted); }
.bd-chat .brain { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.bd-chat .brain select { flex: 1; min-width: 0; height: 32px; padding: 0 34px 0 10px; border: 1px solid var(--border); border-radius: 9px; background-color: var(--white); font-size: 13px; color: var(--fg); background-position: right 9px center; }
.bd-chat .m .dim { color: var(--fg-muted); font-size: 12px; }
.bd-chat .msgs { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.bd-chat .m { max-width: 88%; font-size: 14px; line-height: 1.45; animation: bd-msg .28s cubic-bezier(.22,1,.36,1); }
.bd-chat .m.me { align-self: flex-end; padding: 9px 13px; border-radius: 16px 16px 4px 16px; background: var(--fg); color: var(--bg); white-space: pre-wrap; }
.bd-chat .m.nio { display: flex; gap: 8px; align-items: flex-end; }
.bd-chat .m.nio > div { padding: 10px 13px; border-radius: 16px 16px 16px 4px; background: var(--white); border: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.bd-chat .m.nio b { font-weight: 600; }
.bd-chat .mav { --s: 24px; --bw: .15; margin-bottom: 4px; }
@keyframes bd-msg { from { opacity: 0; transform: translateY(6px); } }
.bd-chat .chips { flex: none; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 4px 16px 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; scroll-snap-type: x proximity; }
.bd-chat header, .bd-chat .brain, .bd-chat .cin { flex: none; }
.bd-chat .chips::-webkit-scrollbar { display: none; }
.bd-chat .chip-s { flex: none; scroll-snap-align: start; max-width: 260px; box-sizing: border-box; height: 32px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 12px; line-height: 30px; text-align: center; border: 1px solid var(--border); border-radius: 999px; background: var(--white); font-size: 12px; font-weight: 500; cursor: pointer; }
.bd-chat .chip-s:hover { border-color: var(--fg); }
.bd-chat .cin { display: flex; gap: 8px; align-items: flex-end; padding: 12px 14px calc(14px + var(--safe-b, 0px)); border-top: 1px solid var(--border); }
.bd-chat .cin textarea { flex: 1; min-height: 42px; max-height: 140px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--white); resize: none; font: inherit; font-size: 14px; line-height: 1.4; outline: none; }
.bd-chat .cin textarea:focus { border-color: var(--fg); }
.bd-chat .send { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border: 0; border-radius: 12px; background: var(--fg); color: var(--bg); cursor: pointer; }

@media (prefers-reduced-motion: reduce) { .bd *, .bd *::before { animation: none !important; transition: none !important; } }

@media (max-width: 1100px) { .board-root { --chat-w: 320px; } }
@media (max-width: 820px) {
  .board-root { height: calc(100dvh - 56px - var(--safe-t, 0px)); }
  .chat-open .bd-tools, .chat-open .bd-right { transform: none; }
  .bd-tools { top: auto; bottom: calc(12px + var(--safe-b, 0px)); left: 10px; right: 10px; transform: none; overflow-x: auto; scrollbar-width: none; }
  .bd-tools::-webkit-scrollbar { display: none; }
  .bd .tb { width: 40px; height: 40px; flex: none; }
  .bd .tb small { display: none; }
  .bd-zoom { top: 10px; bottom: auto; left: 10px; }
  .bd-zoom [data-bd="zin"], .bd-zoom [data-bd="zout"] { display: none; }
  .bd-right { top: 10px; right: 10px; }
  .bd .chat-t { padding: 0 9px; }
  .bd .chat-t > span:not(.bot) { display: none; }
  .only-m { display: grid !important; }
  .bd-style { display: none; }
  .style-open .bd-style:not([hidden]) { display: grid; left: 10px; right: 10px; top: auto; bottom: calc(70px + var(--safe-b, 0px)); width: auto; grid-template-columns: 1fr 1fr; }
  .bd-help .cols { grid-template-columns: 1fr; }
  .bd-chat { position: absolute; top: auto; left: 0; right: 0; bottom: 0; z-index: 9; width: auto; height: min(78%, 600px); border: 0; border-top: 1px solid var(--border); border-radius: 20px 20px 0 0; transform: translateY(105%); transition: transform .34s var(--bd-ease), visibility 0s linear .34s; box-shadow: 0 -20px 50px -30px color-mix(in srgb, var(--fg) 55%, transparent); }
  .chat-open .bd-chat { transform: none; transition: transform .34s var(--bd-ease), visibility 0s; }
  .bd-chat header::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--border); }
  .bd-empty { top: 42%; }
}

/* El llenç s'adapta a la seva amplada real (tauleta, xat obert, mòbil) */
@container stage (max-width: 720px) {
  .bd-chat { position: absolute; top: auto; left: 0; right: 0; bottom: 0; z-index: 9; width: auto; height: min(78%, 600px); border: 0; border-top: 1px solid var(--border); border-radius: 20px 20px 0 0; transform: translateY(105%); transition: transform .34s var(--bd-ease), visibility 0s linear .34s; box-shadow: 0 -20px 50px -30px color-mix(in srgb, var(--fg) 55%, transparent); }
  .chat-open .bd-chat { transform: none; transition: transform .34s var(--bd-ease), visibility 0s; }
  .bd-chat header::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--border); }
  .chat-open .bd-tools, .chat-open .bd-right { transform: none; }
  .bd-tools { top: auto; bottom: calc(12px + var(--safe-b, 0px)); left: 10px; right: 10px; transform: none; overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
  .bd-tools::-webkit-scrollbar { display: none; }
  .bd .tb { flex: none; }
  .bd .tb small { display: none; }
  .bd-zoom { top: 10px; bottom: auto; left: 10px; }
  .bd-zoom [data-bd="zin"], .bd-zoom [data-bd="zout"] { display: none; }
  .bd-right { top: 10px; right: 10px; }
  .bd .chat-t { padding: 0 9px; }
  .bd .chat-t > span:not(.bot) { display: none; }
  .bd .tb.only-m { display: grid !important; }
  .bd-style { display: none; }
  .style-open .bd-style:not([hidden]) { display: grid; left: 10px; right: 10px; top: auto; bottom: calc(70px + var(--safe-b, 0px)); width: auto; grid-template-columns: 1fr 1fr; }
}
@container stage (max-width: 440px) {
  .bd .tb[data-tool="hand"], .bd .tb[data-tool="line"], .bd .tb[data-bd="lock"] { display: none; }
  .bd .tb { width: 38px; height: 38px; }
  .bd-tools { justify-content: space-between; }
  .style-open .bd-style:not([hidden]) { grid-template-columns: 1fr; max-height: 55%; overflow-y: auto; }
}
@container stage (max-width: 400px) {
  .bd-tools { gap: 0; padding: 3px; left: 6px; right: 6px; }
  .bd-tools .sep { display: none; }
  .bd-tools .tb { flex: 1 1 0; min-width: 30px; width: auto; height: 38px; }
}

/* Xat com a drawer inferior (mòbil, tauleta i llenç estret) */
.bd-scrim { display: none; }
.bd-chat header { position: relative; touch-action: none; cursor: grab; }
.bd-chat.dragging { transition: none !important; }
@media (max-width: 820px) {
  .bd-scrim { display: block; position: absolute; inset: 0; z-index: 8; border: 0; background: color-mix(in srgb, var(--fg) 30%, transparent); opacity: 0; visibility: hidden; transition: opacity .3s, visibility 0s linear .3s; }
  .chat-open .bd-scrim { opacity: 1; visibility: visible; transition: opacity .3s, visibility 0s; }
  .bd-chat { max-width: 640px; margin: 0 auto; }
  .bd-chat header { padding-top: 22px; }
  .bd-chat .msgs { overscroll-behavior: contain; }
  .bd-chat .cin textarea { font-size: 16px; }
  .bd-chat .cin { padding-bottom: calc(12px + var(--safe-b, 0px)); }
}
@container stage (max-width: 720px) {
  .bd-scrim { display: block; position: absolute; inset: 0; z-index: 8; border: 0; background: color-mix(in srgb, var(--fg) 30%, transparent); opacity: 0; visibility: hidden; transition: opacity .3s, visibility 0s linear .3s; }
  .chat-open .bd-scrim { opacity: 1; visibility: visible; transition: opacity .3s, visibility 0s; }
  .bd-chat { max-width: 640px; margin: 0 auto; }
  .bd-chat header { padding-top: 22px; }
  .bd-chat .cin textarea { font-size: 16px; }
}

/* Tàctil: botons còmodes, sense menú de pressió llarga ni selecció */
.bd-stage, .bd-svg { -webkit-touch-callout: none; }
@media (pointer: coarse) {
  .bd .ib, .bd .pct { height: 40px; }
  .bd .ib { width: 40px; }
  .bd .pct { min-width: 52px; font-size: 13px; }
  .bd .tb { width: 44px; height: 44px; }
  .bd .chat-t { height: 44px; }
  .bd-menu { top: 50px; min-width: 250px; }
  .bd-menu button, .bd-menu label { padding: 13px 12px; font-size: 15px; }
  .bd-style .sw-c { width: 34px; height: 34px; }
  .bd-style .seg2 button { height: 36px; }
  .bd-chat .chip-s { height: 38px; line-height: 36px; font-size: 13px; }
  .bd-chat .send { width: 46px; height: 46px; }
}
@media (pointer: coarse) and (max-width: 820px) {
  .bd-zoom [data-bd="zin"], .bd-zoom [data-bd="zout"] { display: none; }
  .bd-tools { gap: 0; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
  .bd .tb { scroll-snap-align: center; }
}
@container stage (max-width: 440px) {
  .bd .tb { width: 40px; height: 44px; }
  .bd-zoom { max-width: calc(100% - 128px); }
}
@container stage (max-width: 400px) {
  .bd-tools .tb { min-width: 34px; height: 44px; }
}

/* Teclat obert: el xat puja per damunt del teclat */
@media (max-width: 820px) {
  .bd-chat { bottom: var(--kb, 0px); transition: transform .34s var(--bd-ease), bottom .2s, visibility 0s linear .34s; }
  .chat-open .bd-chat { transition: transform .34s var(--bd-ease), bottom .2s, visibility 0s; }
  .bd-chat.dragging { transition: none !important; }
}
@container stage (max-width: 720px) {
  .bd-chat { bottom: var(--kb, 0px); height: min(78%, 600px, calc(100% - var(--kb, 0px) - 8px)); }
}

/* Mòbil en horitzontal: poc d'alçada */
@media (max-height: 480px) and (max-width: 940px) {
  .bd-chat { height: min(92%, 600px); }
  .bd-tools { bottom: calc(6px + var(--safe-b, 0px)); left: auto; right: auto; max-width: calc(100% - 20px); }
  .bd-tools { left: 50%; transform: translateX(-50%); }
  .bd .tb { height: 40px; }
  .style-open .bd-style:not([hidden]) { bottom: calc(58px + var(--safe-b, 0px)); max-height: calc(100% - 130px); overflow-y: auto; grid-template-columns: repeat(2, 1fr); }
  .bd-help-in { padding: 14px; }
  .bd-empty { display: none; }
}

