/* ===========================================================
   MAX Mini App — стили для раздела «Наш Город / Сообщения»
   Mobile-first, минимальная ширина 375px, палец-френдли
   =========================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e3e5ea;
  --primary: #0a84ff;
  --primary-press: #006edc;
  --danger: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;

  --tap: 44px;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 12px;
  --pad: 16px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #0e0f12;
  --surface: #1a1c20;
  --surface-2: #232529;
  --text: #f5f5f7;
  --text-muted: #9aa0a6;
  --border: #2c2f34;
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; cursor: pointer; }
input, select, button, textarea { font-size: 16px; } /* iOS не зумит при >= 16px */

/* ============== Контейнер ============== */
.app {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(72px + var(--safe-bottom));
  max-width: 720px; margin: 0 auto;
}

/* ============== Шапка ============== */
.app-header {
  position: sticky; top: var(--safe-top); z-index: 10;
  display: grid; grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center; gap: 8px;
  padding: 8px var(--pad);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.app-title {
  margin: 0; font-size: 17px; font-weight: 600; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: var(--tap); height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; color: var(--text);
  border-radius: 50%; transition: background .15s;
}
.icon-btn:active { background: var(--surface-2); }

/* ============== Поиск + switch «В работе» ============== */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 12px var(--pad) 0;
  padding: 0 12px; height: var(--tap);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.search-bar input {
  flex: 1; height: 100%; min-width: 0;
  border: 0; outline: 0; background: transparent; color: var(--text);
}
.search-icon { color: var(--text-muted); flex-shrink: 0; }

.switch {
  display: inline-flex; align-items: center; gap: 6px;
  flex-shrink: 0; cursor: pointer; user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 34px; height: 20px; background: var(--surface-2);
  border-radius: 999px; position: relative; transition: background .2s;
  flex-shrink: 0;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(14px); }
.switch-label { font-size: 13px; color: var(--text-muted); }

/* ============== Чипы ============== */
.chips {
  display: flex; gap: 8px;
  overflow-x: auto; padding: 12px var(--pad);
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0; min-height: 36px;
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 14px;
  scroll-snap-align: start;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip:active { transform: scale(0.97); }
.chips.small .chip { min-height: 32px; padding: 4px 12px; font-size: 13px; }

/* ============== Доп. фильтры ============== */
.filters {
  margin: 0 var(--pad);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.filters-toggle {
  width: 100%; min-height: var(--tap);
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; background: transparent; border: 0;
  color: var(--text); font-weight: 500;
}
.filters-toggle > span:first-child { flex: 1; text-align: left; }
.filters-toggle .chev { transition: transform .2s; color: var(--text-muted); flex-shrink: 0; }
.filters-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.filters-count {
  background: var(--primary); color: #fff;
  font-size: 12px; min-width: 20px; height: 20px;
  border-radius: 999px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
}

.filters-panel {
  padding: 8px 14px 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 14px;
}
.filter-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.filter-row.column { flex-direction: column; align-items: stretch; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.filter-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text); line-height: 1.25;
}
.filter-label small { color: var(--text-muted); font-size: 12px; }
.filter-title { font-size: 13px; color: var(--text-muted); font-weight: 500; }

.grip {
  width: 10px; height: 18px;
  background-image: radial-gradient(circle, var(--text-muted) 1.2px, transparent 1.4px);
  background-size: 4px 4px; background-position: 0 0;
  opacity: .55; flex-shrink: 0; cursor: grab;
}

.sort-arrows { display: flex; flex-direction: column; gap: 2px; }
.sort-arrows .arrow {
  width: 18px; height: 12px;
  background: transparent; border: 0; padding: 0;
  color: var(--text-muted); position: relative;
}
.sort-arrows .arrow::before {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
}
.sort-arrows .arrow.up::before    { border-bottom: 6px solid currentColor; top: 1px; }
.sort-arrows .arrow.down::before  { border-top: 6px solid currentColor; bottom: 1px; }
.sort-arrows .arrow.active        { color: var(--primary); }

.funnel-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.funnel-btn:active { background: var(--surface-2); }

/* ============== Multiselect: проблемная тема ============== */
.multiselect { position: relative; }
.multiselect-trigger {
  width: 100%; min-height: var(--tap);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); text-align: left;
}
.multiselect-trigger:active { background: var(--surface-2); }

.multiselect-panel {
  margin-top: 6px; padding: 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); max-height: 320px; overflow: hidden;
  display: flex; flex-direction: column; gap: 8px;
}
.multiselect-search {
  height: 36px; padding: 0 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); outline: 0;
}
.multiselect-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; max-height: 240px;
  -webkit-overflow-scrolling: touch;
}
.multiselect-list li {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 6px 4px;
  font-size: 14px; cursor: pointer;
}
.multiselect-list li.road { color: var(--primary); font-weight: 500; }
.multiselect-list input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--primary);
}

/* ============== Период ============== */
.date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.date-range label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-muted);
}
.date-range input, .select {
  height: var(--tap); padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); width: 100%;
}

.filters-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }

/* ============== Мета-строка ============== */
.list-meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px var(--pad) 6px;
  font-size: 13px; color: var(--text-muted);
}
.link-btn {
  background: transparent; border: 0; color: var(--primary);
  font-weight: 500; min-height: 32px; padding: 0 4px;
}

/* ============== Карточки ============== */
.list { display: flex; flex-direction: column; gap: var(--gap); padding: 8px var(--pad) var(--pad); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .12s, box-shadow .12s;
}
.card:active { transform: scale(0.995); box-shadow: 0 1px 4px rgba(0,0,0,.06); }

.card-head { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--text);
}
/* Категории объекта */
.badge-roads        { background: #ffe9d6; color: #b35400; }
.badge-yards        { background: #e6f0ff; color: #0a4fb3; }
.badge-houses       { background: #e0e7ff; color: #2840b0; }
.badge-parks        { background: #d8f5e0; color: #1f7a3a; }
.badge-city         { background: #f0e7ff; color: #5b2db3; }
.badge-transport    { background: #fff3cd; color: #8a6d00; }
.badge-construction { background: #ffe1de; color: #b3261e; }
.badge-institutions { background: var(--surface-2); color: var(--text-muted); }

/* Статусы */
.badge-status.badge-preparing  { background: #fff4cc; color: #8a6d00; }
.badge-status.badge-on_review  { background: #e6f0ff; color: #0a4fb3; }
.badge-status.badge-rework     { background: #ffe1de; color: #b3261e; }
.badge-status.badge-published  { background: #d8f5e0; color: #1f7a3a; }
.badge-status.badge-overdue    { background: #ffd0cc; color: #a01b14; }

/* Критичность */
.badge-criticality.badge-low   { background: #fff4cc; color: #8a6d00; }
.badge-criticality.badge-high  { background: #ffd0cc; color: #a01b14; }

.card-title { margin: 0; font-size: 16px; font-weight: 600; }
.card-topic { margin: 0; font-size: 14px; color: var(--text); }

.card-address {
  margin: 0; font-size: 14px; color: var(--text);
  display: flex; align-items: flex-start; gap: 6px;
}
.card-address svg { color: var(--text-muted); margin-top: 2px; flex-shrink: 0; }

.card-meta {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 6px; margin: 0;
  font-size: 12px; color: var(--text-muted);
}
.card-meta div { display: flex; flex-direction: column; gap: 2px; }
.card-meta dt { font-size: 11px; opacity: .8; }
.card-meta dd { margin: 0; color: var(--text); font-weight: 500; }

.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }

/* ============== Кнопки ============== */
.btn {
  min-height: var(--tap); padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 15px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, opacity .15s, transform .1s;
}
.btn:active { transform: scale(0.98); }
.btn.block  { width: 100%; }
.btn-sm     { min-height: 38px; padding: 0 12px; font-size: 14px; }

.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-press); }

.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost:active { background: var(--surface-2); }

/* ============== Футер ============== */
.app-footer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  padding: 10px var(--pad) calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(0,0,0,0));
}
.app-footer .btn { max-width: 720px; margin: 0 auto; }

/* ============== Состояния ============== */
.empty, .loading {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}

/* ============== Адаптив ============== */
@media (max-width: 375px) {
  :root { --pad: 12px; }
  .app-title { font-size: 16px; }
  .card-title { font-size: 15px; }
  .card-actions { grid-template-columns: 1fr; }
  .card-meta { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 480px) {
  .filter-label { font-size: 14px; }
  .card-meta { font-size: 13px; }
}

/* ===========================================================
   Экран деталей заявки
   =========================================================== */
.details {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  /* плавный вход */
  animation: dvIn .18s ease-out;
}
@keyframes dvIn {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.details[hidden] { display: none; }

.details-header {
  display: grid; grid-template-columns: 44px 1fr 44px;
  align-items: center; gap: 8px;
  padding: 8px var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.details-title { min-width: 0; text-align: center; }
.details-title-main {
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.details-title-sub {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.details-body {
  flex: 1; overflow-y: auto;
  padding: var(--pad);
  padding-bottom: calc(80px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.details-badges {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px;
}

.details-topic {
  font-size: 17px; font-weight: 600; line-height: 1.35;
  margin: 0 0 12px;
  word-wrap: break-word; overflow-wrap: anywhere;
}

.details-address-block {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  margin-bottom: 12px;
}
.details-address {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 0; color: var(--text); font-size: 15px;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.details-address svg { flex: none; margin-top: 2px; color: var(--text-muted); }
.details-district {
  margin: 4px 0 0 24px; color: var(--text-muted); font-size: 13px;
}
.details-district:empty { display: none; }

.details-meta {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0 0 12px;
}
.details-meta > div {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  min-width: 0;
}
.details-meta dt {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .3px;
  margin: 0 0 2px;
}
.details-meta dd {
  margin: 0; font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.details-deadline {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 12px;
}
.details-deadline.urgent  { border-left-color: var(--warning); }
.details-deadline.overdue { border-left-color: var(--danger); }
.details-deadline-label { color: var(--text-muted); font-size: 13px; }
.details-deadline-val   { font-weight: 600; font-size: 15px; }

.details-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  margin-bottom: 12px;
}
.details-section h3 {
  margin: 0 0 8px; font-size: 13px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px;
}
.details-text {
  margin: 0; font-size: 14px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}

.details-photos {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.details-photos img {
  width: 100%; aspect-ratio: 1/1; object-fit: cover;
  border-radius: var(--radius-sm); background: var(--surface-2);
  cursor: pointer;
}

.details-history {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 10px;
}
.details-history-item {
  border-left: 2px solid var(--border); padding-left: 10px;
}
.details-history-item .h-meta {
  font-size: 12px; color: var(--text-muted); margin-bottom: 2px;
}
.details-history-item .h-body {
  font-size: 14px; line-height: 1.45;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.details-history-empty {
  color: var(--text-muted); font-size: 13px; list-style: none;
}

.details-links { display: flex; flex-direction: column; gap: 8px; }
.details-link {
  color: var(--primary); text-decoration: none; font-size: 14px;
  padding: 4px 0;
}
.details-link:active { color: var(--primary-press); }

.details-actions {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 3;
  display: grid; grid-template-columns: 1fr 2fr; gap: 8px;
  padding: 10px var(--pad) calc(10px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
  max-width: 720px; margin: 0 auto;
}
.details-actions .btn {
  min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}

/* Когда детали открыты, прячем основной BackButton/header иконки фокуса */
body.details-open { overflow: hidden; }

/* «Следить» включено */
.btn-watching {
  background: var(--success) !important;
  border-color: var(--success) !important;
  color: #fff !important;
}

/* Адаптив для деталей */
@media (max-width: 375px) {
  .details-meta { grid-template-columns: 1fr; }
  .details-photos { grid-template-columns: repeat(2, 1fr); }
}
