:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
}
.logo { font-size: 1.5rem; font-weight: 800; color: var(--text); letter-spacing: -0.5px; }
.logo span { color: var(--primary); }
.search-form { display: flex; flex: 1; gap: 8px; max-width: 520px; }
.search-form input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 999px; font-size: 0.95rem; outline: none;
}
.search-form input:focus { border-color: var(--primary); }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; font-size: 0.9rem; font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f0f1f4; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.layout { display: grid; grid-template-columns: 220px 1fr; gap: 28px; padding: 28px 20px; }
.sidebar { align-self: start; }
.sidebar h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.category-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.cat-btn {
  width: 100%; text-align: left; background: transparent; border: none; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; font-size: 0.95rem; color: var(--text);
}
.cat-btn:hover { background: #e9ebef; }
.cat-btn.active { background: var(--primary); color: #fff; font-weight: 600; }

.content-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.content-head h1 { font-size: 1.4rem; }
.result-count { color: var(--muted); font-size: 0.85rem; }

.advert-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.advert-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: box-shadow 0.15s, transform 0.15s; box-shadow: var(--shadow);
}
.advert-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08); }
.card-photo, .detail-photo { width: 100%; border-radius: 8px; object-fit: cover; background: #eef0f3; }
.card-photo { height: 160px; margin-bottom: 10px; }
.advert-card .price { font-weight: 700; color: var(--primary); font-size: 1.05rem; }
.advert-card .title { font-weight: 600; margin: 4px 0; }
.advert-card .meta { color: var(--muted); font-size: 0.82rem; display: flex; gap: 10px; flex-wrap: wrap; }
.tag { display: inline-block; background: #eef2ff; color: var(--primary-dark); padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }

.loading, .empty { color: var(--muted); padding: 24px 0; grid-column: 1 / -1; }

.site-footer { border-top: 1px solid var(--border); margin-top: 32px; padding: 24px 0; color: var(--muted); text-align: center; font-size: 0.85rem; }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden, .toast.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 20, 30, 0.45); }
.modal-box {
  position: relative; background: var(--surface); border-radius: var(--radius); padding: 28px;
  width: min(560px, 92vw); max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-close { position: absolute; top: 12px; right: 14px; background: none; border: none; font-size: 1.6rem; cursor: pointer; color: var(--muted); line-height: 1; }

.create-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.create-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.create-form input, .create-form select, .create-form textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; color: var(--text); font-weight: 400;
}
.create-form textarea { resize: vertical; }
.form-errors { list-style: none; color: var(--danger); font-size: 0.85rem; }
.form-errors li { margin-bottom: 2px; }

.detail-title { font-size: 1.5rem; margin-bottom: 6px; }
.detail-photo { max-height: 320px; margin-bottom: 12px; }
.detail-price { font-size: 1.3rem; font-weight: 700; color: var(--primary); margin-bottom: 12px; }
.detail-meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.detail-desc { white-space: pre-wrap; margin-bottom: 16px; }
.detail-contact { border-top: 1px solid var(--border); padding-top: 12px; color: var(--muted); font-size: 0.9rem; }
.detail-actions { margin-top: 16px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 20px; border-radius: 999px; z-index: 200; font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .header-inner { flex-wrap: wrap; }
  .search-form { order: 3; max-width: 100%; flex-basis: 100%; }
}
