:root {
  --bg: #0f1218;
  --surface: #171b23;
  --surface-2: #1f2430;
  --border: #2b3140;
  --text: #e7eaf0;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --accent-text: #fff;
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
  --radius: 10px;
  --side-width: 400px;
  font-family: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
code, pre, .mono { font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-variant-ligatures: none; }

input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 12px;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }
.pill { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

/* Lobby */
.lobby { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.lobby-card { width: min(420px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.lobby-card h1 { margin: 0; font-size: 28px; }
.lobby-card p { margin: 0; }
.lobby-card label { display: flex; flex-direction: column; gap: 6px; }
.lobby-card label.check { flex-direction: row; align-items: center; gap: 8px; }
.lobby-card h2 { margin: 0; font-size: 18px; }
.lobby-stack { display: flex; flex-direction: column; gap: 16px; width: min(420px, 100%); }
.lobby-stack .lobby-card { width: 100%; }
.row.between { justify-content: space-between; flex-wrap: wrap; }
.users-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.users-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--surface-2); padding: 6px 10px; border-radius: 8px; }
.user-form { display: flex; flex-direction: column; gap: 8px; }

/* Room layout */
.room {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr var(--side-width);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "stage side";
}
body.wide { --side-width: min(68vw, 1100px); }
.topbar {
  grid-area: top;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.room-title { display: flex; gap: 10px; align-items: center; }

.stage { grid-area: stage; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.videos { flex: 1; min-height: 0; overflow: hidden; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.main-tiles { flex: 1; min-height: 0; display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); align-content: center; }
.main-tiles .tile { aspect-ratio: auto; min-height: 0; }
.strip-tiles { display: flex; gap: 8px; overflow-x: auto; flex: none; height: 110px; }
.strip-tiles .tile { flex: none; width: 180px; height: 100%; aspect-ratio: auto; }
.strip-tiles .tile .avatar { font-size: 24px; }
.videos.speaker .main-tiles .tile video { object-fit: contain; }
body.wide .main-tiles { grid-template-columns: 1fr; }
.pager { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 4px; }
.media-off { margin: auto; max-width: 420px; text-align: center; color: var(--muted); line-height: 1.8; }
.tile .label .quality { margin-inline-start: auto; font-size: 10px; }
.tile .label .quality:empty { display: none; }
.tile {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; border: 2px solid transparent; transition: border-color .15s;
}
.tile.speaking { border-color: var(--ok); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.screen video { object-fit: contain; }
.tile.local:not(.screen) video { transform: scaleX(-1); }
.tile .avatar {
  position: absolute; inset: 0; display: none; place-items: center;
  font-size: 40px; font-weight: 700; background: var(--surface-2);
}
.tile.no-video .avatar { display: grid; }
.tile .label {
  position: absolute; bottom: 8px; right: 8px; left: 8px;
  display: flex; gap: 6px; align-items: center;
  font-size: 12px; text-shadow: 0 1px 2px #000;
}
.tile .label .name { background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 6px; }
.tile .label .state { background: rgba(0,0,0,.55); padding: 2px 6px; border-radius: 6px; }
.tile .label .state:empty { display: none; }
.tile .fullscreen { position: absolute; top: 8px; left: 8px; opacity: 0; background: rgba(0,0,0,.55); border: 0; }
.tile:hover .fullscreen { opacity: 1; }

.controls {
  display: flex; justify-content: center; gap: 10px; padding: 10px;
  border-top: 1px solid var(--border); background: var(--surface);
}
.ctl { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 84px; font-size: 18px; }
.ctl span { font-size: 11px; color: var(--muted); }
.ctl.off { background: var(--danger); border-color: var(--danger); }
.ctl.off span { color: #fff; }
.ctl.on { background: var(--accent); border-color: var(--accent); }
.ctl.on span { color: #fff; }
.ctl.danger { color: var(--danger); }

/* Side panel */
.side {
  grid-area: side; display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border-inline-start: 1px solid var(--border); background: var(--surface);
}
.tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 10px 6px; border-bottom: 2px solid transparent; }
.tab.active { border-bottom-color: var(--accent); color: var(--accent); }
.badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; }
.panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.panel.active { display: flex; }
.composer { padding: 10px; border-top: 1px solid var(--border); }
#panel-tasks .composer { border-top: 0; border-bottom: 1px solid var(--border); }

/* Chat */
.chat-list { list-style: none; margin: 0; padding: 12px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.msg { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; max-width: 90%; align-self: flex-start; }
.msg.mine { align-self: flex-end; background: #233457; }
.msg .meta { font-size: 11px; color: var(--muted); display: flex; gap: 8px; }
.msg .text { white-space: pre-wrap; word-break: break-word; unicode-bidi: plaintext; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; text-align: center; }

/* Task board */
.board { flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 10px; align-items: start; }
.column { background: var(--surface-2); border-radius: 8px; padding: 8px; min-height: 120px; }
.column.drop { outline: 2px dashed var(--accent); }
.column h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.column ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; min-height: 60px; }
.task { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px; cursor: grab; }
.task .title { word-break: break-word; unicode-bidi: plaintext; }
.task .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.task .actions { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.task .actions button { padding: 1px 6px; font-size: 12px; }
.column[data-status="done"] .task .title { text-decoration: line-through; color: var(--muted); }

/* People */
.people { list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.people li { display: flex; justify-content: space-between; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }

/* Repo browser */
#repo-browser { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.rb-head { padding: 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.rb-body { flex: 1; overflow: auto; padding: 10px; }
.rb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rb-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.rb-item:hover { border-color: var(--accent); }
.rb-item .desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.rb-item .meta { color: var(--muted); font-size: 11px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.rb-head .row { flex-wrap: wrap; }
.rb-head select { max-width: 160px; }
.rb-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.rb-tabs button.active { border-color: var(--accent); color: var(--accent); }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; direction: ltr; font-size: 13px; }
.crumbs a { cursor: pointer; text-decoration: none; }
.entries { list-style: none; margin: 0; padding: 0; direction: ltr; }
.entries li { padding: 6px 8px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; justify-content: space-between; }
.entries li:hover { background: var(--surface-2); }
.code { direction: ltr; display: flex; background: #0d1117; border-radius: 8px; overflow: auto; font-size: 12.5px; line-height: 1.55; }
.code pre { margin: 0; padding: 10px; font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, 'DejaVu Sans Mono', monospace; }
.code pre.ln { color: #6e7681; text-align: right; user-select: none; border-right: 1px solid #21262d; }
.code pre.src { flex: 1; text-align: left; background: transparent; overflow: visible; }
.rb-row { direction: ltr; text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
.rb-row .sub { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); margin-inline-end: 4px; }
.tag.pr { border-color: var(--ok); color: var(--ok); }

/* Projects panel extras */
.grow { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.new-project summary { cursor: pointer; color: var(--accent); }
.notice { background: rgba(245, 165, 36, .12); border: 1px solid var(--warn); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.crumbs { margin-bottom: 8px; }
.upload-bar { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; }
.upload-bar .row { flex-wrap: wrap; }
.rb-body.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }
.file-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
a.button { display: inline-block; text-decoration: none; color: inherit; border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 3px 8px; font-size: 12px; }
.rb-row.clickable { cursor: pointer; }
.rb-row.clickable:hover { background: var(--surface-2); }
.rb-row .plain { unicode-bidi: plaintext; }
.viewer-box { position: relative; height: calc(100% - 70px); min-height: 320px; border-radius: 8px; overflow: hidden; background: #0d1117; }

/* Kartable */
.kartable { height: 100%; display: flex; flex-direction: column; }
.kartable .tabs { background: var(--surface); }
.kartable-btn { width: 100%; text-align: center; font-weight: 700; }
.kt-body-wrap { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 420px) 1fr; }
.kt-list { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; border-inline-end: 1px solid var(--border); }
.kt-detail { overflow-y: auto; padding: 16px; }
.kt-item { text-align: start; display: flex; flex-direction: column; gap: 4px; background: var(--surface); }
.kt-item.selected { border-color: var(--accent); }
.kt-item.high { border-inline-start: 3px solid var(--danger); }
.kt-item.unread { border-inline-start: 3px solid var(--accent); font-weight: 600; }
.kt-item .meta, .kt-case .meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--muted); align-items: center; }
.kt-item .text { unicode-bidi: plaintext; }
.kt-empty { text-align: center; margin-top: 30px; }
.kt-case { display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.kt-case h2 { margin: 0; font-size: 18px; }
.kt-case label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.kt-case textarea, .task-edit select, .task-edit input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: inherit; font: inherit; padding: 6px 8px; }
.kt-body { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin: 0; }
.kt-steps { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 8px; border-inline-start: 2px solid var(--border); }
.kt-steps li { font-size: 13px; }
.kt-steps .note { white-space: pre-wrap; color: var(--text); background: var(--surface-2); border-radius: 6px; padding: 4px 8px; margin-top: 2px; }
.kt-act { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.row.wrap { flex-wrap: wrap; }
.tag.kt-referral { border-color: var(--accent); color: var(--accent); }
.tag.kt-approval { border-color: var(--ok); color: var(--ok); }
.tag.kt-p-high, .tag.kt-status-rejected { border-color: var(--danger); color: var(--danger); }
.tag.kt-p-low { color: var(--muted); }
.tag.kt-status-done, .tag.kt-status-approved { border-color: var(--ok); color: var(--ok); }
.danger-btn { border-color: var(--danger); color: var(--danger); }
.kt-approvers { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.kt-chosen .tag button { padding: 0 4px; border: 0; }
.task.high { border-inline-start: 3px solid var(--danger); }
.task-edit { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.approval-badge { font-size: 11px; }
@media (max-width: 860px) { .kt-body-wrap { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } .kt-list { max-height: 40vh; border-inline-end: 0; border-bottom: 1px solid var(--border); } }

/* Lobby room list */
.room-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.room-card { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.room-card.wanted { border-color: var(--accent); }
.room-card .online { font-size: 12px; color: var(--muted); }
.room-card button { align-self: flex-start; }
.tasks-readonly-note { display: none; margin: 0; padding: 8px 10px; font-size: 12px; border-bottom: 1px solid var(--border); }
body.tasks-readonly .tasks-readonly-note { display: block; }
body.tasks-readonly #task-form, body.tasks-readonly .task .actions { display: none; }

/* Project roles and members */
.tag.role-read { border-color: var(--muted); }
.tag.role-write { border-color: var(--ok); color: var(--ok); }
.tag.role-manage { border-color: var(--accent); color: var(--accent); }
.members { display: flex; flex-direction: column; gap: 10px; }
.members .users-list select { padding: 3px 6px; font-size: 12px; }
.add-member { flex-wrap: wrap; }
.add-member select:first-child { flex: 1; min-width: 0; }

/* Viewers */
.viewer-box { display: flex; flex-direction: column; }
.v3d-toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px; background: var(--surface); border-bottom: 1px solid var(--border); }
.v3d-info { margin-inline-start: auto; color: var(--muted); font-size: 12px; }
.v3d-canvas { flex: 1; min-height: 0; position: relative; }
.v3d-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.v3d-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.viewer-box:fullscreen { height: 100vh; }
.native-hint { padding: 16px; line-height: 1.8; background: var(--surface); height: 100%; }
kicanvas-embed { --kc-ui-font: 'Nunito', sans-serif; }

/* Compare */
.cmp-row { flex: 1; min-height: 0; display: flex; gap: 6px; }
.cmp-row > * { flex: 1; min-width: 0; }
.cmp-row figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; overflow: auto; }
.cmp-row figure img, .cmp-row figure canvas { max-width: 100%; height: auto; background: repeating-conic-gradient(#222 0 25%, #2a2a2a 0 50%) 0 0 / 16px 16px; }
.cmp-row figcaption { font-size: 12px; color: var(--muted); }
.cmp-pdf iframe { width: 100%; flex: 1; min-height: 400px; border: 0; background: #fff; }
.cmp-images { flex: 1; min-height: 0; overflow: auto; display: flex; padding: 6px; }
.cmp-pickers { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 12px; }
.cmp-pick { max-width: 280px; font-size: 12px; }
.cmp-box { height: calc(100% - 110px); }
.cmp-flip-label { position: absolute; top: 8px; inset-inline-start: 8px; background: rgba(0,0,0,.6); padding: 2px 8px; border-radius: 6px; font-size: 12px; z-index: 1; }
.cmp-legend { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }
.cmp-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-inline-start: 6px; }
.cmp-legend i.old { background: #ff453a; } .cmp-legend i.new { background: #30d158; } .cmp-legend i.same { background: #e5c000; }
.cmp-gerber .gerber-stack img { mix-blend-mode: screen; opacity: 1; }
.cmp-gerber { background: #000; }
.cmp-summary { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.tag.cmp-added { border-color: var(--ok); color: var(--ok); }
.tag.cmp-removed { border-color: var(--danger); color: var(--danger); }
.tag.cmp-changed { border-color: var(--warn); color: var(--warn); }
.cmp-kicad { overflow: auto; height: 100%; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.cmp-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.cmp-table th, .cmp-table td { border-bottom: 1px solid var(--border); padding: 4px 6px; text-align: start; }
.cmp-table tr.cmp-added td:first-child { color: var(--ok); }
.cmp-table tr.cmp-removed td:first-child { color: var(--danger); }
.cmp-table tr.cmp-changed td:first-child { color: var(--warn); }
.cmp-kicad-side { min-height: 420px; }
.cmp-kicad-side .viewer-box { height: 420px; }
.rb-row .cmp-btn { margin-inline-start: 8px; padding: 1px 6px; font-size: 11px; }
pre.diff { direction: ltr; text-align: left; margin: 0; padding: 8px; background: #0d1117; border-radius: 8px; overflow: auto; font-size: 12.5px; line-height: 1.5; }
pre.diff .add { background: rgba(46, 160, 67, .2); color: #7ee787; }
pre.diff .del { background: rgba(248, 81, 73, .2); color: #ffa198; }
pre.diff .hunk { color: #79c0ff; }
.image-view { max-width: 100%; max-height: 100%; display: block; margin: auto; background: repeating-conic-gradient(#222 0 25%, #2a2a2a 0 50%) 0 0 / 16px 16px; }

/* Gerber */
.gerber-body { flex: 1; min-height: 0; display: flex; }
.gerber-viewport { flex: 1; min-width: 0; overflow: hidden; position: relative; cursor: grab; background: #0b0f14; touch-action: none; }
.gerber-stack { position: absolute; inset: 12px; transform-origin: 0 0; }
.gerber-stack img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none; }
.gerber-stack img + img { opacity: .85; }
.gerber-layers { width: 230px; overflow-y: auto; padding: 8px; border-inline-start: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; font-size: 12px; background: var(--surface); }
.gerber-layers label { display: flex; gap: 6px; align-items: center; }
.gerber-layers .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.gerber-layers .current { color: var(--accent); font-weight: 700; }
.zip-list { max-height: 300px; overflow: auto; background: var(--surface-2); padding: 8px; border-radius: 6px; font-size: 12px; }
@media (max-width: 860px) { .gerber-body { flex-direction: column; } .gerber-layers { width: auto; max-height: 30%; border-inline-start: 0; border-top: 1px solid var(--border); } }

/* 3D comments */
.v3d-canvas.commenting canvas { cursor: crosshair; }
.v3d-pins { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.v3d-pin {
  position: absolute; left: -13px; top: -13px; width: 26px; height: 26px; padding: 0; border-radius: 50% 50% 50% 0;
  background: var(--warn); border: 2px solid #fff; color: #111; font-weight: 700; font-size: 12px; pointer-events: auto;
  box-shadow: 0 2px 6px rgba(0,0,0,.5); display: grid; place-items: center;
}
.v3d-pin.resolved { background: var(--ok); }
.v3d-pin.behind { opacity: .35; }
.v3d-pin.selected { outline: 3px solid var(--accent); }
.v3d-comments {
  position: absolute; top: 8px; bottom: 8px; inset-inline-start: 8px; width: min(300px, 80%); overflow-y: auto;
  background: rgba(23, 27, 35, .96); border: 1px solid var(--border); border-radius: 8px; padding: 8px;
  display: flex; flex-direction: column; gap: 8px; z-index: 2;
}
.v3d-comment { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; background: var(--surface-2); }
.v3d-comment.selected { border-color: var(--accent); }
.v3d-comment.resolved .text { color: var(--muted); }
.v3d-comment .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.v3d-comment .num { background: var(--warn); color: #111; border-radius: 999px; padding: 0 6px; font-weight: 700; }
.v3d-comment.resolved .num { background: var(--ok); }
.v3d-comment .text { margin: 4px 0; white-space: pre-wrap; unicode-bidi: plaintext; }
.v3d-comment .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.v3d-form { position: absolute; width: 250px; display: flex; flex-direction: column; gap: 6px; padding: 8px; z-index: 3;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.v3d-form textarea { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; color: inherit; font: inherit; padding: 6px; resize: vertical; }

/* Toasts */
.toasts { position: fixed; bottom: 16px; left: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; max-width: calc(100vw - 32px); }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.4); }

/* Narrow screens: stack the stage above the side panel */
@media (max-width: 860px) {
  .room {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(240px, 45vh) 1fr;
    grid-template-areas: "top" "stage" "side";
  }
  body.wide .room { grid-template-rows: auto auto 1fr; }
  body.wide .videos { display: none; }
  .side { border-inline-start: 0; border-top: 1px solid var(--border); }
  .topbar { padding: 8px 16px; flex-wrap: wrap; }
  .videos { padding: 8px; }
  .strip-tiles { height: 80px; }
  .strip-tiles .tile { width: 120px; }
  .ctl { min-width: 0; flex: 1; }
  .board { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- Jalali date picker */
.jdate { position: relative; display: inline-flex; }
.jdate-btn { white-space: nowrap; }
.jdate-pop {
  position: absolute; z-index: 50; top: calc(100% + 4px); inset-inline-start: 0;
  width: 260px; padding: 10px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.jdate-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.jdate-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jdate-wd { color: var(--muted); font-size: 12px; padding: 4px 0; }
.jdate-day { padding: 6px 0; border: 0; background: transparent; border-radius: 6px; }
.jdate-day:hover { background: var(--surface-2); }
.jdate-day.today { outline: 1px solid var(--accent); }
.jdate-day.selected { background: var(--accent); color: var(--accent-text); }
.jdate-foot { display: flex; justify-content: space-between; margin-top: 8px; }
.task-edit .jdate, .task-edit .jdate-btn { width: 100%; }

/* ---------------------------------------------------------------- BOM, pin map, CSV */
.eda-wrap { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.eda-tabs { padding: 6px; border-bottom: 1px solid var(--border); flex: none; }
.eda-pane { flex: 1; min-height: 0; overflow: auto; }
.eda-pane > kicanvas-embed { height: 100%; }
.eda-panel { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.eda-panel label { display: inline-flex; align-items: center; gap: 6px; }
.eda-table td, .eda-table th { white-space: nowrap; }
.eda-table .eda-refs { white-space: normal; max-width: 320px; }
.eda-table tr.eda-dnp td { opacity: .55; text-decoration: line-through; }
.eda-pins tr.eda-nc td { color: var(--muted); }
.eda-bom h3, .eda-pin-changes h3 { margin: 8px 0; font-size: 15px; }
.eda-bom { overflow-x: auto; }
.csv-table-wrap { overflow: auto; max-height: 70vh; }
.csv-table td, .csv-table th { min-width: 60px; }
.csv-table.editing td[contenteditable], .csv-table.editing th[contenteditable] { outline: 1px dashed var(--border); background: var(--surface-2); }

/* ---------------------------------------------------------------- Chat: Markdown, files, replies */
#chat-input { resize: none; min-height: 38px; max-height: 140px; flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font: inherit; color: inherit; }
.composer { align-items: flex-end; }
.chat-attach { font-size: 18px; padding: 4px 8px; }
.chat-chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 10px 0; }
.chat-chip { display: inline-flex; align-items: center; gap: 4px; }
.chat-reply-bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--border); background: var(--surface); font-size: 12px; }
.chat-reply-bar .ellipsis { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.panel.drop, .dm-pane.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }
.msg { position: relative; }
.msg .text p { margin: 0; }
.msg .text p + p, .msg .text ul, .msg .text ol, .msg .text pre, .msg .text blockquote { margin: 4px 0 0; }
.msg .text ul, .msg .text ol { padding-inline-start: 18px; }
.msg .text pre { direction: ltr; text-align: left; background: #0d1117; border-radius: 6px; padding: 6px 8px; overflow-x: auto; font-size: 12px; white-space: pre; }
.msg .text code { background: rgba(255, 255, 255, .08); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.msg .text pre code { background: none; padding: 0; }
.msg .text blockquote { border-inline-start: 3px solid var(--border); padding-inline-start: 8px; color: var(--muted); }
.msg .text .mention { color: var(--accent); font-weight: 600; }
.msg-quote { display: block; font-size: 12px; color: var(--muted); border-inline-start: 3px solid var(--accent); padding-inline-start: 6px; margin: 2px 0 4px; text-decoration: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 100%; }
.msg-actions { margin-inline-start: auto; display: none; gap: 2px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: inline-flex; }
.msg-actions button { padding: 0 4px; font-size: 12px; background: transparent; border: 0; }
.msg.bot { background: #2b2440; }
.msg.system.day { font-weight: 600; }
.chat-file { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; font-size: 12px; }
.chat-file img { display: block; max-width: 220px; max-height: 160px; border-radius: 6px; }
.chat-file button { padding: 0 4px; }
@media (hover: none) { .msg-actions { display: inline-flex; } }

/* ---------------------------------------------------------------- Meeting: hands, reactions, recording */
.tile.hand { outline: 3px solid var(--warn); }
.people li.hand { background: rgba(245, 165, 36, .15); }
.react-wrap { position: relative; display: inline-flex; }
.react-pop { position: absolute; bottom: calc(100% + 6px); inset-inline-start: 50%; transform: translateX(50%); display: flex; gap: 2px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); z-index: 20; }
.react-pop button { font-size: 22px; border: 0; background: transparent; padding: 2px 4px; }
.reaction-float { position: absolute; bottom: 10%; font-size: 36px; pointer-events: none; animation: hamkar-float 2.6s ease-out forwards; display: flex; flex-direction: column; align-items: center; z-index: 30; }
.reaction-float small { font-size: 11px; background: rgba(0, 0, 0, .5); border-radius: 6px; padding: 0 4px; color: #fff; }
@keyframes hamkar-float { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-160px); opacity: 0; } }
.stage { position: relative; }
.rec-banner { background: rgba(229, 72, 77, .18); color: #ff8b8e; border-color: var(--danger); animation: hamkar-pulse 2s infinite; }
@keyframes hamkar-pulse { 50% { opacity: .6; } }
.ctl.on { background: rgba(79, 140, 255, .25); }
#btn-record.on { background: rgba(229, 72, 77, .35); }
.recordings { padding: 0 12px 12px; }
.recordings h3 { font-size: 14px; }
#lower-hands { margin: 0 12px 8px; }
.room-card.general { border-color: var(--accent); }

/* ---------------------------------------------------------------- Private messages, meetings */
.lobby-buttons { gap: 8px; }
.lobby-buttons .kartable-btn { flex: 1; }
.dm-side { display: flex; flex-direction: column; gap: 8px; }
.dm-side #dm-search { width: 100%; }
.dm-sep { font-size: 12px; margin: 8px 0 0; }
.dm-pane { display: flex; flex-direction: column; min-height: 0; padding: 0 !important; }
.dm-head { padding: 10px 12px; border-bottom: 1px solid var(--border); gap: 8px; align-items: center; }
.dm-head strong { margin-inline-end: auto; }
.dm-pane .chat-list { flex: 1; min-height: 0; }
#dm-input { resize: none; min-height: 38px; max-height: 140px; flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font: inherit; color: inherit; }
.kt-item.unread strong::after { content: ' •'; color: var(--accent); }
.kt-item .badge { margin-inline-start: 6px; }
.kt-item .ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.kt-item.cancelled { opacity: .6; }
.kt-invitees { display: flex; flex-wrap: wrap; gap: 4px 14px; max-height: 160px; overflow: auto; }
.kt-invitees label.check { flex-direction: row; align-items: center; gap: 4px; }
.kt-note { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; }
#dm-list { display: flex; flex-direction: column; gap: 6px; }
#dm-list .kt-item { width: 100%; text-align: start; }

/* ---------------------------------------------------------------- Office kartable: numbers, files, report, print */
.kt-search { margin: 8px 10px 0; }
.kt-number { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--accent); }
.kt-files { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 12px; }
.kt-attach input[type=file] { font-size: 12px; max-width: 100%; }
.kt-report-table td { white-space: nowrap; }
.kt-bar { display: inline-block; height: 8px; width: calc(var(--w) * .6); min-width: 2px; margin-inline-end: 6px; border-radius: 4px; background: var(--accent); vertical-align: middle; }
.kt-totals { margin: 6px 0; }
.print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing { background: #fff; color: #000; }
  body.printing #print-area { display: block; }
  .print-doc { font-size: 12pt; color: #000; }
  .print-doc .muted { color: #555; }
  .print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
  .print-meta { text-align: start; }
  .print-doc h1 { font-size: 16pt; margin: 8px 0; }
  .print-body { white-space: pre-wrap; border: 1px solid #999; padding: 8px; margin: 8px 0; }
  .print-steps { width: 100%; border-collapse: collapse; margin-top: 12px; }
  .print-steps th, .print-steps td { border: 1px solid #999; padding: 4px 6px; text-align: start; vertical-align: top; }
  .print-signs { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 24px; }
  .print-sign { min-width: 160px; border-top: 1px dashed #000; padding-top: 6px; }
  .print-doc footer { margin-top: 24px; font-size: 9pt; color: #555; }
}
