:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #637083;
  --primary: #1d4ed8;
  --line: #dce3f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  width: min(1400px, 96vw);
  margin: 0 auto;
}

.header {
  background: linear-gradient(140deg, #163d94, #2a63dc);
  color: #fff;
  padding: 24px 0;
}

.header h1 {
  margin: 0 0 6px;
}

.header p {
  margin: 0 0 16px;
  opacity: 0.95;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
}

.tab.active {
  background: #fff;
  color: #163d94;
}

main {
  padding: 20px 0 28px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.muted {
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.sticky {
  position: sticky;
  top: 10px;
  z-index: 5;
  box-shadow: 0 10px 20px rgba(17, 24, 39, 0.06);
}

.controls-top {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.search {
  flex: 1;
  min-width: 260px;
}

.advanced-filters summary {
  cursor: pointer;
  margin-top: 8px;
  font-weight: 600;
}

.dynamic-filters {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.dynamic-filters .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: #f8fbff;
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}

.dynamic-filters .field-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.dual-range-wrap {
  position: relative;
  height: 20px;
}

.dual-range-wrap input[type="range"] {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 20px;
  margin: 0;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.dual-range-wrap input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: #dce3f0;
}

.dual-range-wrap input.dual-max::-webkit-slider-runnable-track {
  background: transparent;
}

.dual-range-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  margin-top: -6px;
  pointer-events: auto;
  cursor: pointer;
}

.dual-range-wrap input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #dce3f0;
}

.dual-range-wrap input.dual-max::-moz-range-track {
  background: transparent;
}

.dual-range-wrap input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  pointer-events: auto;
  cursor: pointer;
}

.range-values {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.range-sep {
  color: var(--muted);
  font-size: 12px;
}

.range-badge {
  display: inline-block;
  min-width: 48px;
  padding: 2px 6px;
  font-size: 12px;
  border-radius: 999px;
  background: #eef3ff;
  color: #1f2937;
  text-align: center;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  min-width: 0;
}

.dynamic-filters select,
.dynamic-filters input {
  width: 100%;
  min-width: 0;
}

label.inline {
  display: flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

input,
select,
textarea,
button {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

button {
  border: 0;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

button.secondary {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-card {
  padding: 0;
  overflow: hidden;
}

.table-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.results-bar {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.results-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap::-webkit-scrollbar {
  height: 6px;
}

.table-wrap::-webkit-scrollbar-track {
  background: var(--line);
  border-radius: 3px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #a0aec0;
  border-radius: 3px;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #718096;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1000px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  background: #f8fbff;
  z-index: 1;
  cursor: pointer;
}

th.sortable .sort-mark {
  font-size: 11px;
  opacity: 0.7;
}

th.sortable:hover {
  background: #edf4ff;
}

th.img-col,
td.img-cell {
  width: 44px;
  padding: 3px;
  text-align: center;
  vertical-align: middle;
}

th.img-col-previews,
td.img-previews {
  width: auto;
  min-width: 120px;
  max-width: 420px;
  text-align: left;
}

.img-preview-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.house-thumb-btn {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  line-height: 0;
}

td.img-cell img.house-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

td.img-cell img.house-thumb:hover {
  outline: 2px solid rgba(29, 78, 216, 0.45);
}

.house-thumb-placeholder {
  color: var(--muted);
  font-size: 13px;
  padding: 4px;
}

.image-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
}

.image-modal.open {
  display: block;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.image-modal-content {
  position: relative;
  z-index: 1;
  width: min(95vw, 1200px);
  height: min(90vh, 860px);
  margin: 5vh auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-modal-img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
  background: #111;
}

.image-modal-close,
.image-modal-nav {
  position: absolute;
  border: 0;
  background: rgba(29, 78, 216, 0.95);
  color: #fff;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.image-modal-close {
  top: 10px;
  right: 10px;
}

.image-modal-nav.prev {
  left: 14px;
}

.image-modal-nav.next {
  right: 14px;
}

.image-modal-counter {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  background: rgba(15, 23, 42, 0.68);
  border-radius: 999px;
  padding: 6px 10px;
}

body.modal-open {
  overflow: hidden;
}

td.img-cell img:not(.house-thumb) {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  display: block;
}

.section-header {
  margin-bottom: 16px;
}

.section-header h2 {
  margin: 0 0 4px;
}

.section-header .muted {
  margin: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
  border-radius: 12px 12px 0 0;
}

.card-header h3 {
  margin: 0;
  font-size: 15px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.forum-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}

.forum-sidebar {
  position: sticky;
  top: 10px;
  padding: 0;
}

.forum-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.forum-main .card {
  padding: 0;
}

.forum-branches {
  list-style: none;
  margin: 0;
  padding: 0;
}

.forum-branches li {
  border-bottom: 1px solid var(--line);
}

.forum-branches li:last-child {
  border-bottom: none;
}

.forum-branches button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.forum-branches button:hover {
  background: #f0f6ff;
}

.forum-branches button.active {
  background: var(--primary);
  color: #fff;
}

.forum-branches .branch-desc {
  font-size: 12px;
  opacity: 0.7;
}

.forum-topics,
.forum-posts {
  list-style: none;
  margin: 0;
  padding: 0;
}

.forum-topics li {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.15s;
}

.forum-topics li:hover {
  background: #f8fbff;
}

.forum-topics li.active {
  background: #eef4ff;
  border-left: 3px solid var(--primary);
}

.forum-topics .topic-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.forum-topics .topic-meta {
  font-size: 12px;
  color: var(--muted);
}

.forum-posts li {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.forum-posts .post-author {
  font-weight: 600;
  font-size: 14px;
}

.forum-posts .post-date {
  font-size: 12px;
  color: var(--muted);
  margin-left: 8px;
}

.forum-posts .post-content {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
}

.topic-form,
.post-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  background: #f8fbff;
  border-top: 1px solid var(--line);
}

.topic-form input,
.post-form input {
  flex: 1;
  min-width: 120px;
  max-width: 200px;
}

.topic-form input[name="title"] {
  flex: 2;
  max-width: none;
}

.post-form textarea {
  width: 100%;
  resize: vertical;
}

.post-form button {
  margin-left: auto;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.blog-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
}

.blog-card:hover {
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.1);
  transform: translateY(-2px);
}

.blog-card-img {
  height: 160px;
  background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.blog-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.blog-card-icon {
  font-size: 48px;
  color: var(--primary);
}

.blog-card-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.blog-card-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 8px;
  line-height: 1.3;
}

.blog-card-title a {
  color: var(--text);
  text-decoration: none;
}

.blog-card-title a:hover {
  color: var(--primary);
}

.blog-card-excerpt {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  flex: 1;
}

.blog-card-meta {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

.empty-state {
  padding: 24px 14px;
  text-align: center;
  color: var(--muted);
  font-style: italic;
}

/* SEO catalog (embedded on picker page) */
.seo-catalog {
  margin-top: 12px;
}

.seo-catalog summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}

.seo-catalog .seo-links {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}

.seo-catalog .seo-links a {
  display: block;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
}

.seo-catalog .seo-links a:hover {
  border-color: rgba(29, 78, 216, 0.4);
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.06);
}

.seo-catalog .seo-links .muted {
  font-size: 12px;
}

.forum-topics .empty-state,
.forum-posts .empty-state {
  border-bottom: none;
  cursor: default;
}

.forum-topics .empty-state:hover {
  background: transparent;
}

/* ===== MOBILE STYLES ===== */

@media (max-width: 980px) {
  .picker-filters.sticky {
    position: static;
    box-shadow: none;
  }
}

@media (max-width: 768px) {
  /* Header */
  .header {
    padding: 16px 0;
  }

  .header h1 {
    font-size: 22px;
  }

  .header p {
    font-size: 14px;
    margin-bottom: 12px;
  }

  .tabs {
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    padding: 8px 12px;
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Main */
  main {
    padding: 12px 0 20px;
  }

  .container {
    width: 100%;
    padding: 0 12px;
  }

  .section-header h2 {
    font-size: 20px;
  }

  /* Cards */
  .card {
    border-radius: 10px;
    padding: 8px 10px;
  }

  /* Picker Controls */
  .controls-top {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .search {
    min-width: 100%;
  }

  .checkbox {
    font-size: 14px;
  }

  .advanced-filters summary {
    font-size: 14px;
  }

  .advanced-filters[open] {
    max-height: 60vh;
    overflow-y: auto;
  }

  .dynamic-filters {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .dynamic-filters .field {
    padding: 8px 10px;
  }

  /* Results bar */
  .results-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .results-right {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .results-right label.inline {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    white-space: normal;
  }

  .results-right label.inline select {
    width: 100%;
  }

  .pager {
    justify-content: center;
  }

  /* Table */
  .table-card {
    border-radius: 10px;
  }

  .table-head {
    padding: 10px 12px;
  }

  table {
    min-width: 800px;
  }

  th, td {
    padding: 8px 6px;
    font-size: 12px;
  }

  th.img-col-previews,
  td.img-previews {
    min-width: 100px;
    max-width: 280px;
  }

  td.img-cell img.house-thumb {
    width: 32px;
    height: 32px;
  }

  /* Forum */
  .forum-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .forum-sidebar {
    position: static;
  }

  .forum-branches button {
    padding: 14px 12px;
  }

  .card-header {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .card-header h3 {
    font-size: 14px;
  }

  .btn-sm {
    padding: 8px 14px;
    font-size: 14px;
  }

  .forum-topics li {
    padding: 14px 12px;
  }

  .forum-topics .topic-title {
    font-size: 15px;
  }

  .forum-posts li {
    padding: 14px 12px;
  }

  .forum-posts .post-author {
    font-size: 15px;
  }

  .forum-posts .post-date {
    display: block;
    margin-left: 0;
    margin-top: 2px;
  }

  .forum-posts .post-content {
    font-size: 15px;
  }

  .topic-form,
  .post-form {
    flex-direction: column;
    padding: 12px;
  }

  .topic-form input,
  .post-form input {
    max-width: none;
    min-width: 100%;
  }

  .topic-form input[name="title"] {
    flex: none;
  }

  .post-form button {
    margin-left: 0;
    width: 100%;
  }

  .form-actions {
    width: 100%;
  }

  .form-actions button {
    flex: 1;
  }

  /* Blog */
  .blog-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .blog-card {
    border-radius: 10px;
  }

  .blog-card-img {
    height: 180px;
  }

  .blog-card-body {
    padding: 14px;
  }

  .blog-card-title {
    font-size: 16px;
  }

  .blog-card-excerpt {
    font-size: 14px;
  }
}

/* Extra small screens */
@media (max-width: 400px) {
  .header h1 {
    font-size: 20px;
  }

  .tab {
    padding: 6px 10px;
    font-size: 13px;
  }

  .dual-range-wrap input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -8px;
  }

  .dual-range-wrap input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
  }

  .range-badge {
    min-width: 42px;
    font-size: 11px;
  }

  table {
    min-width: 700px;
  }

  th, td {
    font-size: 11px;
    padding: 6px 4px;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .tab {
    padding: 12px 16px;
  }

  button, 
  .forum-branches button,
  .forum-topics li {
    min-height: 44px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
    padding: 12px;
  }

  .checkbox input {
    width: 22px;
    height: 22px;
  }
}

/* Статические страницы блога / форума (SEO) */
.header .tabs a.tab {
  color: #fff;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  opacity: 0.95;
}
.header .tabs a.tab:hover {
  background: rgba(255, 255, 255, 0.12);
}
.blog-comments-card {
  margin-top: 20px;
}
.blog-comments {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}
.blog-comments .blog-comment {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.blog-comment-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.blog-comment-form label {
  display: block;
  margin-bottom: 12px;
}
.blog-comment-form input[type="text"],
.blog-comment-form textarea {
  width: 100%;
  max-width: 560px;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
.blog-static-list .blog-card-static {
  margin-bottom: 16px;
}
.forum-static-branches,
.forum-topic-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.forum-post-static {
  margin-bottom: 14px;
}
.forum-post-body {
  margin-top: 8px;
  line-height: 1.5;
}

/* Wall material multiselect dropdown with checkboxes */
.wm-multi {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.wm-multi > summary {
  cursor: pointer;
  padding: 9px 12px;
  list-style: none;
  user-select: none;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wm-multi > summary::-webkit-details-marker {
  display: none;
}

.wm-options {
  max-height: 150px;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 6px 8px 6px 6px;
  display: grid;
  gap: 2px;
  text-align: left;
}

.wm-option {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  font-size: 13px;
  white-space: nowrap;
  text-align: left;
  padding: 1px 0;
}

.wm-option span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  text-align: left;
}

.wm-option input[type="checkbox"] {
  width: auto !important;
  min-width: 0 !important;
  height: auto;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
}

.wm-tools {
  border-top: 1px solid var(--line);
  padding: 6px;
  display: grid;
  gap: 6px;
}

.wm-search {
  width: 100%;
  padding: 6px 8px;
}

.wm-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-start;
}

.wm-actions button {
  padding: 4px 8px;
  font-size: 12px;
}
