:root {
  --primary-color: #3b82f6;
  --bg-color: #f3f4f6;
  --card-bg: #ffffff;
  --text-color: #1f2937;
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

html,
body {
  overflow-x: hidden;
}

/* LOGIN SCREEN */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 50;
  background-color: var(--bg-color);
}

/* APP INTERFACE */
#app-interface {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

#app-interface header {
  height: 80px;
  overflow: visible;
}

/* MAIN LAYOUT */
.app-main {
  height: calc(100% - 80px);
  /* header height */
}

#canvas-container {
  overflow: hidden;
  touch-action: none;
}

#canvas-workspace {
  width: 2560px;
  height: 1440px;
  transform-origin: top left;
  position: relative;
}

#canvas-workspace canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.app-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.app-modal.open {
  display: flex;
}

.app-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.app-modal__dialog {
  position: relative;
  background: #ffffff;
  border-radius: 18px;
  padding: 24px;
  width: min(420px, calc(100% - 32px));
  box-shadow:
    0 25px 50px rgba(15, 23, 42, 0.25),
    0 8px 16px rgba(15, 23, 42, 0.2);
  z-index: 1;
}

.app-modal__title {
  margin: 0 0 10px;
  font-size: 1.1rem;
  color: #0f172a;
}

.app-modal__message {
  margin: 0;
  color: #475569;
  line-height: 1.4;
  font-size: 0.95rem;
}

.app-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.app-modal__btn {
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.app-modal__btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
}

.app-modal__btn--primary {
  background-color: var(--primary-color);
  color: #ffffff;
}

.app-modal__btn--ghost {
  background-color: #f1f5f9;
  color: #0f172a;
}

.app-modal__btn--ghost:hover {
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.1);
}

body.modal-open {
  overflow: hidden;
}

.floating-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  justify-content: center;
  padding: 6px 14px;
  border: none;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.floating-toolbar.static-toolbar {
  position: relative;
  width: 100%;
  max-width: 380px;
  justify-content: center;
}

.tool-group {
  display: inline-flex;
  gap: 8px;
}

.topbar-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
}

.context-menu {
  position: absolute;
  min-width: 210px;
  max-width: 240px;
  background: #fcfcff;
  border-radius: 16px;
  border: 1px solid #dbe4fb;
  box-shadow:
    0 18px 30px rgba(15, 23, 42, 0.18),
    0 6px 14px rgba(15, 23, 42, 0.12);
  padding: 16px;
  z-index: 30;
  backdrop-filter: blur(6px);
}

.context-menu__section+.context-menu__section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #e2e8f0;
}

.context-menu__title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #94a3b8;
  margin-bottom: 10px;
}

.context-menu__tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.context-color-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.color-option {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 2px solid rgba(15, 23, 42, 0.1);
  background-clip: padding-box;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08);
}

.color-option:hover {
  transform: translateY(-1px);
}

.color-option.active {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.user-pointer {
  position: absolute;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transform: translate(-8px, -12px);
  z-index: 40;
}

.user-pointer svg {
  filter: drop-shadow(0 0 4px rgba(15, 23, 42, 0.2));
}

.context-slider {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f7f9ff;
  border: 1px solid #e0e7ff;
}

.context-slider label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  margin-bottom: 8px;
}

.context-slider input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #a5b4fc, var(--primary-color));
  outline: none;
}

.context-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--primary-color);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
  cursor: pointer;
}

.context-slider input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--primary-color);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
  cursor: pointer;
}

.tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  background-color: #ffffff;
  color: #475569;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
  box-shadow: 0 2px 4px rgba(148, 163, 184, 0.15);
}

.tool-btn:hover {
  transform: translateY(-1px);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.tool-btn svg {
  pointer-events: none;
}

.tool-btn.active {
  border-color: var(--primary-color);
  background-color: #eff6ff;
  color: var(--primary-color);
  box-shadow:
    0 4px 12px rgba(59, 130, 246, 0.25),
    0 2px 6px rgba(59, 130, 246, 0.15);
}

.color-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  background-color: #ffffff;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
  box-shadow: 0 2px 4px rgba(148, 163, 184, 0.15);
}

.color-preview:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.4);
  outline-offset: 2px;
}

.color-preview:hover {
  transform: translateY(-1px);
  border-color: var(--primary-color);
  box-shadow:
    0 4px 12px rgba(59, 130, 246, 0.25),
    0 2px 6px rgba(59, 130, 246, 0.15);
}

.color-preview__chip {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.15);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18);
  display: inline-block;
}

.color-picker-hidden {
  position: absolute;
  width: 0;
  height: 0;
  border: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

/* ADMIN */
#admin-dashboard {
  display: none;
}

.room-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.room-card:hover {
  transform: translateY(-2px);
  box-shadow:
    0 6px 12px rgba(15, 23, 42, 0.12),
    0 2px 4px rgba(15, 23, 42, 0.08);
}

.room-canvas-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.room-canvas-preview canvas {
  box-shadow: none;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  border-radius: 0;
}

.hidden {
  display: none !important;
}

.input-maxed {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.4);
}

.room-count-label {
  color: #16a34a;
  font-weight: 600;
}

.room-user-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 65;
  display: flex;
  align-items: center;
  justify-content: center;
}

.room-user-popover {
  position: relative;
  width: min(500px, 90vw);
  max-width: 500px;
  max-height: 80vh;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  box-shadow:
    0 20px 40px rgba(15, 23, 42, 0.2),
    0 10px 20px rgba(15, 23, 42, 0.15);
  padding: 24px;
  z-index: 70;
  display: flex;
  flex-direction: column;
}

.room-user-popover__title {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 12px;
}

.room-user-popover__section-title {
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
  margin: 12px 0 4px;
}

.room-user-popover__empty {
  font-size: 12px;
  color: #94a3b8;
  margin: 0;
}

.room-user-popover__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed #e2e8f0;
}

.room-user-popover__item:last-child {
  border-bottom: none;
}

.room-user-popover__info {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: #0f172a;
}

.room-user-popover__info span {
  color: #64748b;
  font-size: 11px;
}

.room-user-popover__actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 110px;
}

.room-user-popover__actions button {
  border: 1px solid #fecdd3;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 11px;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.room-user-popover__actions button:hover {
  background: #fecaca;
}

.room-user-view-btn {
  border: 1px solid #bfdbfe;
  background: #dbeafe;
  color: #1d4ed8;
}

.room-user-view-btn:hover {
  background: #bfdbfe;
}

.room-user-view-btn--mini {
  margin-top: 4px;
  width: 100%;
  text-align: center;
}

.room-user-popover__history {
  border-top: 1px solid #f1f5f9;
  margin-top: 6px;
  padding-top: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.room-user-popover__history-canvas {
  width: 100%;
  height: auto;
  max-height: 120px;
  border-radius: 12px;
  border: 1px solid #dbe4f0;
  background: #f8fafc;
  box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.08);
  margin-bottom: 6px;
  display: block;
}

.room-user-popover__history-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 0;
  border-bottom: 1px dashed #e2e8f0;
}

.room-user-popover__history-item:last-child {
  border-bottom: none;
}

.room-user-popover__history-item strong {
  font-size: 12px;
  color: #0f172a;
}

.room-user-popover__history-item span {
  font-size: 11px;
  color: #64748b;
}

.room-filter-note {
  margin-top: 4px;
  font-size: 11px;
  color: #0f172a;
  background: #dbeafe;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 6px 8px;
}

/* RESPONSIVE */
@media (max-width: 640px) {
  body {
    overflow-y: auto;
    overflow-x: hidden;
  }

  #login-screen {
    padding: 16px;
    align-items: flex-start;
  }

  #user-login-form,
  #admin-login-form {
    margin-top: 48px;
  }

  .floating-toolbar {
    width: 100%;
    justify-content: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    gap: 6px;
    padding: 6px 12px;
  }

  .floating-toolbar .tool-btn,
  .floating-toolbar .color-preview {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    flex: 0 0 auto;
  }

  .floating-toolbar .tool-btn svg {
    width: 16px;
    height: 16px;
  }

  #color-preview-chip {
    width: 12px;
    height: 12px;
  }

  .topbar-actions {
    position: absolute;
    top: 72px;
    left: 12px;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px;
    flex-direction: column;
    gap: 8px;
    box-shadow:
      0 12px 24px rgba(15, 23, 42, 0.12),
      0 4px 8px rgba(15, 23, 42, 0.08);
    display: none;
    z-index: 30;
  }

  .topbar-actions.open {
    display: flex;
  }

  .context-menu {
    min-width: 200px;
    max-width: 90%;
  }

  #canvas-container {
    padding: 8px;
  }

  .app-main {
    flex-direction: column-reverse;
  }

  canvas {
    border-radius: 8px;
  }
}

.canvas-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(90%, 420px);
  padding: 10px 16px;
  border-radius: 12px;
  color: #fff;
  font-size: 12px;
  text-align: center;
  box-shadow:
    0 10px 20px rgba(15, 23, 42, 0.2),
    0 4px 8px rgba(15, 23, 42, 0.12);
  z-index: 25;
}

#drawing-paused-banner {
  top: 56px;
}

.pointer-label {
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
}

.context-brush-btn {
  margin-top: 12px;
  width: 100%;
  padding: 8px 0;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  background: #f7f9fc;
  font-size: 12px;
  color: #475569;
  cursor: pointer;
}

.context-brush-btn:hover {
  background: #eef2ff;
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.brush-indicator {
  display: none !important;
}

.color-loupe {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 16px;
  border: 2px solid #1d4ed8;
  background: #ffffff;
  box-shadow:
    0 12px 24px rgba(15, 23, 42, 0.25),
    0 4px 8px rgba(15, 23, 42, 0.15);
  pointer-events: none;
  z-index: 60;
}

.color-loupe.hidden {
  display: none !important;
}

.cursor-brush {
  position: absolute;
  border: 2px solid rgba(15, 23, 42, 0.35);
  border-radius: 999px;
  pointer-events: none;
  z-index: 50;
  mix-blend-mode: multiply;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
  background: rgba(255, 255, 255, 0.05);
}

.cursor-brush.hidden {
  display: none !important;
}

.quick-color-panel {
  position: absolute;
  width: 220px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #dbe4f0;
  border-radius: 16px;
  box-shadow:
    0 12px 24px rgba(15, 23, 42, 0.18),
    0 4px 8px rgba(15, 23, 42, 0.12);
  padding: 12px;
  pointer-events: auto;
  z-index: 50;
  cursor: default;
  touch-action: none;
}

.quick-color-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.quick-color-picker {
  display: flex;
  gap: 12px;
}

.quick-color-spectrum {
  position: relative;
  width: 180px;
  height: 150px;
  border-radius: 12px;
  border: 1px solid #dbe4f0;
  background-image:
    linear-gradient(180deg, rgba(0, 0, 0, 0), #000000),
    linear-gradient(90deg, #ffffff, rgba(255, 255, 255, 0));
  background-color: var(--quick-spectrum-hue, #ff0000);
  cursor: crosshair;
}

.quick-color-spectrum::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.1);
}

.quick-color-spectrum-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.quick-color-hue {
  position: relative;
  width: 22px;
  height: 150px;
  border-radius: 12px;
  border: 1px solid #dbe4f0;
  background: linear-gradient(180deg,
      #ff0000,
      #ff00ff,
      #0000ff,
      #00ffff,
      #00ff00,
      #ffff00,
      #ff0000);
  cursor: pointer;
}

.quick-color-hue-handle {
  position: absolute;
  left: 50%;
  width: 24px;
  height: 6px;
  border-radius: 999px;
  border: 1px solid #fff;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.4);
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.8);
  pointer-events: none;
}

.quick-color-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.quick-color-preview-box {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid #dbe4f0;
  box-shadow: inset 0 1px 4px rgba(15, 23, 42, 0.1);
}

.quick-color-hex {
  border: 1px solid #cbd5f5;
  border-radius: 10px;
  padding: 6px 10px;
  width: 100px;
  font-size: 12px;
  font-family: monospace;
  text-transform: uppercase;
}

.quick-color-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 8px;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.quick-color-panel.dragging .quick-color-header {
  cursor: grabbing;
}

.quick-color-close {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #64748b;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.quick-color-close:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.quick-color-hint {
  font-size: 11px;
  color: #64748b;
  text-align: center;
  margin: 0;
}

@media (max-width: 640px) {
  .quick-color-panel {
    width: min(240px, calc(100% - 24px));
    padding: 10px;
  }

  .quick-color-body {
    gap: 10px;
  }

  .quick-color-spectrum {
    width: 150px;
    height: 120px;
  }

  .quick-color-hue {
    height: 120px;
  }
}
