/* ============================================================
   СОПС — стили карты
   ============================================================ */

html, body { width:100%; height:100%; margin:0; padding:0; overflow:hidden; }

#map { width:100%; height:100%; }

/* ---- Прогресс загрузки геометрии ---- */
#geo-bar-wrap {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 9999;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
}
#geo-bar-wrap.active { opacity: 1; }
#geo-bar-wrap.done   { opacity: 0; transition: opacity .6s .3s; }
#geo-bar-fill {
  height: 100%;
  background: var(--color-primary, #1a73e8);
  width: 0%;
  transition: width .4s ease;
}
#geo-bar-label {
  position: absolute;
  top: 5px; right: 10px;
  font-size: .7rem;
  color: var(--color-text-sec);
  background: var(--color-surface);
  padding: 1px 5px;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  white-space: nowrap;
  pointer-events: none;
}

/* ---- Шапка с фильтром ---- */
#map-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-surface);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
#map-header .logo-link {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-primary);
  white-space: nowrap;
  text-decoration: none;
}
#station-filter-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
}
#station-input {
  width: 100%;
  padding: 7px 30px 7px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: 20px;
  font-size: .9rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color .15s;
}
#station-input:focus { border-color: var(--color-primary); }
#station-clear {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  cursor: pointer; font-size: 1rem;
  color: var(--color-text-sec);
  display: none;
  padding: 2px;
}
#station-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
  z-index: 300;
  display: none;
}
.suggestion-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: .9rem;
  border-bottom: 1px solid var(--color-border);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--color-surface2); }

#map-header .spacer { flex: 1; }
#header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .875rem;
  white-space: nowrap;
}
#header-user a { color: var(--color-primary); text-decoration: none; }

/* ---- Загрузочный оверлей ---- */
#loading-overlay {
  position: fixed; inset: 0;
  background: var(--color-surface);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity .4s;
}
#loading-overlay.fade-out { opacity: 0; pointer-events: none; }

.loading-logo {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
}
.loading-step {
  width: 280px;
}
.loading-label {
  display: flex;
  justify-content: space-between;
  font-size: .85rem;
  color: var(--color-text-sec);
  margin-bottom: 6px;
}
.progress-bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--color-surface2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--color-primary);
  width: 0%;
  transition: width .2s;
}
#loco-step { opacity: .4; transition: opacity .3s; }
#loco-step.active { opacity: 1; }

/* ---- Иконки поездов ---- */
.train-icon {
  position: relative;
  cursor: pointer;
  transform: translate(-50%, -100%);
}
.train-icon-inner {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  border: 2px solid #4a4a4a;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
  font-family: system-ui, Arial, sans-serif;
  overflow: hidden;
  min-width: 44px;
  position: relative;
}
.train-icon-inner::after {
  content: '';
  position: absolute;
  bottom: -7px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid #4a4a4a;
}
.train-icon-photo {
  width: 56px; height: 32px;
  object-fit: cover; display: block;
}
.train-icon-text {
  display: flex;
  align-items: baseline;
  gap: 3px;
  padding: 3px 6px;
  white-space: nowrap;
}
.train-icon-name { font-size: 12px; font-weight: bold; color: #222; }
.train-icon-loco { font-size: 9px; color: #777; font-weight: normal; }
.train-icon-inner.no-photo .train-icon-text { padding: 3px 7px; }

[data-theme="dark"] .train-icon-inner { background: #2a2a2a; border-color: #888; }
[data-theme="dark"] .train-icon-name  { color: #eee; }

/* ---- Баллун ---- */
.train-balloon {
  font-family: system-ui, Arial, sans-serif;
  line-height: 1.5;
  min-width: 240px;
  max-width: 320px;
  max-height: min(520px, 70vh);
  overflow-y: auto;
  font-size: .9rem;
}
.balloon-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1a73e8;
}
.balloon-route {
  font-size: .85rem;
  color: #666;
  margin-bottom: 10px;
}
.balloon-status {
  background: #f1f3f4;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 10px;
  font-size: .875rem;
}
.balloon-rzd-link {
  margin-bottom: 10px;
  font-size: .82rem;
}
.balloon-rzd-link a {
  color: var(--color-primary, #1a73e8);
  text-decoration: none;
}
.balloon-rzd-link a:hover { text-decoration: underline; }
.balloon-loco {
  margin-bottom: 10px;
}
.balloon-loco-label {
  font-size: .8rem;
  color: #666;
  margin-bottom: 3px;
}
.balloon-loco-value {
  font-weight: 600;
  font-size: .95rem;
}
.balloon-loco-photo {
  max-width: 100%;
  border-radius: 4px;
  margin-top: 5px;
  display: block;
}
.balloon-votes {
  display: flex;
  gap: 12px;
  font-size: .85rem;
  color: #555;
  margin-top: 4px;
}
.balloon-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.balloon-actions .btn { font-size: .8rem; padding: 5px 12px; }
.balloon-admin {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 5px 8px;
  background: rgba(220,50,50,.08);
  border-left: 3px solid #e8453c;
  border-radius: 4px;
}
.balloon-admin-id {
  font-size: .78rem;
  color: #c0392b;
  font-family: monospace;
  flex: 1;
}
.btn-danger {
  background: #e8453c;
  color: #fff;
  border: none;
}
.btn-danger:hover { background: #c0392b; }
.balloon-loading {
  color: #999;
  font-size: .85rem;
  font-style: italic;
}

/* ---- Кластер ---- */
.cluster-list {
  font-family: system-ui, Arial, sans-serif;
  line-height: 1.6;
  max-height: 300px;
  overflow-y: auto;
  min-width: 200px;
  font-size: .9rem;
}
.cluster-list a {
  color: #1a73e8;
  text-decoration: none;
  cursor: pointer;
  display: block;
  padding: 2px 0;
}
.cluster-list a:hover { text-decoration: underline; }

/* ---- Модальное "нужна авторизация" ---- */
#auth-prompt .modal { text-align: center; }
#auth-prompt .modal p { color: var(--color-text-sec); font-size: .9rem; margin-bottom: 16px; }

/* ---- Комментарии в баллуне ---- */
.balloon-comments { margin-top: 12px; }
.balloon-comments-label {
  font-size: .8rem;
  color: #666;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.balloon-comments-list {
  max-height: 160px;
  overflow-y: auto;
  margin-bottom: 8px;
}
.balloon-comment {
  padding: 5px 0;
  border-bottom: 1px solid var(--color-border, #eee);
  font-size: .82rem;
}
.balloon-comment:last-child { border-bottom: none; }
.balloon-comment-author {
  font-weight: 600;
  color: var(--color-text, #222);
  margin-right: 4px;
}
.balloon-comment-author.admin { color: #d62;  }
.balloon-comment-time {
  font-size: .75rem;
  color: #999;
}
.balloon-comment-text {
  color: var(--color-text, #333);
  margin-top: 2px;
  white-space: pre-wrap;
  word-break: break-word;
}
.balloon-comment-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.balloon-comment-input {
  width: 100%;
  padding: 6px 8px;
  border: 1.5px solid var(--color-border, #ddd);
  border-radius: 6px;
  font-size: .85rem;
  resize: vertical;
  font-family: inherit;
  box-sizing: border-box;
}
.balloon-comment-input:focus { border-color: var(--color-primary, #1a73e8); outline: none; }
.balloon-votes { margin-top: 4px; gap: 8px; }
.btn-xs { font-size: .72rem !important; padding: 2px 8px !important; }

/* ---- Адаптив ---- */
@media (max-width: 600px) {
  #map-header { flex-wrap: wrap; padding: 6px 10px; gap: 6px; }
  #station-filter-wrap {
    order: 3;
    flex: 0 0 100%;
    max-width: none;
  }
  #map-header .spacer { display: none; }
  .loading-step { width: 260px; }
}

/* ---- Кнопка расписания в баллуне ---- */
.balloon-rzd-link { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: .82rem; }
.btn-sched {
  background: none;
  border: 1px solid var(--color-primary, #1a73e8);
  color: var(--color-primary, #1a73e8);
  border-radius: 5px;
  padding: 2px 10px;
  font-size: .82rem;
  cursor: pointer;
}
.btn-sched:hover { background: rgba(26,115,232,.08); }

/* ---- Модал расписания ---- */
.sched-modal-inner { max-width: 480px; position: relative; }
#sched-list { max-height: 60vh; overflow-y: auto; }
.sched-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--color-border);
  font-size: .875rem;
}
.sched-row:last-child { border-bottom: none; }
.sched-past { opacity: .45; }
.sched-date-sep {
  font-size: .75rem; font-weight: 600; color: var(--color-text-sec);
  text-align: center; padding: 6px 0 4px;
  border-top: 1px solid var(--color-border);
  margin-top: 2px; letter-spacing: .03em;
}
.sched-current { background: rgba(26,115,232,.08); border-radius: 4px; font-weight: 600; }
.sched-name { flex: 1; }
.sched-times { display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.sched-arr  { color: var(--color-text-sec); min-width: 38px; text-align: right; }
.sched-dep  { color: var(--color-primary, #1a73e8); min-width: 38px; }
.sched-stop { font-size: .75rem; color: var(--color-text-sec); min-width: 44px; text-align: center; }

/* ---- Тёмная тема: баллун Яндекс Карт ---- */
[data-theme="dark"] [class*="ymaps"][class*="balloon__layout"],
[data-theme="dark"] [class*="ymaps"][class*="balloon__content-body"],
[data-theme="dark"] [class*="ymaps"][class*="balloon__content"] {
  background: #1e1e2e !important;
  color: #e0e0e0 !important;
  border-color: #333 !important;
}
[data-theme="dark"] [class*="ymaps"][class*="balloon__tail"]::after {
  border-top-color: #1e1e2e !important;
}
[data-theme="dark"] [class*="ymaps"][class*="balloon__close-button"] {
  filter: invert(1);
}
[data-theme="dark"] .train-balloon { color: #e0e0e0; }
[data-theme="dark"] .balloon-title { color: #7aadff; }
[data-theme="dark"] .balloon-route { color: #999; }
[data-theme="dark"] .balloon-status { background: #2a2a3e; color: #ccc; }
[data-theme="dark"] .balloon-loco-label { color: #999; }
[data-theme="dark"] .balloon-votes { color: #aaa; }
[data-theme="dark"] .balloon-loading { color: #777; }
[data-theme="dark"] .balloon-comments-label { color: #888; }
[data-theme="dark"] .balloon-comment-time { color: #777; }
[data-theme="dark"] .balloon-comment { border-bottom-color: #333; }
[data-theme="dark"] .balloon-comment-input {
  background: #2a2a3e;
  color: #e0e0e0;
  border-color: #444;
}
[data-theme="dark"] .cluster-list a { color: #7aadff; }

/* ---- Модал: Топ наблюдателей ---- */
#top-modal .modal { max-width: 420px; position: relative; }
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: none;
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-sec);
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--color-border); }
.top-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.top-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--color-border);
}
.top-row-rank { font-size: 1.1rem; width: 24px; text-align: center; }
.top-row-name { flex: 1; }
.top-row-name--top3 { font-weight: 600; }
.top-row-count { color: var(--color-text-sec); font-size: .9rem; }
.top-empty {
  text-align: center;
  padding: 20px;
  color: var(--color-text-sec);
}

/* ---- ui-utils: toast ---- */
.ui-toast-wrap {
  position: fixed; top: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 99999; pointer-events: none;
}
.ui-toast {
  display: flex; align-items: center; gap: 8px;
  background: var(--color-surface, #23272f);
  border: 1px solid var(--color-border, #3a3f4b);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 220px; max-width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
  pointer-events: all;
  opacity: 0;
  transform: translateX(40px);
  transition: opacity .25s, transform .25s cubic-bezier(.34,1.56,.64,1);
}
.ui-toast.show { opacity: 1; transform: translateX(0); }
.ui-toast.hide { opacity: 0; transform: translateX(40px); transition: opacity .3s, transform .3s ease-in; }
.ui-toast-ico { font-size: 1.1rem; flex-shrink: 0; }
.ui-toast-txt { flex: 1; font-size: .875rem; color: var(--color-text, #e2e8f0); word-break: break-word; }
.ui-toast-cls {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-sec, #8b95a7); font-size: .8rem;
  padding: 0 2px; line-height: 1; flex-shrink: 0;
}
.ui-toast-cls:hover { color: var(--color-text, #e2e8f0); }
.ui-toast.t-ok  { border-color: #22c55e44; }
.ui-toast.t-err { border-color: #ef444444; }
.ui-toast.t-warn{ border-color: #f59e0b44; }

/* ---- ui-utils: confirm dialog ---- */
.ui-cdialog-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99998;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s;
}
.ui-cdialog-overlay.show { opacity: 1; }
.ui-cdialog {
  background: var(--color-surface, #23272f);
  border: 1px solid var(--color-border, #3a3f4b);
  border-radius: 12px;
  padding: 24px 24px 20px;
  min-width: 260px; max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  transform: scale(.88);
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}
.ui-cdialog-overlay.show .ui-cdialog { transform: scale(1); }
.ui-cdialog-msg { font-size: .95rem; color: var(--color-text, #e2e8f0); margin-bottom: 20px; line-height: 1.5; }
.ui-cdialog-btns { display: flex; justify-content: flex-end; gap: 8px; }
.ui-btn {
  padding: 7px 16px; border-radius: 8px; border: none;
  cursor: pointer; font-size: .875rem; font-weight: 500;
  transition: opacity .15s;
}
.ui-btn:hover { opacity: .85; }
.ui-btn-ghost   { background: var(--color-border, #3a3f4b); color: var(--color-text, #e2e8f0); }
.ui-btn-primary { background: var(--color-primary, #6366f1); color: #fff; }
.ui-btn-danger  { background: var(--color-danger, #ef4444); color: #fff; }
