/* ============================================================
   style.css — Стили для адаптивной совместной онлайн-доски
   ============================================================ */

/* ---------- БАЗОВЫЙ СБРОС И ГЛОБАЛЬНЫЕ НАСТРОЙКИ ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  touch-action: none;
}

body {
  background: #ebedf0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Segoe UI', 'Inter', sans-serif;
}

.app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #ebedf0;
}

input, textarea, .inline-text-editor {
  user-select: text;
  -webkit-user-select: text;
}

/* ---------- ПАНЕЛЬ ИНСТРУМЕНТОВ (снизу по центру) ---------- */
.floating-toolbar {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 40px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  border: none;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  flex-wrap: nowrap;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}

.toolbar-collapsed .floating-toolbar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
}

.tool-group {
  display: flex;
  gap: 2px;
  padding: 0 4px;
  border-right: 1px solid #dce1e6;
  flex-shrink: 0;
}

.tool-group:last-child {
  border-right: none;
}

.tool-btn {
  background: transparent;
  border: none;
  color: #2c3e50;
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 500;
  touch-action: manipulation;
  flex-shrink: 0;
}

.tool-btn:hover {
  background: #e5ebf1;
}

.tool-btn.active {
  background: #0077ff;
  color: white;
}

#colorPicker {
  width: 36px;
  height: 36px;
  border: 1px solid #dce1e6;
  border-radius: 10px;
  cursor: pointer;
  background: white;
  padding: 2px;
}

#brushSize {
  width: 80px;
  accent-color: #0077ff;
}

#sizeValue {
  color: #2c3e50;
  min-width: 38px;
  font-size: 13px;
  font-weight: 500;
}

#imageUpload {
  display: none;
}

/* ---------- КНОПКА СВОРАЧИВАНИЯ ПАНЕЛИ ---------- */
.toggle-toolbar-btn {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  z-index: 101;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  border-radius: 30px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  color: #2c3e50;
  transition: all 0.2s;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.toolbar-collapsed .toggle-toolbar-btn {
  background: #0077ff;
  color: white;
}

.toggle-toolbar-btn:active {
  transform: scale(0.95);
}

/* ---------- ПАНЕЛЬ УПРАВЛЕНИЯ МАСШТАБОМ ---------- */
.zoom-panel {
  position: absolute;
  bottom: calc(80px + max(16px, env(safe-area-inset-bottom))); /* поднимаем над панелью инструментов */
  right: max(16px, env(safe-area-inset-right));
  z-index: 100;
  display: flex;
  flex-direction: column; /* вертикально */
  gap: 4px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 6px 6px;
  border-radius: 40px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  align-items: center;
}

.zoom-btn {
  background: transparent;
  border: none;
  color: #2c3e50;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-btn:hover {
  background: #e5ebf1;
}

#zoomLevelDisplay {
  min-width: 40px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  height: 30px;
  line-height: 30px;
  border-radius: 10px;
  transition: background 0.15s;
  width: 100%;
}

#zoomLevelDisplay:hover {
  background: #e5ebf1;
}

/* ---------- СТАТУС-БАР ---------- */
.status-mini {
  position: absolute;
  bottom: calc(80px + max(16px, env(safe-area-inset-bottom))); /* так же поднимаем */
  left: max(16px, env(safe-area-inset-left));
  z-index: 100;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: 40px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  pointer-events: none;
}

/* ---------- ПАНЕЛЬ ВЫБОРА КОМНАТЫ ---------- */
.room-panel {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 100;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: 40px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  display: flex;
  gap: 6px;
  align-items: center;
}

.room-panel input {
  border: 1px solid #dce1e6;
  border-radius: 24px;
  padding: 6px 12px;
  font-size: 14px;
  outline: none;
  width: 120px;
}

.room-panel button {
  background: #0077ff;
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
}

#connectionStatus {
  font-size: 16px;
  margin-left: 2px;
}

/* ---------- ОБЛАСТЬ ХОЛСТА ---------- */
.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #ebedf0;
}

#boardCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: #ffffff;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
}

/* ---------- РЕДАКТОР ТЕКСТА ---------- */
.inline-text-editor {
  position: absolute;
  z-index: 200;
  background: white;
  border: 2px solid #0077ff;
  border-radius: 12px;
  padding: 8px 12px;
  font-family: 'Segoe UI', sans-serif;
  font-size: 20px;
  min-width: 120px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  outline: none;
  resize: both;
  overflow: auto;
}

.inline-text-editor:focus {
  border-color: #0055cc;
}

/* ---------- АДАПТИВНОСТЬ ---------- */
@media (max-width: 700px) {
  .floating-toolbar { padding: 4px 6px; }
  .tool-btn { width: 36px; height: 36px; font-size: 16px; }
  #brushSize { width: 60px; }
  #sizeValue { min-width: 32px; font-size: 12px; }
  .room-panel input { width: 100px; }
  #clearBtn, #deleteSelectedBtn, #exportPdfBtn { display: none; }
  .status-mini { font-size: 11px; padding: 4px 10px; }
  .zoom-panel {
    bottom: calc(60px + max(16px, env(safe-area-inset-bottom))); /* немного опускаем при уменьшенной панели */
    padding: 4px 4px;
    gap: 2px;
  }
  .zoom-btn { width: 32px; height: 32px; font-size: 18px; }
  #zoomLevelDisplay { min-width: 36px; font-size: 12px; height: 28px; line-height: 28px; }
}

@media (max-width: 500px) {
  .file-input-label { display: none; }
  .floating-toolbar { gap: 2px; padding: 4px 6px; }
  .tool-group { padding: 0 2px; }
  #brushSize { width: 50px; }
  #sizeValue { min-width: 28px; font-size: 11px; }
  .zoom-panel {
    bottom: calc(60px + max(16px, env(safe-area-inset-bottom)));
    padding: 3px 3px;
    gap: 2px;
  }
  .zoom-btn { width: 30px; height: 30px; font-size: 16px; }
  #zoomLevelDisplay { min-width: 32px; font-size: 11px; height: 26px; line-height: 26px; }
  .room-panel input { width: 80px; padding: 4px 8px; }
  .status-mini { display: none; } /* на очень маленьких экранах скрываем координаты */
}

@media (max-width: 400px) {
  .tool-btn { width: 32px; height: 32px; font-size: 14px; }
  #colorPicker { width: 32px; height: 32px; }
  #brushSize { width: 45px; }
  .zoom-panel { bottom: calc(55px + max(16px, env(safe-area-inset-bottom))); }
  .zoom-btn { width: 28px; height: 28px; }
  #zoomLevelDisplay { min-width: 28px; font-size: 10px; height: 24px; line-height: 24px; }
}