:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1e2740;
  --line: #2a3554;
  --text: #e8ecf5;
  --muted: #93a0bd;
  --accent: #4f8cff;
  --accent-2: #37d0a2;
  --danger: #e5534b;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow-x: hidden; }
body {
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app { display: flex; height: 100vh; height: 100dvh; }

/* Bottom tab bar hidden on desktop, shown on phones/tablets via media query */
.mobile-tabs { display: none; }

/* ---------- left sidebar ---------- */
.sidebar {
  width: 380px;
  min-width: 340px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 18px 32px;
  overflow-y: auto;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.brand { font-size: 18px; margin: 0; letter-spacing: .3px; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: 7px; }
.brand-ico { width: 24px; height: 24px; border-radius: 6px; display: inline-block; }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field em { font-style: normal; opacity: .7; }
.field input, .field select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.checks {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px 10px;
  margin: 12px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}
.checks legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.checks label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.checks input { accent-color: var(--accent); width: 15px; height: 15px; }

.actions { display: flex; gap: 8px; margin-top: 14px; }
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
a.btn { text-decoration: none; display: inline-block; }
.btn.big { padding: 12px 18px; font-size: 15px; }
.btn[disabled] { opacity: .5; cursor: default; }
.results-actions { display: flex; gap: 8px; align-items: center; }

.feed-note { font-size: 11.5px; color: var(--muted); margin-top: 14px; }
.feed-note code { color: var(--accent-2); }

/* ---------- right results ---------- */
.results { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.results-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-wrap: wrap;
}
.results-bar h2 { margin: 0; font-size: 17px; }
.muted { color: var(--muted); font-size: 12.5px; }

.portal-links { display: flex; gap: 8px; flex-wrap: wrap; }
.portal-links a {
  color: var(--accent-2); text-decoration: none; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px;
}
.portal-links a:hover { border-color: var(--accent-2); }

.grid {
  flex: 1; overflow-y: auto; padding: 20px 22px;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
  align-content: start;
}

.card {
  display: block;
  color: inherit;
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card img { width: 100%; height: 165px; object-fit: cover; display: block; background: var(--panel-2); }
.card .no-photo { height: 165px; display: flex; align-items: center; justify-content: center; color: var(--muted); background: var(--panel-2); }
.card-body { padding: 11px 13px 13px; }
.card-price { font-size: 17px; font-weight: 700; }
.card-price .dom { font-size: 11px; color: var(--muted); font-weight: 400; float: right; margin-top: 3px; }
.card-stats { font-size: 12.5px; color: var(--text); margin: 3px 0; }
.card-addr { font-size: 12.5px; color: var(--muted); }
.card-tags { margin-top: 7px; display: flex; gap: 5px; flex-wrap: wrap; }
.card-tags span {
  font-size: 10.5px; color: var(--accent-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px;
}

.empty { grid-column: 1 / -1; text-align: center; margin-top: 12vh; font-size: 15px; }
.error-box {
  grid-column: 1 / -1; background: #3a1f22; border: 1px solid var(--danger);
  border-radius: var(--radius); padding: 14px 18px;
}
.loading { grid-column: 1 / -1; text-align: center; margin-top: 10vh; color: var(--muted); }

/* ---------- listing detail page ---------- */
.detail-page { padding: 0 0 40px; }
.detail-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 26px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.detail-source { color: var(--muted); font-size: 13px; }
.detail-main { max-width: 1150px; margin: 24px auto; padding: 0 26px; display: flex; gap: 28px; flex-wrap: wrap; }
.detail-gallery { flex: 1.3; min-width: 340px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start; }
.detail-gallery img { width: 100%; border-radius: 8px; display: block; }
.detail-gallery img:first-child { grid-column: 1 / -1; }
.detail-info { flex: 1; min-width: 320px; }
.detail-info h1 { margin: 0; font-size: 30px; }
.detail-info h2 { margin: 4px 0 8px; font-size: 16px; font-weight: 500; color: var(--muted); }
.detail-stats { font-size: 15px; }
.detail-facts { list-style: none; padding: 0; margin: 14px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 7px 16px; }
.detail-facts b { color: var(--muted); font-weight: 500; display: inline-block; min-width: 110px; }
.detail-remarks { color: var(--text); font-size: 13.5px; line-height: 1.6; }
.detail-agent { color: var(--muted); font-size: 12.5px; }
.detail-page .portal-links { margin-top: 16px; }
.detail-page .portal-links a { font-size: 13.5px; padding: 7px 14px; }

/* ============ responsive: phones, tablets, all sizes ============ */

/* Tablet landscape / small laptop: keep two panels, trim the sidebar */
@media (max-width: 1100px) and (min-width: 821px) {
  .sidebar { width: 320px; min-width: 300px; }
}

/* Phones + tablet portrait: single panel at a time, switched by bottom tabs */
@media (max-width: 820px) {
  .app {
    flex-direction: column;
    height: 100dvh;
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }
  .sidebar, .results { width: 100%; min-width: 0; }
  .sidebar {
    display: block;
    padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  .results { display: none; }

  /* When Listings tab is active, swap which panel shows */
  body.view-results .sidebar { display: none; }
  body.view-results .results { display: flex; }

  /* Bigger, thumb-friendly controls */
  .field input, .field select { padding: 12px; font-size: 16px; } /* 16px stops iOS zoom-on-focus */
  .btn { padding: 12px 16px; }
  .checks { grid-template-columns: 1fr 1fr; gap: 10px 12px; }
  .checks label { padding: 4px 0; }
  .checks input { width: 20px; height: 20px; }
  .actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 10px; }
  .results-bar { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .grid { padding: 14px 16px; grid-template-columns: 1fr; gap: 14px; }

  /* Bottom tab bar */
  .mobile-tabs {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
    border-top: 1px solid var(--line);
    z-index: 50;
  }
  .mobile-tabs button {
    flex: 1;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .mobile-tabs button.active { color: var(--accent); }
  .tab-badge {
    display: inline-block;
    background: var(--accent-2);
    color: #04110c;
    font-size: 11px;
    border-radius: 999px;
    padding: 1px 7px;
    margin-left: 2px;
  }
}

/* Single-column card grid also on the narrowest phones for the listing detail */
@media (max-width: 600px) {
  .detail-main { flex-direction: column; margin: 14px auto; padding: 0 16px; }
  .detail-gallery { grid-template-columns: 1fr; }
  .detail-info h1 { font-size: 26px; }
  .detail-facts { grid-template-columns: 1fr; }
}

/* ---------- touch / tablet polish ---------- */
@media (max-width: 820px) {
  .sidebar { -webkit-overflow-scrolling: touch; }

  /* results header stacks; portal links become one horizontal scroll strip
     (no vertical wrapping that eats screen height) */
  .results-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .portal-links {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    max-width: 100%; padding-bottom: 2px;
    scrollbar-width: none; -ms-overflow-style: none;
  }
  .portal-links::-webkit-scrollbar { display: none; }
  .portal-links a { flex: 0 0 auto; padding: 7px 14px; font-size: 13px; }

  /* bigger, clearly tappable cards with press feedback */
  .card img, .card .no-photo { height: 200px; }
  .card { transition: transform .1s ease, border-color .12s ease; }
  .card:active { transform: scale(0.98); border-color: var(--accent); }
  .card-tags span { font-size: 11.5px; padding: 3px 10px; }

  /* lift the sticky action bar off the scrolling form */
  .actions { box-shadow: 0 -6px 12px -9px rgba(0, 0, 0, 0.6); }

  /* clearer active tab */
  .mobile-tabs button { transition: color .12s ease; }
  .mobile-tabs button.active { box-shadow: inset 0 2px 0 var(--accent); }
}

/* Landscape phones: keep the tab bar reachable, trim vertical chrome */
@media (max-width: 820px) and (max-height: 480px) {
  .card img, .card .no-photo { height: 150px; }
  .results-bar { padding-top: 8px; }
}

/* ---------- review / approval page ---------- */
.review-main { max-width: 760px; margin: 24px auto; padding: 0 20px; }
.rv-title { font-size: 20px; margin: 0 0 16px; }
.rv-list { display: flex; flex-direction: column; gap: 14px; }
.rv-card {
  display: flex; gap: 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; overflow: hidden;
}
.rv-photo { width: 200px; height: 140px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; background: var(--panel-2); }
.rv-photo.no-photo { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.rv-body { flex: 1; min-width: 0; }
.rv-price { font-size: 22px; font-weight: 800; }
.rv-stats { font-size: 13px; margin: 2px 0; }
.rv-addr { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.rv-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rv-tag { font-size: 12.5px; font-weight: 700; }
.rv-tag.up { color: var(--accent-2); }
.rv-tag.down { color: var(--danger); }
.rv-card .btn.primary { padding: 8px 14px; }
.rv-footer { margin-top: 20px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* booking slot picker */
.rv-book { margin-top: 12px; }
.bk-day { margin-bottom: 10px; }
.bk-daylabel { font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.bk-slots { display: flex; flex-wrap: wrap; gap: 6px; }
.bk-slot {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px; font-size: 13px; cursor: pointer;
}
.bk-slot:hover { border-color: var(--accent); }
.bk-slot[disabled] { opacity: .5; }
.bk-done { background: #123227; border: 1px solid var(--accent-2); border-radius: 8px; padding: 12px 14px; font-size: 14px; }

/* ---------- outbox preview ---------- */
.ob-app { display: flex; height: 100vh; height: 100dvh; }
.ob-list { width: 340px; min-width: 300px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.ob-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); }
.ob-head .brand { display: block; margin-bottom: 8px; }
.ob-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  border-bottom: 1px solid var(--line); padding: 12px 16px; cursor: pointer; color: var(--text);
}
.ob-item:hover { background: var(--panel-2); }
.ob-item.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.ob-kind { font-size: 11px; color: var(--accent-2); }
.ob-subj { font-size: 14px; font-weight: 600; margin: 2px 0; }
.ob-to { font-size: 12px; color: var(--muted); }
.ob-view { flex: 1; display: flex; flex-direction: column; }
.ob-meta { padding: 12px 18px; }
#ob-frame { flex: 1; width: 100%; border: none; background: #fff; }

@media (max-width: 820px) {
  .rv-card { flex-direction: column; }
  .rv-photo { width: 100%; height: 190px; }
  .ob-app { flex-direction: column; height: auto; }
  .ob-list { width: 100%; min-width: 0; }
  #ob-frame { height: 70vh; }
}
