/* =========================================================
   Perfume Suppliers · Telegram dark theme
   ========================================================= */

:root {
  --tg-bg:        var(--tg-theme-bg-color, #17212b);
  --tg-secondary: var(--tg-theme-secondary-bg-color, #232e3c);
  --tg-card:      #242f3d;
  --tg-text:      var(--tg-theme-text-color, #f5f5f5);
  --tg-hint:      var(--tg-theme-hint-color, #708499);
  --tg-link:      var(--tg-theme-link-color, #6ab3f3);
  --tg-button:    var(--tg-theme-button-color, #5288c1);
  --tg-button-tx: var(--tg-theme-button-text-color, #ffffff);
  --tg-divider:   rgba(255, 255, 255, 0.08);
  --tg-input-bg:  rgba(255, 255, 255, 0.05);

  --color-fresh:   #4caf50;
  --color-warn:    #ffb300;
  --color-stale:   #f44336;
  --color-empty:   #455a64;
  --color-neutral: #6b7a8c;  /* "не наш" офис */

  --color-edit-accent: #ff8a65; /* акцент для режима правки */
  --color-wall:        #ff6b9a;
  --color-draft:       #6ab3f3;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--tg-bg); color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; overflow: hidden; overscroll-behavior: none;
}

body {
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* =========================================================
   Header
   ========================================================= */

.app-header {
  flex: 0 0 auto;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--tg-divider);
  background: var(--tg-bg);
  z-index: 5;
}

.header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}

.floor-switcher {
  display: inline-flex;
  background: var(--tg-secondary);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.floor-btn {
  border: none;
  background: transparent;
  color: var(--tg-hint);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.floor-btn.is-active {
  background: var(--tg-button);
  color: var(--tg-button-tx);
}

.floor-btn.is-dev::after {
  content: "•";
  position: absolute;
  top: 1px; right: 4px;
  color: var(--color-warn);
  font-size: 14px;
  line-height: 1;
}

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

.icon-btn {
  background: var(--tg-secondary);
  border: none;
  color: var(--tg-text);
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  display: inline-flex; align-items: center; gap: 5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn .icon { font-size: 16px; line-height: 1; }
.icon-btn .btn-label { font-size: 13px; font-weight: 500; }

.icon-btn[aria-pressed="true"] {
  background: var(--color-edit-accent);
  color: #1a1a1a;
}

.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--tg-card);
  border: 1px solid var(--tg-divider);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  padding: 4px;
  z-index: 30;
}

.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--tg-text);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.dropdown-item:hover, .dropdown-item:active {
  background: var(--tg-secondary);
}

.dropdown-item.danger { color: var(--color-stale); }

.legend {
  display: flex; gap: 14px;
  font-size: 11px; color: var(--tg-hint);
  flex-wrap: wrap; margin-top: 6px;
}

.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-fresh   { background: var(--color-fresh); }
.dot-warn    { background: var(--color-warn); }
.dot-stale   { background: var(--color-stale); }
.dot-neutral { background: var(--color-neutral); }

/* =========================================================
   Edit toolbar
   ========================================================= */

.edit-toolbar {
  display: flex; align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px;
  background: var(--tg-secondary);
  border-radius: 10px;
  flex-wrap: wrap;
}

.tool-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--tg-text);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, border 0.15s;
}

.tool-btn:hover { background: rgba(255, 255, 255, 0.05); }

.tool-btn.is-active {
  background: var(--color-edit-accent);
  color: #1a1a1a;
}

.tool-btn.ghost {
  background: var(--tg-card);
  border-color: var(--tg-divider);
  font-size: 12px;
  padding: 4px 8px;
}

.tool-btn.ghost:hover {
  background: var(--tg-bg);
}

.tool-icon { font-size: 14px; }

.tool-separator {
  width: 1px; height: 22px;
  background: var(--tg-divider);
  margin: 0 2px;
}

.tool-hint {
  font-size: 11px;
  color: var(--tg-hint);
  flex: 1;
  margin-left: 4px;
}

/* =========================================================
   Map & SVG
   ========================================================= */

.map-wrap {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  background: var(--tg-bg);
  touch-action: none;
}

#floor-map {
  display: block;
  width: 100%; height: 100%;
  user-select: none;
}

#floor-bg {
  /* Полупрозрачный фон, чтобы поверх него были видны полигоны бутиков */
  opacity: 0.85;
}

/* Кликабельные полигоны (офисы) */
.office-shape {
  fill: var(--color-empty);
  fill-opacity: 0.0;        /* по умолчанию прозрачный — виден только фон 2ГИС */
  stroke: var(--color-empty);
  stroke-width: 2;
  stroke-opacity: 0.4;
  cursor: pointer;
  transition: fill-opacity 0.15s, stroke-opacity 0.15s;
}

/* "Наш" — закрашен по свежести прайса */
.office-shape.is-our { fill-opacity: 0.55; stroke-opacity: 0.95; stroke-width: 3; }

.office-shape.status-fresh { fill: var(--color-fresh);   stroke: var(--color-fresh); }
.office-shape.status-warn  { fill: var(--color-warn);    stroke: var(--color-warn); }
.office-shape.status-stale { fill: var(--color-stale);   stroke: var(--color-stale); }

/* "Не наш" — нейтральная обводка, заливка только при ховере */
.office-shape.is-neutral { fill: var(--color-neutral); stroke: var(--color-neutral); }
.office-shape.is-neutral:hover { fill-opacity: 0.30; stroke-opacity: 0.8; }

/* Выделенный (выбранный в edit-mode или открытый sheet) */
.office-shape.is-selected {
  stroke: var(--tg-button);
  stroke-width: 4;
  fill-opacity: 0.45;
}

/* Edit-mode: все полигоны видны контурно */
body.edit-mode .office-shape {
  fill-opacity: 0.10;
  stroke-opacity: 0.8;
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

body.edit-mode .office-shape.is-our { fill-opacity: 0.30; stroke-dasharray: none; }
body.edit-mode .office-shape.is-selected { stroke-dasharray: none; }

/* Подпись номера офиса внутри полигона */
.office-label {
  fill: #ffffff;
  font-size: 22px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* Перегородки */
.custom-wall {
  stroke: var(--color-wall);
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.9;
}

body.edit-mode .custom-wall { cursor: pointer; }

/* Слой черновика рисования (полигон в процессе) */
.draw-layer { pointer-events: none; }

.draft-polygon {
  fill: var(--color-draft);
  fill-opacity: 0.2;
  stroke: var(--color-draft);
  stroke-width: 3;
  stroke-dasharray: 8 4;
}

.draft-line {
  stroke: var(--color-draft);
  stroke-width: 3;
  stroke-dasharray: 8 4;
}

.draft-vertex {
  fill: var(--color-draft);
  stroke: white;
  stroke-width: 1.5;
}

/* =========================================================
   Loader & stub
   ========================================================= */

.loader {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--tg-bg);
  color: var(--tg-hint);
  font-size: 14px;
  z-index: 10;
}
.loader.hidden { display: none; }

.floor-stub {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--tg-bg);
  padding: 20px;
  z-index: 8;
}
/* `display: flex` выше переопределяет default display:none у [hidden] —
   без этого правила заглушка остаётся видимой поверх карты, даже когда
   код выставил stub.hidden = true. */
.floor-stub[hidden] { display: none; }

.stub-card {
  background: var(--tg-card);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  max-width: 320px;
}

.stub-icon { font-size: 48px; margin-bottom: 12px; }
.stub-card h2 { margin: 0 0 8px; font-size: 18px; }
.stub-card p { margin: 0; color: var(--tg-hint); font-size: 14px; line-height: 1.4; }

/* =========================================================
   Bottom sheets
   ========================================================= */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 20;
}
.sheet-backdrop.is-open { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--tg-card);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 21;
  max-height: 85vh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.is-open { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 8px auto 0;
  flex-shrink: 0;
}

.sheet-content {
  padding: 16px 20px 24px;
  overflow-y: auto;
}

.sheet-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-bottom: 12px;
}

.sheet-office {
  font-size: 12px; color: var(--tg-hint);
  text-transform: uppercase; letter-spacing: 0.4px;
  margin-bottom: 2px;
}

.sheet-name {
  margin: 0; font-size: 20px; font-weight: 600;
  line-height: 1.25; word-break: break-word;
}

.sheet-close {
  background: rgba(255, 255, 255, 0.08); border: none;
  color: var(--tg-text);
  width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.sheet-close:active { background: rgba(255, 255, 255, 0.16); }

.sheet-status {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 0 18px; flex-wrap: wrap;
}

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600;
  padding: 5px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}
.status-pill::before {
  content: ""; display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--color-empty);
}
.status-pill.is-fresh::before   { background: var(--color-fresh); }
.status-pill.is-warn::before    { background: var(--color-warn); }
.status-pill.is-stale::before   { background: var(--color-stale); }
.status-pill.is-neutral::before { background: var(--color-neutral); }

.status-date { font-size: 13px; color: var(--tg-hint); }

.sheet-actions { display: flex; flex-direction: column; gap: 10px; }

.action-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  background: var(--tg-secondary);
  border: none; border-radius: 12px;
  color: var(--tg-text);
  font-size: 15px; font-weight: 500;
  cursor: pointer; text-decoration: none;
  text-align: left; width: 100%;
}
.action-btn:active { background: rgba(255, 255, 255, 0.08); }
.action-btn.primary { background: var(--tg-button); color: var(--tg-button-tx); }
.action-icon { width: 22px; flex-shrink: 0; text-align: center; font-size: 18px; }
.action-label { flex: 1; }
.action-sub {
  display: block; font-size: 12px; color: var(--tg-hint);
  font-weight: 400; margin-top: 2px;
}
.action-btn.primary .action-sub { color: rgba(255, 255, 255, 0.75); }

.sheet-empty {
  color: var(--tg-hint); text-align: center;
  padding: 24px 0 8px; font-size: 14px;
}

/* =========================================================
   Edit form
   ========================================================= */

.edit-form { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12px; color: var(--tg-hint); padding-left: 2px; }

.field input[type="text"],
.field input[type="tel"],
.field input[type="date"] {
  background: var(--tg-input-bg);
  border: 1px solid var(--tg-divider);
  color: var(--tg-text);
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 8px;
  width: 100%;
  font-family: inherit;
}

.field input:focus {
  outline: none;
  border-color: var(--tg-button);
}

.field-check {
  flex-direction: row; align-items: center; gap: 8px;
  background: var(--tg-input-bg);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.field-check input { width: 18px; height: 18px; cursor: pointer; }
.field-check span { font-size: 14px; }

#our-fields {
  display: flex; flex-direction: column; gap: 12px;
  border-left: 2px solid var(--color-edit-accent);
  padding-left: 12px;
  margin-left: 2px;
}
#our-fields.hidden { display: none; }

.form-actions {
  display: flex; gap: 10px; margin-top: 10px;
  flex-wrap: wrap;
}

.btn-primary, .btn-danger {
  flex: 1; min-width: 130px;
  padding: 12px 16px;
  border: none; border-radius: 10px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--tg-button);
  color: var(--tg-button-tx);
}
.btn-primary:active { filter: brightness(1.1); }

.btn-danger {
  background: transparent;
  border: 1px solid var(--color-stale);
  color: var(--color-stale);
}
.btn-danger:active { background: rgba(244, 67, 54, 0.12); }

/* Маленькая всплывашка-toast (для подтверждений) */
.toast {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.85);
  color: white; font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.is-shown { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 380px) {
  .floor-btn { padding: 6px 10px; font-size: 13px; }
  .icon-btn .btn-label { display: none; }
  .legend { gap: 10px; font-size: 10px; }
  .tool-hint { display: none; }
}
