:root {
  --ink: #0f1b2d;
  --ink-soft: #5b6b80;
  --line: #e6eaf0;
  --bg: #f6f8fb;
  --card: #ffffff;
  --brand: #1f6f5c;
  --brand-soft: #e7f3ef;
  --brand-ink: #14503f;
  --accent: #2f6df6;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 8px 24px rgba(15, 27, 45, .06);
  --shadow-lg: 0 20px 60px rgba(15, 27, 45, .25);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  align-self: center;
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.brand-sub { color: var(--ink-soft); font-size: 13px; }
.agent-badge {
  font-size: 13px;
  color: var(--brand-ink);
  background: var(--brand-soft);
  border: 1px solid #cfe7df;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}

/* ---------- Layout ---------- */
.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.state {
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 80px 20px;
  text-align: center;
  color: var(--ink-soft);
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Agent header ---------- */
.agent-hero {
  background: linear-gradient(180deg, #ffffff, #fbfdfc);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 26px;
}
.agent-hero h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.02em; }
.agent-hero .meta { color: var(--ink-soft); font-size: 14px; }
.agent-hero .count {
  display: inline-block;
  margin-top: 14px;
  font-weight: 700;
  color: var(--brand-ink);
}
.hero-note {
  margin-top: 14px;
  padding: 12px 14px;
  background: #f0f6ff;
  border: 1px solid #d7e6ff;
  border-radius: 10px;
  font-size: 13px;
  color: #2c4a78;
}

/* ---------- Bien card ---------- */
.bien {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}
.bien-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.bien-head h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.bien-head .sub { color: var(--ink-soft); font-size: 13px; margin-top: 3px; }
.bien-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
  padding: 12px;
  background: #fafbfc;
}
.gallery .thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  cursor: zoom-in;
  background: #eef1f5;
  border: none;
  padding: 0;
}
.gallery .thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .25s ease;
}
.gallery .thumb:hover img { transform: scale(1.05); }
.gallery .thumb .idx {
  position: absolute;
  left: 6px; top: 6px;
  background: rgba(15, 27, 45, .65);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
}

/* ad text */
.bien-body { padding: 18px 20px; }
.section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  font-weight: 700;
  margin: 0 0 8px;
}
.ad-text {
  white-space: pre-wrap;
  font-size: 14.5px;
  color: #25313f;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  max-height: 260px;
  overflow: auto;
}
.ad-text.expanded { max-height: none; }
.expand-btn {
  margin-top: 8px;
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  font-size: 13.5px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f4f6f9; }
.btn:active { transform: translateY(1px); }
.btn .ic { width: 15px; height: 15px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(.95); }

/* ---------- Index (no agent) ---------- */
.index-head { margin-bottom: 18px; }
.index-head h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.02em; }
.index-head p { color: var(--ink-soft); margin: 0; }
.search {
  width: 100%;
  margin: 18px 0;
  padding: 12px 16px;
  font: inherit;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}
.agent-list { display: grid; gap: 10px; }
.agent-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.agent-row .who strong { display: block; font-size: 15px; }
.agent-row .who span { color: var(--ink-soft); font-size: 13px; }
.agent-row .pill {
  font-size: 12px;
  color: var(--brand-ink);
  background: var(--brand-soft);
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 700;
}
.row-actions { display: flex; gap: 8px; }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
}
.empty h1 { color: var(--ink); margin-bottom: 8px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 14, 24, .92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
[hidden] { display: none !important; }
.lb-figure { margin: 0; max-width: 92vw; max-height: 88vh; text-align: center; }
.lb-figure img {
  max-width: 92vw;
  max-height: 80vh;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}
.lb-figure figcaption { color: #c7d0db; font-size: 13px; margin-top: 10px; }
.lb-close, .lb-nav {
  position: absolute;
  background: rgba(255, 255, 255, .12);
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.lb-close { top: 18px; right: 20px; width: 44px; height: 44px; font-size: 26px; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 52px; height: 52px; font-size: 34px; }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-close:hover, .lb-nav:hover { background: rgba(255, 255, 255, .25); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Footer ---------- */
.footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  color: var(--ink-soft);
  font-size: 12.5px;
  text-align: center;
}

@media (max-width: 560px) {
  .bien-head { flex-direction: column; }
  .bien-actions { width: 100%; }
  .agent-badge { max-width: 40vw; }
}
