/* ============================================================
   Munshi Whiteboard — styles. Same tokens as the board so it
   feels like one product; nothing here is shared with app.js.
   ============================================================ */
:root {
  --bg: #f6f7fb; --panel: #ffffff; --border: #e6e9ef; --text: #323338;
  --muted: #676879; --brand: #0073ea; --brand-dark: #0060b9;
  --shadow: 0 4px 14px rgba(0,0,0,.08); --sel: #0073ea;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; overflow: hidden; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }
button { font-family: inherit; }

/* ---------- Login ---------- */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: 360px; padding: 32px 28px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.login-card input { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; }
.login-card input:focus { border-color: var(--brand); }
.login-card button { width: 100%; margin-top: 22px; padding: 12px; border: none; border-radius: 8px; background: var(--brand); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.login-err { color: #df2f4a; font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- Top bars ---------- */
.topbar, .ed-top { display: flex; align-items: center; gap: 12px; background: var(--panel); border-bottom: 1px solid var(--border); padding: 10px 18px; height: 54px; }
.topbar .logo { font-weight: 700; font-size: 16px; }
.dot { color: var(--brand); }
.back { color: var(--muted); text-decoration: none; font-weight: 600; padding: 6px 10px; border-radius: 8px; }
.back:hover { background: var(--bg); color: var(--text); }
.who { display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.btn-out, .btn-ghost { background: transparent; border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; color: var(--text); font-weight: 600; }
.btn-out:hover, .btn-ghost:hover { background: var(--bg); }
.btn-primary { background: var(--brand); color: #fff; border: none; border-radius: 8px; padding: 9px 14px; font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: var(--brand-dark); }
.icon-btn { background: transparent; border: none; border-radius: 8px; width: 32px; height: 32px; font-size: 18px; cursor: pointer; color: var(--text); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--bg); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ---------- Boards list ---------- */
#boardsView { height: 100vh; overflow: auto; }
.boards-wrap { max-width: 1100px; margin: 0 auto; padding: 28px 22px; }
.boards-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.boards-head h2 { margin: 0; font-size: 22px; }
#boardSearch { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; width: 220px; font-size: 14px; }
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.bcard { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); cursor: pointer; overflow: hidden; position: relative; transition: transform .1s; }
.bcard:hover { transform: translateY(-2px); border-color: #c9d7f5; }
.bcard .thumb { height: 120px; background: radial-gradient(circle, #d7dbe6 1px, transparent 1px) 0 0/16px 16px, #fbfbfd; position: relative; }
.bcard .thumb .mini { position: absolute; border-radius: 2px; }
.bcard .meta { padding: 12px 14px; }
.bcard .bname { font-weight: 700; font-size: 15px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard .bsub { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.bcard .avs { display: flex; margin-left: auto; }
.bcard .avs .avatar { width: 22px; height: 22px; font-size: 10px; margin-left: -6px; border: 2px solid #fff; }
.bcard .menu { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.9); border-radius: 8px; opacity: 0; }
.bcard:hover .menu { opacity: 1; }
.boards-empty { text-align: center; color: var(--muted); padding: 60px 0; }
.ctx { position: fixed; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 50; min-width: 160px; }
.ctx div { padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.ctx div:hover { background: var(--bg); }
.ctx div.danger { color: #df2f4a; }

/* ---------- Editor chrome ---------- */
#editorView { height: 100vh; display: flex; flex-direction: column; }
.ed-body { flex: 1; position: relative; display: flex; min-height: 0; }
.board-name { border: 1px solid transparent; border-radius: 8px; font-size: 16px; font-weight: 700; padding: 6px 10px; width: 280px; background: transparent; color: var(--text); }
.board-name:hover { border-color: var(--border); }
.board-name:focus { border-color: var(--brand); outline: none; background: #fff; }
.save-state { font-size: 12px; color: var(--muted); min-width: 60px; }
.save-state.err { color: #df2f4a; font-weight: 600; }
.people { display: flex; align-items: center; }
.people .avatar { width: 28px; height: 28px; font-size: 11px; margin-left: -6px; border: 2px solid #fff; }
.hist { display: flex; gap: 2px; margin-left: 6px; }

.tools { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 2px; z-index: 20; }
.tools .tool { width: 40px; height: 40px; border: none; background: transparent; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text); }
.tools .tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tools .tool:hover { background: var(--bg); }
.tools .tool.active { background: #e3efff; color: var(--brand); }
.tools .sep { height: 1px; background: var(--border); margin: 4px 6px; }
.shape-pop { position: absolute; left: 58px; top: 50%; transform: translateY(-50%); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: grid; grid-template-columns: repeat(3, 40px); gap: 4px; }
.shape-pop button { width: 40px; height: 40px; border: none; background: transparent; border-radius: 8px; cursor: pointer; }
.shape-pop button:hover, .shape-pop button.active { background: #e3efff; }
.shape-pop svg { width: 24px; height: 24px; fill: none; stroke: #323338; stroke-width: 1.8; stroke-linejoin: round; }

#canvas { flex: 1; position: relative; overflow: hidden; background-color: #f7f8fc; background-image: radial-gradient(circle, #cfd4e0 1px, transparent 1.2px); touch-action: none; user-select: none; -webkit-user-select: none; cursor: default; }
#canvas.tool-hand { cursor: grab; }
#canvas.panning { cursor: grabbing !important; }
#canvas.tool-sticky, #canvas.tool-text, #canvas.tool-shape, #canvas.tool-frame, #canvas.tool-conn { cursor: crosshair; }
#canvas.tool-pen { cursor: crosshair; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; width: 0; height: 0; }
#itemsLayer, #labelsLayer, #selLayer { position: absolute; left: 0; top: 0; }
#linesLayer { position: absolute; left: 0; top: 0; overflow: visible; width: 1px; height: 1px; z-index: 1000000; pointer-events: none; }
#linesLayer g { pointer-events: auto; }
#labelsLayer { z-index: 1000001; }
#selLayer { z-index: 2000000; pointer-events: none; }
#selLayer .hd { pointer-events: auto; }   /* only the handles catch the mouse; outlines must let clicks reach the card */
#cursorsLayer { position: absolute; inset: 0; pointer-events: none; z-index: 3000000; overflow: hidden; }

/* ---------- Items ---------- */
.it { position: absolute; transform-origin: center center; }
.it .txt { width: 100%; height: 100%; padding: 10px; display: flex; flex-direction: column; justify-content: safe center; overflow: hidden; cursor: inherit; }
.it .tin { width: 100%; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.25; outline: none; min-height: 1em; }
.it .tin[contenteditable="true"] { cursor: text; user-select: text; -webkit-user-select: text; }

.it.editing { z-index: 1500000 !important; }
.it-sticky { box-shadow: 2px 3px 8px rgba(0,0,0,.14); border-radius: 2px; }
.it-sticky .txt { font-family: "Segoe UI", Helvetica, Arial, sans-serif; }
.it-text .txt { height: auto; padding: 4px 6px; justify-content: flex-start; overflow: visible; }
.it-text { min-height: 20px; }
.it-shape svg.shp { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.it-shape .txt { position: relative; text-align: center; }
.it-image img { width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; }
.it-image { border-radius: 2px; overflow: hidden; }
.it-pen svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.it-frame { border: 1px solid #d0d4de; background: #ffffff; border-radius: 4px; }
.it-frame .ftitle { position: absolute; left: 0; bottom: 100%; padding: 2px 6px; font-size: 13px; font-weight: 600; color: #676879; white-space: nowrap; outline: none; margin-bottom: 2px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.it-frame .ftitle[contenteditable="true"] { background: #fff; color: var(--text); }
.it.locked { cursor: not-allowed; }
.lbl { position: absolute; transform: translate(-50%, -50%); background: #fff; padding: 2px 6px; border-radius: 4px; font-size: 13px; white-space: pre; outline: none; min-width: 10px; box-shadow: 0 0 0 1px #e6e9ef; }
.lbl:empty { display: none; }
.lbl.editing:empty { display: block; min-width: 40px; height: 22px; }
#linesLayer .hit { stroke: transparent; fill: none; cursor: pointer; }
#linesLayer .vis { fill: none; }
#linesLayer .head { stroke: none; }
#linesLayer g.selected .vis { filter: drop-shadow(0 0 2px rgba(0,115,234,.9)); }

/* selection */
.sel-out { position: absolute; border: 1px solid var(--sel); pointer-events: none; transform-origin: center center; }
.sel-box { position: absolute; border: 1px solid var(--sel); transform-origin: center center; pointer-events: none; }
.hd { position: absolute; background: #fff; border: 1px solid var(--sel); border-radius: 2px; pointer-events: auto; transform: translate(-50%, -50%); }
.hd.rot { border-radius: 50%; }
.hd.n, .hd.s { cursor: ns-resize; } .hd.e, .hd.w { cursor: ew-resize; }
.hd.ne, .hd.sw { cursor: nesw-resize; } .hd.nw, .hd.se { cursor: nwse-resize; }
.hd.rot { cursor: alias; }
.hd.ep { border-radius: 50%; cursor: move; }
.hd.dot { border-radius: 50%; background: var(--sel); border-color: #fff; cursor: crosshair; opacity: .9; }
.marquee { position: absolute; border: 1px solid var(--sel); background: rgba(0,115,234,.08); pointer-events: none; }
.hover-out { position: absolute; border: 1px solid rgba(0,115,234,.6); pointer-events: none; transform-origin: center center; }

/* floating bar */
#fbar { position: absolute; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; display: flex; align-items: center; gap: 3px; z-index: 30; white-space: nowrap; }
#fbar .fb { height: 30px; min-width: 30px; padding: 0 6px; border: none; background: transparent; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
#fbar .fb:hover { background: var(--bg); }
#fbar .fb.on { background: #e3efff; color: var(--brand); }
#fbar .sw { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); display: inline-block; cursor: pointer; }
#fbar .sw.on { outline: 2px solid var(--brand); outline-offset: 1px; }
#fbar .sw.none { background: linear-gradient(135deg, transparent 45%, #df2f4a 45%, #df2f4a 55%, transparent 55%), #fff; }
#fbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 3px; }
#fbar select { height: 28px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: 13px; }
#fbar .pal { display: flex; gap: 4px; align-items: center; padding: 0 4px; }
.pop { position: absolute; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 8px; z-index: 40; display: grid; grid-template-columns: repeat(6, 24px); gap: 6px; }
.pop .sw { width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); cursor: pointer; }
.pop .sw.none { background: linear-gradient(135deg, transparent 45%, #df2f4a 45%, #df2f4a 55%, transparent 55%), #fff; }

/* zoom + misc */
.zoom { position: absolute; right: 14px; bottom: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); display: flex; align-items: center; padding: 3px; z-index: 20; }
.zoom-lbl { background: transparent; border: none; font-weight: 600; cursor: pointer; padding: 0 8px; min-width: 56px; height: 32px; border-radius: 8px; }
.zoom-lbl:hover { background: var(--bg); }
.readonly { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: #fff4d6; color: #7a5200; border: 1px solid #f3dc9d; padding: 6px 12px; border-radius: 20px; font-weight: 600; z-index: 20; }
.cur { position: absolute; pointer-events: none; transform: translate(-2px, -2px); transition: left .12s linear, top .12s linear; }
.cur svg { width: 18px; height: 18px; display: block; }
.cur .cname { position: absolute; left: 14px; top: 14px; color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 10px; white-space: nowrap; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(30,33,40,.35); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: var(--panel); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.2); width: 440px; max-width: calc(100vw - 32px); padding: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 16px; }
#shareSearch { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; margin-bottom: 10px; }
.share-list { max-height: 340px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.share-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.share-row:last-child { border-bottom: none; }
.share-row .nm { flex: 1; }
.share-row .nm small { display: block; color: var(--muted); }
.share-row select { border: 1px solid var(--border); border-radius: 6px; padding: 5px 6px; background: #fff; }
.share-row.owner .tag { color: var(--muted); font-size: 12px; }
.modal-foot { display: flex; align-items: center; margin-top: 12px; gap: 10px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2229; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 200; box-shadow: var(--shadow); max-width: 80vw; }
#toast.err { background: #b3232f; }

/* ---------- templates ---------- */
.modal-card.wide { width: 860px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; max-height: 70vh; overflow: auto; padding: 2px; }
.tpl { border: 1px solid var(--border); border-radius: 10px; cursor: pointer; overflow: hidden; background: #fff; }
.tpl:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.tpl .prev { height: 110px; background: radial-gradient(circle, #d7dbe6 1px, transparent 1px) 0 0/12px 12px, #fbfbfd; display: flex; align-items: center; justify-content: center; }
.tpl .prev svg { width: 100%; height: 100%; }
.tpl .tn { font-weight: 700; padding: 8px 10px 0; font-size: 13px; }
.tpl .td { color: var(--muted); font-size: 11.5px; padding: 2px 10px 10px; line-height: 1.35; }

/* ---------- comments ---------- */
.it-comment { width: 0 !important; height: 0 !important; transform-origin: 0 100%; z-index: 1200000 !important; }
.it-comment .pin { position: absolute; left: 0; bottom: 0; width: 32px; height: 32px; border-radius: 50% 50% 50% 4px; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.28); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.it-comment .pav { width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.it-comment .pn { position: absolute; top: -6px; right: -8px; background: #e0344b; color: #fff; font-size: 10px; font-weight: 700; border-radius: 9px; padding: 1px 5px; }
.it-comment .pn:empty { display: none; }
.it-comment.resolved .pin { opacity: .45; }
.it-comment.open .pin { outline: 2px solid var(--brand); }
#canvas.tool-comment { cursor: copy; }
#cpop { position: absolute; width: 320px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); z-index: 45; display: flex; flex-direction: column; max-height: 420px; }
#cpop .ch { display: flex; align-items: center; gap: 6px; padding: 8px 8px 6px 12px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
#cpop .ch b { color: var(--text); }
#cpop .cm { overflow: auto; padding: 6px 12px; flex: 1; }
#cpop .msg { display: flex; gap: 8px; padding: 6px 0; }
#cpop .msg .avatar { width: 24px; height: 24px; font-size: 10px; flex: none; }
#cpop .msg .mb { flex: 1; min-width: 0; }
#cpop .msg .mn { font-size: 12px; font-weight: 700; }
#cpop .msg .mn small { color: var(--muted); font-weight: 400; margin-left: 6px; }
#cpop .msg .mt { font-size: 13px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.35; }
#cpop textarea { margin: 6px 12px 0; border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-family: inherit; font-size: 13px; resize: none; height: 60px; outline: none; }
#cpop textarea:focus { border-color: var(--brand); }
#cpop .cf { display: flex; gap: 6px; padding: 8px 12px 10px; align-items: center; }
#cpop .cf .btn-primary { padding: 6px 12px; font-size: 13px; }
#cpop .cf .btn-ghost { padding: 5px 10px; font-size: 12px; }
#cpop .cf .danger { color: #df2f4a; border-color: transparent; }
#cmtPanel { position: absolute; right: 14px; top: 12px; width: 300px; max-height: calc(100% - 80px); overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 44; }
#cmtPanel .ph { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 700; }
#cmtPanel .ph label { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: auto; display: flex; align-items: center; gap: 4px; }
#cmtPanel .row { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
#cmtPanel .row:hover { background: var(--bg); }
#cmtPanel .row .avatar { width: 24px; height: 24px; font-size: 10px; flex: none; }
#cmtPanel .row .rb { flex: 1; min-width: 0; font-size: 12.5px; }
#cmtPanel .row .rb .rt { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cmtPanel .row .rb .rm { color: var(--muted); font-size: 11px; }
#cmtPanel .row.resolved { opacity: .55; }
#cmtPanel .empty { padding: 18px 12px; color: var(--muted); font-size: 13px; }
/* ---------- minimap ---------- */
#minimap { position: absolute; right: 14px; bottom: 62px; width: 180px; height: 120px; background: rgba(255,255,255,.92); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); z-index: 20; cursor: pointer; }
.bcard .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
