:root {
  --bg: #f7f7f8;
  --fg: #1d1d1f;
  --muted: #6b7280;
  --line: #e5e7eb;
  --card: #fff;
  --primary: #2563eb;
  --primary-fg: #fff;
  --green: #16a34a;
  --yellow: #f59e0b;
  --red: #dc2626;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.05);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
img, video, table { max-width: 100%; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--fg);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3 { margin: 0 0 .5rem; }
p { margin: 0 0 .5rem; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--red); margin-top: .5rem; }
.flash {
  background: #ecfdf5; border: 1px solid #a7f3d0;
  color: #065f46; padding: .75rem 1rem; margin: 1rem;
  border-radius: var(--radius);
}
.flash.flash-error {
  background: #fef2f2; border-color: #fecaca; color: #991b1b;
}
button, .btn {
  appearance: none; border: 1px solid var(--line);
  background: #fff; color: var(--fg);
  padding: .5rem .9rem; border-radius: var(--radius);
  cursor: pointer; font-size: .95rem;
}
button:hover { background: #fafafa; }
button.primary, .primary {
  background: var(--primary); color: var(--primary-fg);
  border-color: var(--primary);
}
button.primary:hover { background: #1d4ed8; }
input, select, textarea {
  font: inherit; padding: .5rem .65rem; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; width: 100%;
}
label {
  display: block; margin: .5rem 0; font-size: .9rem; color: var(--muted);
}
label input, label select, label textarea {
  display: block; margin-top: .25rem; color: var(--fg);
}
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem .75rem; }

/* ===== Topbar ===== */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--fg); }
.topbar nav { margin-left: auto; display: flex; gap: 1rem; align-items: center; }
.topbar nav a, .topbar nav span { color: var(--fg); font-size: .9rem; cursor: pointer; }
.topbar nav .primary {
  background: var(--primary); color: #fff; padding: .35rem .75rem;
  border-radius: 8px;
}
.role-nav span {
  padding: .35rem .75rem; border-radius: 8px;
}
.role-nav span.active { background: var(--primary); color: #fff; }
.user-chip { display: flex; align-items: center; gap: .5rem; position: relative; }
.user-chip .who { font-size: .85rem; color: var(--muted); }

/* ===== Notification bell + dropdown ===== */
.bell-wrap { position: relative; }
.bell-btn {
  border: none; background: transparent;
  padding: .35rem .5rem; font-size: 1.15rem;
  cursor: pointer; border-radius: 8px;
  position: relative;
  line-height: 1;
}
.bell-btn:hover { background: #f3f4f6; }
.bell-btn.ring { animation: bellRing .8s ease-in-out 1; }
@keyframes bellRing {
  0%, 100% { transform: rotate(0); }
  20%      { transform: rotate(-12deg); }
  40%      { transform: rotate(10deg); }
  60%      { transform: rotate(-8deg); }
  80%      { transform: rotate(6deg); }
}
.bell-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--red); color: #fff;
  border-radius: 999px;
  font-size: .65rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  line-height: 1;
}
.notif-panel {
  position: absolute; top: calc(100% + 4px); right: 0;
  width: min(360px, 92vw);
  max-height: 70vh; overflow: hidden;
  background: #fff; border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,.12); border: 1px solid var(--line);
  z-index: 1000;
  display: flex; flex-direction: column;
}
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
}
.notif-header button {
  font-size: .8rem; padding: .25rem .6rem;
  background: transparent; border: 1px solid var(--line);
}
.notif-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.notif-item {
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: block;
}
.notif-item:hover { background: #fafafa; }
.notif-item.unread { background: #eff6ff; }
.notif-item.unread .notif-msg { font-weight: 600; }
.notif-msg { font-size: .9rem; line-height: 1.35; color: var(--fg); }
.notif-time { font-size: .72rem; margin-top: .15rem; }

/* ===== Public landing ===== */
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.hero {
  text-align: center; padding: 2.5rem 1rem 1.5rem;
}
.hero h1 { font-size: 2.2rem; }
.block { margin-top: 2rem; }
.filters {
  display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: .5rem;
  margin: 1rem 0;
}
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem;
}
.card {
  display: block; background: var(--card); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); color: var(--fg);
}
.card:hover { text-decoration: none; transform: translateY(-1px); }
.card img, .card .ph {
  display: block; width: 100%; height: 180px; object-fit: cover; background: #ddd;
}
.card .cardbody { padding: .75rem .9rem; }
.card .rent { font-weight: 600; }
.card.soon { border: 1px dashed var(--line); background: #fffbeb; }

.type-toggle {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .35rem .75rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: .5rem 0;
}
.type-toggle legend { padding: 0 .35rem; font-size: .8rem; color: var(--muted); }
.type-toggle .inline { margin: 0; display: inline-flex; gap: .35rem; }
.type-toggle input[type="radio"] { width: auto; }

.badge-sale {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  margin-left: .35rem;
  vertical-align: middle;
}
.filter-pills {
  display: flex; gap: .35rem; flex-wrap: wrap; margin: .5rem 0;
}
.filter-pills button {
  border-radius: 999px;
  font-size: .85rem;
  padding: .35rem .85rem;
}
.filter-pills button.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

/* For-sale rich detail blocks */
.sale-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0;
}
.sale-detail-grid > div {
  background: #fff;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sale-detail-grid h3 {
  margin: 0 0 .5rem;
  font-size: 1rem;
  color: var(--fg);
  border-bottom: 1px solid var(--line);
  padding-bottom: .35rem;
}
.sale-detail-grid dl {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: .25rem .75rem;
  margin: 0;
  font-size: .9rem;
}
.sale-detail-grid dt { color: var(--muted); }
.sale-detail-grid dd { margin: 0; }
.feature-tags {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-wrap: wrap; gap: .35rem;
}
.feature-tags li {
  background: #f3f4f6;
  border-radius: 999px;
  padding: .25rem .65rem;
  font-size: .8rem;
}

/* Sectioned dialog: <details> styling */
.thread-wrap details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .25rem .75rem;
  margin: .35rem 0;
}
.thread-wrap details[open] {
  background: #fafafa;
}
.thread-wrap summary {
  cursor: pointer; padding: .35rem 0;
  font-size: .9rem; color: var(--fg);
  list-style: revert;
}
.thread-wrap details > *:not(summary) { margin-top: .35rem; }

.detail .gallery { display: grid; grid-template-columns: repeat(2,1fr); gap: .5rem; margin: 1rem 0; }
.detail .gallery img {
  width: 100%; border-radius: var(--radius);
  cursor: zoom-in;
  transition: transform .15s ease;
}
.detail .gallery img:hover { transform: scale(1.01); }

/* ===== Fullscreen image lightbox ===== */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.93);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  touch-action: pan-y;
}
.lightbox.hidden { display: none; }
.lightbox-stage {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.lightbox-stage img {
  max-width: 95vw; max-height: 90vh;
  object-fit: contain;
  display: block;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  background: #000;
}
.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  background: rgba(0,0,0,.5);
  color: #fff;
  border: none;
  width: 48px; height: 48px;
  font-size: 28px; line-height: 48px; padding: 0;
  border-radius: 50%;
  cursor: pointer;
  z-index: 2;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover { background: rgba(0,0,0,.8); }
.lightbox-close { top: 16px; right: 16px; font-size: 32px; }
.lightbox-prev  { left: 16px;  top: 50%; transform: translateY(-50%); }
.lightbox-next  { right: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-counter {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55);
  color: #fff;
  padding: .35rem .9rem;
  border-radius: 999px;
  font-size: .85rem;
  letter-spacing: .03em;
}
@media (max-width: 600px) {
  .lightbox-prev, .lightbox-next, .lightbox-close { width: 44px; height: 44px; font-size: 26px; }
  .lightbox-prev { left: 8px; }
  .lightbox-next { right: 8px; }
  .lightbox-close { top: 8px; right: 8px; }
}
.back { display: inline-block; margin-bottom: .5rem; }

footer { padding: 2rem 1rem; text-align: center; }

/* ===== App shell ===== */
body.app main { max-width: 1280px; }
.pane { display: block; }
.pane.hidden { display: none; }
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr));
  gap: 1rem; margin: 1rem 0;
}
.tile {
  background: #fff; border-radius: var(--radius); padding: 1rem;
  box-shadow: var(--shadow); min-height: 90px;
}
.tile h4 { margin: 0 0 .25rem; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .big { font-size: 1.6rem; font-weight: 700; }
.tile.green { border-left: 4px solid var(--green); }
.tile.yellow { border-left: 4px solid var(--yellow); }
.tile.red { border-left: 4px solid var(--red); }

.row { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0; }
.row.admin-actions {
  background: #fff;
  padding: .75rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: .5rem;
}

table {
  width: 100%; border-collapse: collapse; background: #fff;
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin: 0.5rem 0 1.25rem;
}

/* Horizontal-scroll wrapper for tables that don't fit the viewport.
   Applied at runtime by JS to every <table> inside a .pane. The table
   keeps its native table layout; the wrapper owns the overflow. */
.table-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  margin: 0.5rem 0 1.25rem;
  /* A little hint that there's more to the right */
  background:
    linear-gradient(to right, #fff 30%, rgba(255,255,255,0)),
    linear-gradient(to right, rgba(0,0,0,0.06), rgba(255,255,255,0) 30%) 0 0,
    linear-gradient(to left,  rgba(0,0,0,0.06), rgba(255,255,255,0) 30%) 100% 0,
    linear-gradient(to left, #fff 30%, rgba(255,255,255,0)) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 14px 100%, 14px 100%, 40px 100%;
  background-attachment: local, scroll, scroll, local;
}
.table-scroll-wrap > table {
  margin: 0;
  min-width: 100%;
  width: max-content;  /* let the table grow to fit its widest row */
}
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); font-size: .9rem; vertical-align: middle; }
th { background: #fafafa; font-weight: 600; color: var(--muted); }
table[data-sortable] th { user-select: none; }
table[data-sortable] th:hover { background: #f3f4f6; }
table[data-sortable] th.sort-asc::after  { content: " ▲"; color: var(--primary); font-size: .75em; }
table[data-sortable] th.sort-desc::after { content: " ▼"; color: var(--primary); font-size: .75em; }
tr:last-child td { border-bottom: none; }

.grid-table tr td:first-child {
  width: 6px; padding: 0;
}
.grid-table tr.color-green td:first-child { background: var(--green); }
.grid-table tr.color-yellow td:first-child { background: var(--yellow); }
.grid-table tr.color-red td:first-child { background: var(--red); }
.grid-table tr.color-vacant td:first-child { background: #d1d5db; }
.grid-table tr.vacant td { color: #6b7280; }

.ticket-list { list-style: none; padding: 0; }
.ticket-list li {
  background: #fff; padding: .75rem 1rem; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: .5rem; display: flex; align-items: center; gap: .75rem;
  cursor: pointer;
}
.ticket-list li .pill { font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; background: #eef2ff; color: #3730a3; }
.ticket-list li .pill.high, .ticket-list li .pill.emergency { background: #fef2f2; color: #991b1b; }
.ticket-list li .pill.completed, .ticket-list li .pill.closed { background: #ecfdf5; color: #065f46; }

/* ===== Dialog modals ===== */
dialog {
  border: none; border-radius: var(--radius);
  padding: 1.25rem 1.5rem; width: min(520px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

/* Inbox grid */
.inbox-grid {
  display: grid; grid-template-columns: 280px 1fr; gap: 1rem; min-height: 400px;
}
.contacts { list-style: none; padding: 0; margin: 0; max-height: 500px; overflow: auto; }
.contacts li { padding: .5rem .75rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.contacts li.active { background: #eff6ff; }
.inbox-thread { display: flex; flex-direction: column; gap: .5rem; }
#inbox-messages {
  flex: 1; min-height: 300px; max-height: 500px; overflow: auto;
  background: #fff; border-radius: var(--radius); padding: .75rem;
  box-shadow: var(--shadow);
}
.msg { padding: .5rem .75rem; border-radius: 8px; margin-bottom: .5rem; max-width: 80%; }
.msg.inbound { background: #f3f4f6; }
.msg.outbound { background: #dbeafe; margin-left: auto; }
.msg .meta { font-size: .75rem; color: var(--muted); }
#inbox-compose textarea { min-height: 80px; }
#inbox-compose .compose-status.err { color: var(--red); font-weight: 600; }
#inbox-compose .compose-status.ok  { color: #059669; font-weight: 600; }

/* Thread dialog (maintenance) — wider, taller, photo grid constrained */
#ticket-thread-dialog {
  width: min(1100px, 96vw);
  max-width: none;
  max-height: 92vh;
  padding: 1.25rem 1.5rem;
}
#ticket-thread-dialog .thread-wrap {
  width: 100%;
  max-height: 86vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
#thread-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .5rem;
  margin: .5rem 0 1rem;
  max-width: 100%;
}
#thread-photos img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
  background: #f3f4f6;
}
#thread-messages {
  flex: 1 1 auto;
  margin: 1rem 0;
  overflow-y: auto;
  min-height: 200px;
  max-height: 50vh;
}
.thread-msg { background: #f9fafb; padding: .6rem .85rem; border-radius: 8px; margin-bottom: .5rem; }
.thread-msg .meta { font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.thread-msg.from-tenant { background: #eef2ff; }
.thread-msg.from-pm { background: #f1f5f9; }
.thread-msg.pending {
  opacity: 0.55;
  border-left: 3px solid var(--muted);
}
.thread-msg.pending .meta::after {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-left: .35rem;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
  vertical-align: middle;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}
.thread-msg.failed {
  background: #fef2f2 !important;
  border-left: 3px solid var(--red);
}
.thread-msg.failed .meta { color: var(--red); }
#thread-reply {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: .5rem;
  align-items: end;
  padding-top: .75rem;
  border-top: 1px solid var(--line);
}
#thread-reply textarea {
  min-height: 70px;
  resize: vertical;
  grid-column: 1 / -1;
}
@media (min-width: 720px) {
  #thread-reply textarea { grid-column: 1; }
}

.unit-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: .35rem; margin-bottom: .35rem; }

.hidden { display: none !important; }

/* ===== Apply page ===== */
body.apply main { max-width: 880px; }
.apply-section {
  background: #fff;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 1.25rem 0;
}
.apply-section h2 { margin-bottom: .25rem; font-size: 1.15rem; }
.apply-section h3 { margin: 1rem 0 .25rem; font-size: 1rem; color: #374151; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem .75rem; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: .25rem .75rem; }
.grid4 { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: .25rem .75rem; }
.grid2 .span2, .grid3 .span2, .grid4 .span2 { grid-column: span 2; }
@media (max-width: 600px) {
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
}
.member-row, .ref-row { margin-bottom: .25rem; }
label.inline {
  display: flex; align-items: flex-start; gap: .5rem;
  margin: .5rem 0; font-size: .9rem;
}
label.inline input[type="checkbox"] { width: auto; margin-top: 4px; }
.actions { text-align: center; margin: 2rem 0; }
button.big { padding: .85rem 1.75rem; font-size: 1rem; }

/* Edit-listing dialog — wide modal so contents don't need to scroll */
#edit-listing-dialog {
  width: min(960px, 96vw);
  max-width: none;
  padding: 1.5rem 1.75rem;
}
#edit-listing-dialog .thread-wrap {
  width: 100%;
  max-height: none;
  overflow: visible;
}
#edit-listing-dialog .grid2 { grid-template-columns: 1fr 1fr 1fr 1fr; }
@media (max-width: 720px) {
  #edit-listing-dialog .grid2 { grid-template-columns: 1fr 1fr; }
}

/* Edit-listing dialog — photo grid + delete control */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .5rem;
  margin: .5rem 0 1rem;
}
.photo-tile {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #f3f4f6;
  aspect-ratio: 4 / 3;
}
.photo-tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.photo-x {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none; padding: 0;
  background: rgba(0,0,0,.65); color: #fff;
  font-size: 18px; line-height: 24px; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.photo-x:hover { background: var(--red); }

/* Form field error state — set on the wrapping <label> */
label.field-invalid > input,
label.field-invalid > select,
label.field-invalid > textarea,
.field-invalid input, .field-invalid select, .field-invalid textarea {
  border-color: var(--red);
  background: #fff5f5;
  outline-color: var(--red);
}
label.field-invalid { color: var(--red); }
.field-error-msg {
  display: block;
  margin-top: 4px;
  font-size: .8rem;
  color: var(--red);
}
/* Native HTML5 invalid styling — light red border on touched-then-invalid inputs */
input:user-invalid, select:user-invalid, textarea:user-invalid {
  border-color: var(--red); background: #fff5f5;
}

/* ===== Auth shell (login/signup/reset on /app for anonymous visitors) ===== */
body.app.auth { background: var(--bg); }
body.app.auth .topbar-auth nav a { color: var(--fg); }
.auth-shell {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  padding: 1.75rem;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .08);
}
.auth-tabs {
  display: flex;
  gap: .35rem;
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: .35rem;
}
.auth-tabs button {
  background: transparent;
  border: none;
  padding: .5rem .75rem;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}
.auth-tabs button.active {
  background: var(--primary);
  color: #fff;
}
.auth-tabs button:hover:not(.active) { background: #f3f4f6; color: var(--fg); }
.auth-card label { display: block; margin-bottom: .75rem; }
.auth-card label input { display: block; width: 100%; margin-top: .25rem; }
.auth-card .big {
  width: 100%;
  margin-top: .5rem;
  padding: .85rem 1rem;
  font-size: 1rem;
}
.auth-card .error { min-height: 1.2rem; }
@media (max-width: 480px) {
  .auth-card { padding: 1.25rem; }
  .auth-shell { padding: 1rem .5rem; }
}

/* Listing detail apply CTA — full-size variant (no longer used at
   bottom of page; kept for compatibility). */
.detail .apply-cta {
  background: #fff;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 1.5rem 0;
  text-align: center;
}
.detail .apply-cta h3 { margin-bottom: .35rem; }
.detail .apply-cta p { color: var(--muted); margin-bottom: 1rem; font-size: .9rem; }

/* TOP variant — compact, sits right under the summary line above
   the photo gallery. Single visual line: button on the left, brief
   subtext on the right. Drops to two lines on mobile. */
.detail .apply-cta.apply-cta-top {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  border: 1px solid #fde68a;
  padding: 0.85rem 1.25rem;
  margin: 0.75rem 0 1.25rem;
  text-align: left;
}
.detail .apply-cta.apply-cta-top .muted {
  color: #78350f;
  font-size: 0.88rem;
}
.big-cta {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.big-cta:hover { filter: brightness(0.95); }

@media (max-width: 600px) {
  .detail .apply-cta.apply-cta-top {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    gap: 0.4rem;
  }
  .big-cta { width: 100%; padding: 0.9rem 1rem; }
}


/* ============================================================
   MOBILE LAYER — applies on phones and small tablets.
   Everything above is desktop-first; this overrides as needed.
   ============================================================ */
@media (max-width: 720px) {
  main {
    padding: 1rem .75rem 3rem;
  }

  /* ----- Topbar: stack the brand+nav, scroll the role tabs horizontally ----- */
  .topbar {
    flex-wrap: wrap;
    padding: .6rem .75rem;
    gap: .5rem;
  }
  .topbar nav {
    margin-left: 0;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .topbar nav a, .topbar nav span {
    white-space: nowrap;
    font-size: .85rem;
  }
  .role-nav span { padding: .4rem .65rem; }
  .user-chip {
    width: 100%;
    justify-content: space-between;
    font-size: .8rem;
  }
  .user-chip span { font-size: .8rem; }

  /* ----- Hero ----- */
  .hero h1 { font-size: 1.6rem; }
  .hero p { font-size: .95rem; }

  /* ----- Listing grid + filters ----- */
  .filters {
    grid-template-columns: 1fr 1fr;
  }
  .filters button { grid-column: 1 / -1; }
  .grid {
    grid-template-columns: 1fr;
  }
  .card img, .card .ph { height: 200px; }

  /* ----- Tiles: full width stack on phones ----- */
  .tiles {
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
  }
  .tile { padding: .75rem; min-height: 0; }
  .tile .big { font-size: 1.3rem; }

  /* ----- Action toolbars: wrap and full-width buttons ----- */
  .row { gap: .4rem; }
  .row.admin-actions { padding: .5rem; }
  .row.admin-actions button {
    flex: 1 1 calc(50% - .4rem);
    font-size: .85rem;
    padding: .55rem .6rem;
  }

  /* ----- Tables on mobile: smaller cell padding; horizontal scroll
            handled by the .table-scroll-wrap that wraps each table. ----- */
  th, td { font-size: .85rem; padding: .45rem .55rem; white-space: nowrap; }

  /* ----- Listing detail ----- */
  .detail .gallery {
    grid-template-columns: 1fr;
  }
  .detail h1 { font-size: 1.4rem; }

  /* ----- Apply form: 1-col, no fancy grids ----- */
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  #edit-listing-dialog .grid2 { grid-template-columns: 1fr 1fr; }
  .apply-section { padding: 1rem; }
  .apply-section h2 { font-size: 1.05rem; }

  /* ----- Dialogs: near-full-screen on phones ----- */
  dialog {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh;
    padding: 1rem !important;
    border-radius: 12px;
    margin: 1vh auto;
  }
  #ticket-thread-dialog,
  #edit-listing-dialog {
    width: 96vw !important;
  }
  #ticket-thread-dialog .thread-wrap { max-height: 86vh; }
  #thread-photos { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  #thread-messages { max-height: 35vh; }

  /* ----- Inbox: stack contacts above thread on phones ----- */
  .inbox-grid {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .contacts { max-height: 220px; }
  #inbox-messages { min-height: 200px; max-height: 40vh; }

  /* ----- Buttons: meatier tap targets ----- */
  button, .btn {
    padding: .65rem 1rem;
    font-size: .9rem;
  }

  /* ----- Photo manager grid in edit-listing dialog ----- */
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }

  /* ----- Notification panel: anchor to viewport on mobile so it can't go
            off-screen left when the bell sits at the start of a wrapped row.
            JS sets a precise top via positionNotifPanel(); these are the
            fallback values if JS hasn't run yet. ----- */
  .notif-panel {
    position: fixed;
    top: 4.5rem;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
  }
}

/* Even smaller — phones in portrait under 420px */
@media (max-width: 420px) {
  .tiles { grid-template-columns: 1fr; }
  .row.admin-actions button {
    flex: 1 1 100%;
  }
  .topbar .brand { font-size: 1rem; }
}

/* ===== Builder View link in admin nav (Slice 0) ===== */
.builder-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  margin: 0 0.5rem;
  background: linear-gradient(180deg, #fefce8, #fde68a);
  color: #78350f;
  border: 1px solid #d97706;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: filter 0.12s ease;
}
.builder-link:hover {
  filter: brightness(0.96);
}
.builder-link:active { transform: translateY(1px); }

/* =========== RENT ROLL section =========== */
.rent-roll-filters { gap: .85rem; align-items: flex-end; flex-wrap: wrap; }
.rent-roll-filters label.inline { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; }

#rent-roll-table.compact { font-size: .88rem; }
#rent-roll-table.compact th, #rent-roll-table.compact td { padding: .4rem .55rem; }
#rent-roll-table .num { text-align: right; font-variant-numeric: tabular-nums; }
#rent-roll-table .rr-addr { font-weight: 600; max-width: 250px; }
#rent-roll-table tr[data-rid] { cursor: pointer; }
#rent-roll-table tr[data-rid]:hover { background: #fef9e7; }
#rent-roll-table .rr-balance { font-weight: 600; }
#rent-roll-table .small { font-size: .75rem; }
#rent-roll-table .rr-fee-num { color: #b45309; font-weight: 600; }

#rent-roll-table .rr-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: #94a3b8;
}
#rent-roll-table .rr-paid    .rr-dot { background: #10b981; }   /* green */
#rent-roll-table .rr-due     .rr-dot { background: #e2e8f0; }   /* not yet due */
#rent-roll-table .rr-grace   .rr-dot { background: #facc15; }   /* in grace */
#rent-roll-table .rr-tier1   .rr-dot { background: #f97316; }   /* $50 assessed */
#rent-roll-table .rr-tier2   .rr-dot { background: #dc2626; }   /* $150 assessed */

#rent-roll-table .rr-paid  .rr-balance { color: #059669; }
#rent-roll-table .rr-tier1 .rr-balance,
#rent-roll-table .rr-tier2 .rr-balance { color: #b91c1c; }

.tiles-tight .tile { padding: .85rem 1rem; }
.tiles-tight .tile .big { font-size: 1.4rem; }

/* Lease-expiration pills */
.pill-red, .pill-orange, .pill-yellow {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: .75rem; font-weight: 600; margin-left: .35rem;
  vertical-align: 1px;
}
.pill-red    { background: #fee2e2; color: #991b1b; }
.pill-orange { background: #ffedd5; color: #9a3412; }
.pill-yellow { background: #fef9c3; color: #854d0e; }

/* Rent-roll detail dialog — wider than other dialogs so the payment
   history, late fees, and reminders tables all fit side-by-side. */
#rent-roll-dialog {
  width: min(1820px, 95vw);
  max-width: 95vw;
  padding: 1.5rem 2rem;
}
#rent-roll-dialog .thread-wrap {
  max-height: 90vh;
  overflow-y: auto;
}

.rr-detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2rem;
  margin-top: .5rem;
}
/* On really wide screens (>= 1400px), push the detail panel to 3 columns
   so payment summary, tenant info, and lease info each get a column. */
@media (min-width: 1400px) {
  .rr-detail-grid { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 720px) {
  #rent-roll-dialog { width: 96vw; padding: 1rem; }
  .rr-detail-grid { grid-template-columns: 1fr; gap: 1rem; }
}
#rent-roll-dialog table.kv { width: 100%; border-collapse: collapse; }
#rent-roll-dialog table.kv th {
  text-align: left; font-weight: 500; color: #6b7280;
  padding: .25rem .5rem .25rem 0; vertical-align: top;
  width: 40%; font-size: .88rem;
}
#rent-roll-dialog table.kv td {
  padding: .25rem 0; font-size: .92rem; font-variant-numeric: tabular-nums;
}
#rent-roll-dialog table.kv.kv-full th,
#rent-roll-dialog table.kv.kv-full td { width: auto; padding: .35rem .55rem; }
#rent-roll-dialog table.kv.kv-full { border: 1px solid #e5e7eb; border-radius: 6px; }
#rent-roll-dialog table.kv.kv-full thead th {
  background: #f3f4f6; color: #374151; border-bottom: 1px solid #e5e7eb;
}
#rent-roll-dialog table.kv.kv-full tbody tr:not(:last-child) td {
  border-bottom: 1px solid #f3f4f6;
}
#rent-roll-dialog table.kv.kv-full .num { text-align: right; }

/* =========== ADMIN TAB BAR =========== */
.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 1.25rem 0 1rem;
  border-bottom: 2px solid #e5e7eb;
  overflow-x: auto;
  scrollbar-width: thin;
}
.admin-tab {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.65rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  margin-bottom: -2px;          /* overlap parent's border-bottom */
}
.admin-tab:hover {
  color: #1f2937;
  background: #f9fafb;
}
.admin-tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  background: #fff;
}
.admin-tab:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: -2px;
}

.admin-tab-panel { margin-top: 0.5rem; }

/* Tab header — title + helper subtext on one row, replaces the
   inline span in the old per-section h3. */
.tab-header {
  display: flex; align-items: baseline; gap: 0.75rem;
  flex-wrap: wrap; margin: 0.25rem 0 0.85rem;
}
.tab-header h3 { margin: 0; }
.tab-header .muted { font-size: 0.88rem; }
/* Poll-inbox button lives at the right edge of the Unified Inbox header */
.tab-header .inbox-poll-btn {
  margin-left: auto;
  padding: .3rem .7rem;
  font-size: .85rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.tab-header .inbox-poll-btn:hover:not(:disabled) {
  background: #f3f4f6;
}
.tab-header .inbox-poll-btn:disabled {
  opacity: .6; cursor: wait;
}

/* Mobile: tabs scroll horizontally instead of wrapping */
@media (max-width: 720px) {
  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-tab { padding: 0.55rem 0.85rem; font-size: 0.88rem; }
}

/* ============================================================
   Tenant pay-intent dialog (ACH authorization)
   ------------------------------------------------------------
   Wider than the default dialog because we need to render an
   itemized breakdown + the full NACHA mandate text. The mandate
   block stays scrollable on small screens so the Authorize button
   is always reachable without scrolling the page.
   ============================================================ */
.pay-intent-dialog {
  width: min(640px, 94vw);
  padding: 0;
  overflow: hidden;
}
.pay-intent-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.pay-intent-header h3 { margin: 0; font-size: 1.05rem; }
.pay-intent-close {
  background: none; border: 0; font-size: 1.4rem; cursor: pointer;
  color: #6b7280; padding: 0 .25rem;
}
.pay-intent-close:hover { color: #111827; }

.pay-intent-loading,
.pay-intent-error,
.pay-intent-body {
  padding: 1rem 1.25rem;
  max-height: 75vh;
  overflow-y: auto;
}

/* Two-column header: balance on the left, the (highlighted) amount-to-pay
   card on the right. Wraps to stacked on narrow viewports. */
.pay-intent-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}
.pay-intent-amount {
  flex: 1 1 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: .25rem 0;
}
.pay-intent-total {
  font-size: 2.25rem; font-weight: 700; color: #111827;
  margin-top: .15rem;
}

/* The partial-payment input — deliberately the loudest element in the
   dialog: tinted panel, accent border, oversized right-aligned figure. */
.pay-intent-payamt {
  flex: 0 0 auto;
  min-width: 230px;
  text-align: right;
  background: #eff6ff;
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: .7rem .9rem .8rem;
  box-shadow: 0 1px 4px rgba(37, 99, 235, .15);
}
.pay-intent-payamt-label {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  color: #1e3a8a;
  letter-spacing: .01em;
}
.pay-intent-payamt-hint {
  font-size: .78rem;
  color: #3b5bdb;
  margin-top: .1rem;
}
.pay-intent-input-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .15rem;
  margin-top: .5rem;
}
.pay-intent-currency {
  font-size: 1.7rem;
  font-weight: 700;
  color: #1e3a8a;
  line-height: 1;
}
.pay-intent-payamt input#pay-intent-amount {
  width: 150px;
  font-size: 1.7rem;
  font-weight: 700;
  text-align: right;
  color: #111827;
  padding: .15rem .4rem;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: #fff;
}
.pay-intent-payamt input#pay-intent-amount:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
#pay-intent-amount-err {
  color: #b91c1c;
  margin-top: .3rem;
  min-height: 1em;
}

.pay-intent-meta {
  font-size: .9rem;
  display: flex; flex-direction: column; gap: .2rem;
  margin-bottom: 1rem;
}

.pay-intent-breakdown {
  width: 100%; border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: .9rem;
}
.pay-intent-breakdown th,
.pay-intent-breakdown td {
  padding: .45rem .5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.pay-intent-breakdown thead th {
  text-align: left; background: #f8fafc;
  font-weight: 600; font-size: .8rem;
  color: #6b7280; text-transform: uppercase;
}
.pay-intent-breakdown .num { text-align: right; white-space: nowrap; }
.pay-intent-breakdown tfoot th {
  font-weight: 700;
  padding-top: .65rem;
}

.pay-intent-notice {
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: .55rem .75rem;
  margin-bottom: 1rem;
  font-size: .82rem;
  line-height: 1.45;
}

.pay-intent-mandate {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .75rem .85rem;
  margin-bottom: 1rem;
}
.pay-intent-mandate-label {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: .5rem;
  margin-bottom: .4rem;
}
.pay-intent-mandate pre {
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .78rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
  max-height: 14rem; overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .55rem .65rem;
  color: #111827;
}

.pay-intent-ack {
  display: flex; gap: .5rem;
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  border-radius: 6px;
  padding: .65rem .8rem;
  margin-bottom: 1rem;
  cursor: pointer;
  font-size: .9rem;
}
.pay-intent-ack input[type="checkbox"] {
  margin-top: .15rem;
  width: 1.1rem; height: 1.1rem;
  cursor: pointer;
}

.pay-intent-actions {
  display: flex; gap: .5rem; justify-content: flex-end;
}
.pay-intent-actions button {
  padding: .5rem 1rem;
  font-size: .9rem; font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white; cursor: pointer;
}
.pay-intent-actions button.primary {
  background: #2563eb; color: white; border-color: #2563eb;
}
.pay-intent-actions button.primary:disabled {
  background: #cbd5e1; border-color: #cbd5e1; cursor: not-allowed;
}
.pay-intent-actions button:not(.primary):hover {
  background: #f8fafc;
}

/* ============================================================
   Tenant dashboard — THIS PERIOD tile lifecycle states
   ------------------------------------------------------------
   Driven by payment_status.state from /api/tenant/dashboard.
   ============================================================ */
.tile.tile-state-unpaid       { border-left: 4px solid #dc2626; }
.tile.tile-state-initiated    { border-left: 4px solid #f59e0b; }
.tile.tile-state-processing   { border-left: 4px solid #2563eb; background: #eff6ff; }
.tile.tile-state-provisionally_cleared {
  border-left: 4px solid #84cc16;
  background: #f7fee7;
}
.tile.tile-state-paid         { border-left: 4px solid #16a34a; background: #f0fdf4; }
.tile.tile-state-failed,
.tile.tile-state-returned     { border-left: 4px solid #dc2626; background: #fef2f2; }

/* ============================================================
   Tenant account ledger
   ------------------------------------------------------------
   Chronological line ledger of charges + payments + running
   balance. Newest first.
   ============================================================ */
.tenant-ledger-totals {
  display: flex; gap: .5rem; align-items: baseline;
  margin: 0 0 .5rem;
}
.tenant-ledger-totals strong {
  font-size: 1.15rem;
}
.tenant-ledger {
  width: 100%; border-collapse: collapse;
  margin-bottom: 1.5rem;
}
.tenant-ledger th,
.tenant-ledger td {
  padding: .45rem .55rem;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
}
.tenant-ledger thead th {
  text-align: left; background: #f8fafc;
  font-weight: 600; font-size: .8rem;
  color: #6b7280; text-transform: uppercase;
}
.tenant-ledger .num { text-align: right; white-space: nowrap; }

/* Color-band the left edge to make charges vs credits scannable */
.tenant-ledger tr.ledger-charge td:first-child { border-left: 3px solid #f59e0b; }
.tenant-ledger tr.ledger-credit td:first-child { border-left: 3px solid #16a34a; }
.tenant-ledger tr.ledger-info   td:first-child { border-left: 3px solid #94a3b8; background: #f8fafc; }
