:root {
  --blue: #1957ff;
  --blue-dark: #0f3fc9;
  --blue-soft: #eaf0ff;
  --avito-color: #04a595;
  --avito-soft: #e2f7f4;
  --cian-color: #1957ff;
  --cian-soft: #eaf0ff;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --text: #12131a;
  --text-muted: #6b7280;
  --border: #e7e9ee;
  --danger: #ff4d4f;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 14px rgba(16, 24, 40, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f14;
    --surface: #1a1d24;
    --text: #eef0f4;
    --text-muted: #9aa0ac;
    --border: #2a2e38;
    --avito-soft: #10322d;
    --cian-soft: #16233f;
    --blue-soft: #16233f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: calc(64px + var(--safe-bottom));
}

button { font: inherit; }
a { color: inherit; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--blue), #4e7bff);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 17px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.icon-btn:active { transform: scale(0.92); background: var(--bg); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.topbar-actions { display: flex; gap: 8px; }

.notify-hint {
  margin: 0 16px 10px;
  padding: 10px 12px;
  background: var(--blue-soft);
  color: var(--text);
  border-radius: var(--radius-md);
  font-size: 12.5px;
  line-height: 1.4;
}
.notify-hint.hidden { display: none; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px 10px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 0;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.filters-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 12px;
}
.filters-bar .chip-row { flex: 1; min-width: 0; }
.filter-toggle-btn { flex-shrink: 0; }

.filters {
  padding: 0 16px 0;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height .25s ease, opacity .2s ease, padding-bottom .25s ease;
}
.filters.open {
  max-height: 220px;
  opacity: 1;
  padding-bottom: 12px;
}

.icon-btn { position: relative; }
.icon-dot {
  position: absolute; top: 5px; right: 5px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  border: 1.5px solid var(--surface);
}
.icon-dot.hidden { display: none; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s ease;
}
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.filter-controls { display: flex; gap: 8px; }
.select {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-size: 16px;
  min-width: 0;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}
.search-icon { color: var(--text-muted); flex-shrink: 0; }
.search-row input {
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  font-size: 16px;
  width: 100%;
}

/* Feed */
.feed { padding: 12px; display: flex; flex-direction: column; gap: 12px; min-height: 40vh; }

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: fadeIn .25s ease;
  border: 1px solid var(--border);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card.removing { animation: fadeOut .2s ease forwards; }
@keyframes fadeOut { to { opacity: 0; transform: scale(.97); } }

.card-media { position: relative; width: 100%; aspect-ratio: 16/10.5; background: var(--bg); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.card-media .thumb-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13px;
  background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 10px, var(--surface) 10px, var(--surface) 20px);
}
.badge {
  position: absolute; top: 10px; left: 10px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: #fff;
  backdrop-filter: blur(4px);
}
.badge.avito { background: color-mix(in srgb, var(--avito-color) 88%, transparent); }
.badge.cian { background: color-mix(in srgb, var(--cian-color) 88%, transparent); }
.badge-archived {
  position: absolute; top: 10px; right: 10px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; color: #fff;
  background: rgba(20,20,20,.55);
}

.card-body { padding: 12px 14px 6px; cursor: pointer; }
.card-price { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.card-title { font-size: 14px; color: var(--text); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.card-address { font-size: 13px; color: var(--text-muted); margin-top: 3px; display: flex; gap: 4px; align-items: flex-start; }
.card-address svg { flex-shrink: 0; margin-top: 2px; color: var(--blue); }
.card-address a, .detail-address a { color: inherit; text-decoration: none; }
.card-address a:hover, .detail-address a:hover { text-decoration: underline; color: var(--blue); }
.card-updated { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.card-note-preview {
  margin: 8px 14px 0;
  padding: 8px 10px;
  background: var(--blue-soft);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
}

.card-actions {
  display: flex;
  border-top: 1px solid var(--border);
  margin-top: 10px;
}
.card-actions button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 11px 6px;
  font-size: 13px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer;
  border-right: 1px solid var(--border);
  transition: background .15s ease;
}
.card-actions button:last-child { border-right: none; }
.card-actions button:active { background: var(--bg); }
.card-actions .act-open { color: var(--blue); }
.card-actions .act-archive { color: var(--text-muted); }
.card-actions .act-archive.is-archived { color: var(--danger); }
.card-actions .act-comment.has-note { color: var(--blue); }

/* Skeleton */
.skeleton-list { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.skeleton-card { height: 280px; border-radius: var(--radius-lg); background: linear-gradient(100deg, var(--surface) 30%, var(--border) 50%, var(--surface) 70%); background-size: 300% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 120% 0; } 100% { background-position: -20% 0; } }

/* Empty state */
.empty-state { text-align: center; padding: 60px 24px; color: var(--text-muted); }
.empty-state.hidden { display: none; }
.empty-emoji { font-size: 40px; margin-bottom: 10px; }
.empty-state p { margin: 4px 0; }
.muted.small { font-size: 13px; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + var(--safe-bottom));
  z-index: 30;
}
.nav-btn {
  flex: 1;
  border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 0;
  cursor: pointer;
}
.nav-btn.active { color: var(--blue); }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(76px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #16181d;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Sheet (modal) */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 12, 16, .5);
  z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 1; transition: opacity .2s ease;
}
.sheet-overlay.hidden { display: none; }
.sheet {
  position: relative;
  background: var(--surface);
  width: 100%; max-width: 560px;
  max-height: 92vh;
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  animation: slideUp .22s cubic-bezier(.2,.8,.2,1);
  padding-bottom: calc(20px + var(--safe-bottom));
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 999px; margin: 10px auto 4px; }
.sheet-content { padding: 6px 18px 18px; }

.detail-media { width: 100%; aspect-ratio: 16/11; border-radius: var(--radius-md); overflow: hidden; background: var(--bg); margin-bottom: 14px; }
.detail-media img { width: 100%; height: 100%; object-fit: cover; }
.detail-price { font-size: 24px; font-weight: 800; }
.detail-title { font-size: 15px; margin-top: 4px; color: var(--text); }
.detail-meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.meta-pill { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px; font-size: 12px; color: var(--text-muted); }
.detail-address { margin-top: 12px; font-size: 14px; display: flex; gap: 6px; }
.detail-address svg { color: var(--blue); flex-shrink: 0; margin-top: 2px; }
.detail-desc { margin-top: 12px; font-size: 14px; line-height: 1.5; color: var(--text-muted); white-space: pre-wrap; }
.detail-section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); margin: 18px 0 8px; }

.note-textarea {
  width: 100%;
  min-height: 90px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
.note-textarea:focus { outline: none; border-color: var(--blue); }

.detail-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 10px;
  font-size: 14px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-save { background: var(--text); color: var(--surface); margin-top: 10px; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.close-x {
  position: absolute; top: 14px; right: 14px; z-index: 5;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg); border: none; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

@media (min-width: 600px) {
  .sheet-overlay { align-items: center; }
  .sheet { border-radius: 20px; max-height: 88vh; margin: 20px; }
}
