:root {
  --bg: #0f1419;
  --bg-elevated: #121820;
  --card: #1a2332;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #5b9cff;
  --price: #7dffb3;
  --border: #2a3544;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --workspace-gap: 1rem;
  --panel-pad: 1.1rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[data-density="compact"] {
  --workspace-gap: 0.65rem;
  --panel-pad: 0.75rem;
  --radius: 10px;
}

[data-density="spacious"] {
  --workspace-gap: 1.35rem;
  --panel-pad: 1.35rem;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.brand h1 { margin: 0; font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.92rem; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.meta { color: var(--muted); font-size: 0.85rem; white-space: nowrap; max-width: min(420px, 50vw); overflow: hidden; text-overflow: ellipsis; }
.meta.meta-warn { color: #e8a54b; }
.meta.meta-bad { color: #e07070; }
.meta.meta-ok { color: var(--muted); }

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.stats-bar .stat strong { color: var(--text); }

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(200px, 230px) minmax(0, 2.5fr) minmax(240px, 280px);
  gap: var(--workspace-gap);
  padding: var(--workspace-gap) 0.65rem 0.85rem;
  max-width: none;
  width: 100%;
  margin: 0;
  align-items: stretch;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: var(--shadow);
}

.panel-head {
  padding: var(--panel-pad);
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.panel-head-inline {
  flex-wrap: wrap;
  gap: 0.65rem;
}

.panel-head-inline .toolbar-actions {
  flex: 1 1 100%;
  justify-content: flex-end;
}

@media (min-width: 900px) {
  .panel-head-inline .toolbar-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
  }
}

.panel-body {
  padding: var(--panel-pad);
  flex: 1;
  min-height: 0;
}

.panel-body-scroll {
  overflow-y: auto;
  max-height: calc(100vh - 118px);
}

.panel-list {
  min-height: calc(100vh - 88px);
}

.panel-list .panel-body-scroll {
  max-height: calc(100vh - 108px);
  min-height: calc(100vh - 160px);
}

.filter-search-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}

.filter-search-row input[type="search"] {
  flex: 1;
  min-width: 0;
}

.filter-search-row .btn {
  flex-shrink: 0;
  white-space: nowrap;
  padding-left: 0.85rem;
  padding-right: 0.85rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.ai-search-bar-wrap {
  display: flex;
  flex: 1 1 280px;
  min-width: 200px;
  max-width: 520px;
  gap: 0.35rem;
}

.ai-search-bar {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
}

.btn-accent {
  background: color-mix(in srgb, var(--accent) 28%, var(--card));
  border-color: var(--accent);
  font-weight: 600;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field > span {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.field-check span { text-transform: none; font-size: 0.88rem; color: var(--text); }

input[type="search"],
input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

textarea { resize: vertical; min-height: 88px; }

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
  background: color-mix(in srgb, var(--accent) 18%, var(--card));
  border-color: var(--accent);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.35rem 0.55rem;
}

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.btn-block { width: 100%; }

.view-toggle { display: inline-flex; gap: 2px; }
.view-toggle .btn.active {
  background: color-mix(in srgb, var(--accent) 22%, var(--card));
  border-color: var(--accent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.chip-clear { color: var(--muted); }

mark {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  color: inherit;
  border-radius: 2px;
  padding: 0 0.1em;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.list.grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.list.grid-view .card {
  grid-template-columns: 1fr;
  padding: 0;
  overflow: hidden;
}

.list.grid-view .card .thumb-wrap {
  display: block;
}

.list.grid-view .card .thumb {
  width: 100%;
  height: 180px;
  border-radius: 0;
}

.list.grid-view .card-body {
  padding: 0.85rem 1rem 1rem;
}

.list.grid-view .card.no-img .card-body {
  padding-top: 1rem;
}

.card {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  transition: border-color 0.15s;
}

.card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

.card-clickable { cursor: pointer; }
.card-clickable .thumb-wrap { cursor: pointer; }

.card.no-img { grid-template-columns: 1fr; }

.card .thumb {
  width: 140px;
  height: 105px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--border);
}

.thumb-wrap { display: block; line-height: 0; }

.card-body { min-width: 0; }

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.card-top h2 {
  margin: 0;
  flex: 1;
  font-size: 1.08rem;
  font-weight: 600;
  min-width: 0;
}

.fav-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
}

.fav-btn:hover,
.fav-btn.active {
  color: #ffc857;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.badge-drop {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.12rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: middle;
  border-radius: 4px;
  color: #0d3b24;
  background: color-mix(in srgb, var(--price) 55%, #fff);
  border: 1px solid color-mix(in srgb, var(--price) 40%, var(--border));
}

.badge-deal {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.12rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.badge-deal.hot {
  color: #3b1208;
  background: #ffb080;
  border-color: #e07840;
}
.badge-deal.warm {
  color: #3a2a08;
  background: #ffe08a;
  border-color: #d4b040;
}
.badge-deal.ok {
  color: var(--muted);
  background: color-mix(in srgb, var(--card) 80%, var(--border));
}
.badge-deal.cold {
  color: var(--muted);
  background: transparent;
  opacity: 0.85;
}

.stat-drop { color: var(--price); font-weight: 600; }
.stat-deal { color: #e09050; font-weight: 600; }

.detail-deal {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--muted);
}

.detail-price-drop {
  margin: 0.35rem 0 0;
  color: var(--price);
  font-size: 0.92rem;
  font-weight: 600;
}

.detail-price-history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  font-size: 0.88rem;
}

.detail-price-history li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.detail-price-history .ph-when { color: var(--muted); }
.detail-price-history .ph-amount { font-weight: 600; }

.card .price {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--price);
  margin-bottom: 0.3rem;
}

.card .loc { color: var(--muted); font-size: 0.88rem; margin-bottom: 0.45rem; }

.card .desc {
  color: var(--muted);
  font-size: 0.88rem;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.65rem;
}

.card .meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.card .link {
  display: inline-block;
  font-size: 0.88rem;
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.panel-ai-body { display: flex; flex-direction: column; }

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  line-height: 1.4;
}

.section-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.watch-panel {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.watch-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  max-height: 180px;
  overflow-y: auto;
}

.watch-item {
  padding: 0.55rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.watch-item-off { opacity: 0.55; }

.watch-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.watch-meta {
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0.25rem 0 0.35rem;
}

.watch-form .btn-block { margin-top: 0.35rem; }

.catalog-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.catalog-tab {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
}

.catalog-tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg));
}

.listing-group {
  margin-bottom: 1.25rem;
}

.group-title {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.group-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

.group-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.grid-view .group-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
}

.card-archived {
  opacity: 0.88;
  border-style: dashed;
}

.thumb-wrap {
  position: relative;
}

.badge-archived {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  z-index: 1;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: color-mix(in srgb, #888 75%, transparent);
  color: #fff;
}

.badge-inline {
  position: static;
  display: inline-block;
  margin: 0.35rem 0 0 0.35rem;
}

.ai-status {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.ai-status.error { color: #ff9a9a; }

.ai-output {
  margin-top: 0.75rem;
  padding: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  white-space: pre-wrap;
  max-height: min(50vh, 480px);
  overflow-y: auto;
  line-height: 1.55;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1.25rem;
  max-width: 36rem;
  margin: 2rem auto;
}
.empty-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  color: var(--text);
  font-weight: 600;
}
.empty-hint {
  margin: 0;
  line-height: 1.5;
  font-size: 0.92rem;
}
.empty-meta {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--muted);
}

.footer {
  text-align: center;
  padding: 0.85rem 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.error {
  background: color-mix(in srgb, #c44 12%, var(--card));
  border: 1px solid color-mix(in srgb, #c44 35%, var(--border));
  color: #ffb4b4;
  padding: 1rem;
  border-radius: var(--radius-sm);
}

.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(520px, 94vw);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-inner {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0;
  padding: 0;
  color: var(--text);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 { margin: 0; font-size: 1.1rem; }

.modal-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1rem 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.modal-body {
  padding: 1rem 1.15rem;
  max-height: 60vh;
  overflow-y: auto;
}

.modal-body h3 {
  margin: 1rem 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.modal-body h3:first-child { margin-top: 0; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.15rem;
  border-top: 1px solid var(--border);
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.color-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.color-field input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

@media (max-width: 1200px) {
  .workspace {
    grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  }
  .panel-ai {
    grid-column: 1 / -1;
    max-height: 420px;
  }
  .panel-ai .panel-body-scroll,
  .panel-ai-body { max-height: none; }
}

.modal-detail {
  max-width: min(960px, 96vw);
  width: 100%;
}

.modal-detail::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.detail-inner {
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.detail-body {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 1.2fr);
  gap: 1.25rem;
  overflow-y: auto;
}

.detail-gallery-main img {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.detail-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.detail-thumb {
  border: 2px solid transparent;
  padding: 0;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: none;
  width: 64px;
  height: 48px;
}

.detail-thumb.active { border-color: var(--accent); }

.detail-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-no-photo {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.detail-price {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--price);
  margin-bottom: 0.35rem;
}

.detail-loc { color: var(--muted); margin-bottom: 0.5rem; }

.detail-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.detail-block h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.detail-desc {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 0.95rem;
}

.detail-params {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
}

#detail-seller {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.seller-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.seller-name { font-weight: 600; }

#detail-contacts a {
  font-size: 1.1rem;
  font-weight: 600;
}

.detail-foot {
  justify-content: space-between;
  align-items: center;
}

body.detail-open { overflow: hidden; }

@media (max-width: 768px) {
  .detail-body { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 0.75rem;
  }
  .panel-body-scroll { max-height: none; }
  .card { grid-template-columns: 100px 1fr; }
  .card .thumb { width: 100px; height: 75px; }
}
