/* ==========================================================================
   screens.new - Collaborative Canvas App Stylesheet
   ========================================================================== */

/* Reset & Base
   ========================================================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #1a1a1a;
  color: #e0e0e0;
  font-family: -apple-system, system-ui, 'Segoe UI', sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Canvas Layers
   ========================================================================== */

#canvas-root {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: default;
  background-image: radial-gradient(circle, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 20px 20px;
  /* background-position set by JS to track pan */
}

#canvas-world {
  position: absolute;
  transform-origin: 0 0;
  /* transform set by JS: translate(panX, panY) scale(zoom) */
  will-change: transform;
}

#element-layer {
  position: absolute;
  top: 0;
  left: 0;
  /* Elements positioned absolutely within */
}

#draw-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  /* Canvas for freehand paths, JS handles transform */
}

#selection-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

#cursor-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

/* Canvas Elements
   ========================================================================== */

.canvas-element {
  position: absolute;
  transform-origin: center center;
  /* x, y, w, h, rotation set via inline styles by JS */
  cursor: move;
  min-width: 1px;
  min-height: 1px;
}

.canvas-element.selected {
  outline: 2px solid #4a9eff;
  outline-offset: -1px;
}

/* Text elements */
.canvas-element[data-type="text"] {
  background: transparent;
  border: none;
  overflow: visible;
}

.canvas-element[data-type="text"] .text-content {
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 20px;
  min-height: 1em;
}

.canvas-element[data-type="text"] .text-content:focus {
  cursor: text;
}

/* Sticky notes */
.canvas-element[data-type="sticky"] {
  border-radius: 4px;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.3);
  padding: 12px;
}

.canvas-element[data-type="sticky"] .text-content {
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  width: 100%;
  height: 100%;
}

/* Shape elements */
.canvas-element[data-type="rect"] {
  border-radius: 0;
}

.canvas-element[data-type="circle"] {
  border-radius: 50%;
}

/* Image elements */
.canvas-element[data-type="image"] img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
}

/* YouTube embed elements */
.canvas-element[data-type="youtube"] {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.canvas-element[data-type="youtube"] iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: none;
}

.youtube-overlay {
  position: absolute;
  inset: 0;
  cursor: move;
}

.canvas-element[data-type="youtube"].youtube-interactive .youtube-overlay {
  display: none;
}

/* Line/Arrow/Connector elements use inline SVG */
.canvas-element[data-type="line"] svg,
.canvas-element[data-type="arrow"] svg,
.canvas-element[data-type="connector"] svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Selection Handles (in #selection-layer)
   ========================================================================== */

.select-handle {
  fill: white;
  stroke: #4a9eff;
  stroke-width: 2;
  cursor: pointer;
}

.select-handle.rotate {
  fill: #4a9eff;
  cursor: grab;
}

.select-box {
  fill: none;
  stroke: #4a9eff;
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

/* Marquee selection */
.marquee {
  fill: rgba(74, 158, 255, 0.1);
  stroke: #4a9eff;
  stroke-width: 1;
}

/* Connector tool: anchor indicators and preview line */
.anchor-indicator {
  fill: #4a9eff;
  stroke: white;
  stroke-width: 1.5;
  pointer-events: none;
}
.anchor-indicator.snapped {
  fill: #2979ff;
}
.connector-preview {
  stroke: #4a9eff;
  stroke-width: 2;
  stroke-dasharray: 6 3;
  pointer-events: none;
}

/* Toolbar - Unified, Draggable, Dockable
   ========================================================================== */

#toolbar {
  position: fixed;
  display: flex;
  gap: 2px;
  padding: 6px;
  background: rgba(30, 30, 30, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  z-index: 100;
  transition: left 0.3s ease, top 0.3s ease, bottom 0.3s ease,
              right 0.3s ease, transform 0.3s ease,
              flex-direction 0.2s ease, border-radius 0.2s ease;
}

/* Remove transition when dragging */
#toolbar.dragging {
  transition: none !important;
}

/* Bottom dock (default) - horizontal */
#toolbar.dock-bottom {
  bottom: 16px;
  left: 50%;
  top: auto;
  right: auto;
  transform: translateX(-50%);
  flex-direction: row;
}

/* Left dock - vertical */
#toolbar.dock-left {
  left: 16px;
  top: 50%;
  bottom: auto;
  right: auto;
  transform: translateY(-50%);
  flex-direction: column;
}

/* Right dock - vertical */
#toolbar.dock-right {
  right: 16px;
  top: 50%;
  bottom: auto;
  left: auto;
  transform: translateY(-50%);
  flex-direction: column;
}

/* Toolbar buttons */
#toolbar button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: #999;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  position: relative;
}

#toolbar button:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

#toolbar button:active {
  background: rgba(255,255,255,0.15);
  transform: scale(0.92);
}

#toolbar button.active {
  background: #4a9eff;
  color: #fff;
}

#toolbar button.active:active {
  background: #3a8eef;
}

#toolbar button svg {
  width: 18px;
  height: 18px;
}

/* Drag handle */
#toolbar .drag-handle {
  width: 20px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  color: rgba(255,255,255,0.2);
  flex-shrink: 0;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

#toolbar .drag-handle:hover {
  color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.05);
}

#toolbar .drag-handle:active {
  cursor: grabbing;
}

#toolbar .drag-handle svg {
  width: 14px;
  height: 14px;
}

/* Vertical dock: drag handle changes orientation */
#toolbar.dock-left .drag-handle,
#toolbar.dock-right .drag-handle {
  width: 36px;
  height: 20px;
}

/* Dividers */
#toolbar .divider {
  background: rgba(255,255,255,0.12);
  margin: 4px 2px;
  align-self: stretch;
  flex-shrink: 0;
  border-radius: 1px;
}

/* Horizontal divider */
#toolbar.dock-bottom .divider {
  width: 1px;
  min-height: 20px;
}

/* Vertical divider (when toolbar is vertical) */
#toolbar.dock-left .divider,
#toolbar.dock-right .divider {
  height: 1px;
  width: 100%;
  min-height: 0;
  margin: 2px 0;
}

/* Zoom controls inline */
.toolbar-zoom {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

#toolbar.dock-left .toolbar-zoom,
#toolbar.dock-right .toolbar-zoom {
  flex-direction: column;
}

.toolbar-zoom button {
  font-family: monospace;
  font-size: 14px;
  font-weight: 600;
}

.toolbar-zoom .zoom-level {
  width: auto !important;
  min-width: 44px;
  font-size: 11px;
  font-family: monospace;
  color: rgba(255,255,255,0.4);
  text-align: center;
  padding: 0 2px;
}

/* Peer count inline */
.toolbar-peers {
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 11px;
  font-family: monospace;
  color: rgba(255,255,255,0.3);
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 36px;
}

#toolbar.dock-left .toolbar-peers,
#toolbar.dock-right .toolbar-peers {
  min-height: 0;
  padding: 4px 0;
  justify-content: center;
}

/* Voice button states (in toolbar) */
#toolbar .voice-off {
  color: #666;
}

#toolbar .voice-requesting {
  color: #f0a030;
  animation: voice-pulse 1.5s ease-in-out infinite;
}

#toolbar .voice-active {
  color: #4ade80;
  background: rgba(30, 60, 30, 0.85);
}

/* Chat/command bar toggle button */
#toolbar .chat-toggle {
  position: relative;
}

.chat-unread-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  background: #f44336;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  border-radius: 7px;
  pointer-events: none;
  display: none;
}

.chat-unread-badge.visible {
  display: block;
}

/* Mobile toolbar adjustments */
@media (max-width: 600px) {
  #toolbar.dock-bottom {
    max-width: calc(100vw - 24px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    bottom: 8px;
  }
  #toolbar.dock-bottom::-webkit-scrollbar { display: none; }

  #toolbar.dock-left,
  #toolbar.dock-right {
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    scrollbar-width: none;
  }
  #toolbar.dock-left::-webkit-scrollbar,
  #toolbar.dock-right::-webkit-scrollbar { display: none; }

  #toolbar button {
    width: 32px;
    height: 32px;
  }
  #toolbar button svg {
    width: 16px;
    height: 16px;
  }
  #toolbar .drag-handle {
    width: 16px;
    height: 32px;
  }
  #toolbar.dock-left .drag-handle,
  #toolbar.dock-right .drag-handle {
    width: 32px;
    height: 16px;
  }
  .toolbar-zoom .zoom-level {
    min-width: 36px;
    font-size: 10px;
  }
  .toolbar-peers {
    font-size: 10px;
    padding: 0 4px;
    min-height: 32px;
  }
}

@keyframes voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Color Picker (popover from toolbar)
   ========================================================================== */

.color-picker {
  position: fixed;
  padding: 8px;
  background: rgba(30,30,30,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(6, 28px);
  gap: 4px;
  z-index: 150;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  border-color: #4a9eff;
}

.color-swatch.transparent-swatch {
  background: linear-gradient(45deg, #666 25%, transparent 25%, transparent 75%, #666 75%),
              linear-gradient(45deg, #666 25%, transparent 25%, transparent 75%, #666 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
}

/* Context Menu
   ========================================================================== */

#context-menu {
  position: fixed;
  min-width: 160px;
  padding: 4px;
  background: rgba(30,30,30,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

#context-menu.hidden {
  display: none;
}

.ctx-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: #ddd;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}

.ctx-item:hover {
  background: rgba(255,255,255,0.1);
}

.ctx-item .shortcut {
  color: rgba(255,255,255,0.3);
  font-size: 12px;
  margin-left: 16px;
}

.ctx-divider {
  height: 1px;
  background: rgba(255,255,255,0.1);
  margin: 4px 0;
}

/* Room Label
   ========================================================================== */

#room-label {
  position: fixed;
  top: 12px;
  left: 12px;
  font-size: 14px;
  color: rgba(255,255,255,0.3);
  font-family: monospace;
  cursor: pointer;
  z-index: 100;
  transition: color 0.2s;
}

#room-label:hover {
  color: rgba(255,255,255,0.6);
}

/* QR Code
   ========================================================================== */

#qr-code {
  position: fixed;
  bottom: 16px;
  right: 16px;
  opacity: 0.15;
  transition: opacity 0.3s;
  cursor: pointer;
  z-index: 99;
}

#qr-code:hover {
  opacity: 0.6;
}

#qr-code canvas {
  display: block;
  border-radius: 4px;
}

/* Remote Cursors
   ========================================================================== */

.remote-cursor {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  will-change: transform;
  z-index: 51;
}

.remote-cursor .cursor-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid white;
}

.remote-cursor .cursor-label {
  position: absolute;
  top: 12px;
  left: 4px;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  color: white;
  white-space: nowrap;
  font-family: monospace;
}

/* Cursor Modes
   ========================================================================== */

#canvas-root.tool-select { cursor: default; }
#canvas-root.tool-hand   { cursor: grab; }
#canvas-root.tool-hand:active { cursor: grabbing; }
#canvas-root.tool-draw   { cursor: crosshair; }
#canvas-root.tool-shape  { cursor: crosshair; }
#canvas-root.tool-text   { cursor: text; }
#canvas-root.tool-connector { cursor: crosshair; }

/* Command Bar
   ========================================================================== */

#command-bar {
  position: fixed;
  z-index: 110;
  width: 400px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  background: rgba(25, 25, 25, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  overflow: hidden;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

#command-bar.command-bar-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

/* Position variants for command bar based on toolbar dock */
#command-bar.cmd-from-bottom {
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
}

#command-bar.cmd-from-bottom.command-bar-hidden {
  transform: translateX(-50%) translateY(8px);
}

#command-bar.cmd-from-left {
  left: 72px;
  top: 50%;
  transform: translateY(-50%);
}

#command-bar.cmd-from-left.command-bar-hidden {
  transform: translateY(-50%) translateX(-8px);
}

#command-bar.cmd-from-right {
  right: 72px;
  top: 50%;
  transform: translateY(-50%);
}

#command-bar.cmd-from-right.command-bar-hidden {
  transform: translateY(-50%) translateX(8px);
}

#command-messages {
  max-height: 240px;
  overflow-y: auto;
  padding: 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}

#command-messages::-webkit-scrollbar {
  width: 4px;
}

#command-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 2px;
}

#command-messages:empty {
  display: none;
}

.cmd-msg {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}

.cmd-msg.cmd-system {
  color: rgba(255,255,255,0.3);
  font-size: 11px;
  font-style: italic;
  padding: 1px 0;
  white-space: pre-wrap;
}

.cmd-msg .cmd-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  top: 2px;
}

.cmd-msg .cmd-author {
  font-weight: 600;
  color: #888;
  font-size: 11px;
  font-family: monospace;
  flex-shrink: 0;
}

.cmd-msg .cmd-text {
  color: #d0d0d0;
  white-space: pre-wrap;
}

.cmd-msg .cmd-time {
  margin-left: auto;
  font-size: 10px;
  color: rgba(255,255,255,0.15);
  flex-shrink: 0;
  white-space: nowrap;
}

#command-input-row {
  padding: 8px 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

#command-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  padding: 8px 10px;
  outline: none;
  line-height: 1.4;
}

#command-input::placeholder {
  color: rgba(255,255,255,0.2);
}

#command-input:focus {
  border-color: rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
}

/* Slash command hints */
.cmd-hints {
  padding: 4px 8px 4px 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
  max-height: 160px;
  overflow-y: auto;
}

.cmd-hint {
  padding: 4px 8px;
  font-size: 12px;
  font-family: monospace;
  color: rgba(255,255,255,0.45);
  border-radius: 4px;
  cursor: pointer;
}

.cmd-hint:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
}

.cmd-hint .cmd-hint-desc {
  color: rgba(255,255,255,0.25);
  margin-left: 8px;
  font-family: -apple-system, system-ui, 'Segoe UI', sans-serif;
}

@media (max-width: 600px) {
  #command-bar {
    width: calc(100vw - 24px);
  }
  #command-bar.cmd-from-bottom {
    bottom: 56px;
  }
}

/* Voice Prompts (floating banners, top-center)
   ========================================================================== */

#voice-prompts {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.voice-prompt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(30, 30, 30, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  font-size: 13px;
  color: #ddd;
  white-space: nowrap;
}

.voice-prompt-accept {
  padding: 4px 12px;
  background: #4ade80;
  border: none;
  border-radius: 6px;
  color: #000;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.voice-prompt-accept:hover {
  background: #22c55e;
}

.voice-prompt-decline {
  padding: 4px 12px;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 6px;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
}

.voice-prompt-decline:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.voice-error {
  position: fixed;
  top: 48px;
  right: 12px;
  padding: 8px 14px;
  background: rgba(180, 40, 40, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,100,100,0.3);
  border-radius: 8px;
  color: #fbb;
  font-size: 12px;
  z-index: 200;
  animation: voice-error-fade 3s ease-out forwards;
}

@keyframes voice-error-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}
