/* ================================================================
   REALTY PAGE — realty.css
   Depends on global.css design tokens.
   NOTE: A few base rules duplicate those in main.css; they can be
         consolidated in a final cleanup pass.
   ================================================================ */

/* ── MAIN CONTAINER ────────────────────────────────────────────── */
.realty-main {
  position: relative;
  z-index: 1;
  padding: 28px 32px 120px;
  min-height: calc(100vh - 57px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.realty-main .btn-back {
  align-self: flex-start;
}

/* ── VIEW CONTAINERS (buildings / apartments) ────────────────── */
#viewBuildings,
#viewApartments {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
}

#viewApartments .btn-back {
  align-self: center;
  margin-bottom: 20px;
  margin-top: 1rem;
}

#viewDetail {
  width: 100%;
}

.view-heading {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 24px;
  letter-spacing: -0.02em;
  text-align: center;
  width: 100%;
  max-width: 620px;
}

/* ── BUILDINGS GRID ──────────────────────────────────────────── */
.buildings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  width: 100%;
  max-width: 620px;
}

.building-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition:
    transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.22s,
    border-color 0.22s;
}

[data-theme="light"] .building-card {
  background: #e2dee9;
  border-color: var(--border);
  box-shadow: 0 2px 8px rgba(45, 25, 105, 0.09);
}

.building-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 48px rgba(212, 187, 255, 0.2);
  border-color: var(--accent);
}

.building-img {
  height: 120px;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.building-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.6;
}

.building-info {
  padding: 16px 18px;
}

.building-info h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
}

.building-info p {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── APARTMENTS GRID ──────────────────────────────────────────── */
.apartments-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 620px;
}

.apt-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 14px;
  padding: 24px 22px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

[data-theme="light"] .apt-card {
  background: var(--card);
  border-color: var(--border);
  box-shadow: 0 2px 8px rgba(45, 25, 105, 0.06);
}

.apt-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(212, 187, 255, 0.12);
}

.apt-position {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.apt-tenant {
  font-size: 0.75rem;
  color: var(--muted);
}

.apt-rent {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}

/* ── DETAIL HEADER (tenant + rent info) ──────────────────────── */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  width: 100%;
}

.detail-tenant-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent2);
  text-align: center;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.detail-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 3px;
}

.btn-tenant {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.18s;
}

.btn-tenant:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── DETAIL GRID (payments, etc.) ────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
}

/* Panel inside detail grid: fixed height with scroll */
.detail-panel {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
  min-width: 0;
  display: flex;
  flex-direction: column;
  max-height: 420px;
}

[data-theme="light"] .detail-panel {
  background: var(--card);
  border-color: var(--border);
  box-shadow: 0 2px 8px rgba(45, 25, 105, 0.06);
}

.detail-panel .panel-header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

[data-theme="light"] .detail-panel .panel-header {
  background: rgba(109, 40, 217, 0.03);
}

.detail-panel .panel-header h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.detail-panel .data-table-wrap {
  overflow-y: auto;
  flex: 1;
}

/* Scrollbar for detail panel tables */
.detail-panel .data-table-wrap::-webkit-scrollbar {
  width: 4px;
}
.detail-panel .data-table-wrap::-webkit-scrollbar-track {
  background: transparent;
}
.detail-panel .data-table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}


.jd-label {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

/* ── PAYMENT STATUS BADGES ──────────────────────────────────── */
.status-paid {
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
}

.status-partial {
  color: #d0bcff;
  font-size: 0.75rem;
  font-weight: 700;
}

.status-unpaid {
  color: var(--red);
  font-size: 0.75rem;
  font-weight: 700;
}

/* ── PAY BUTTON ─────────────────────────────────────────────── */
.btn-pay {
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  border: 1px solid transparent;
  border-radius: 9999px;
  padding: 3px 11px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.18s;
  box-shadow: 0 0 12px rgba(212, 187, 255, 0.2);
}

.btn-pay:hover {
  background: var(--btn-primary-hover);
}
[data-theme="light"] .btn-pay { color: #fff; }

/* ── DEBT CONTAINER (cross-service debts) ───────────────────── */
.debt-container {
  margin-top: 20px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid rgba(239, 68, 68, 0.25);
  overflow: hidden;
  width: 100%;
}

.debt-container-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid rgba(239, 68, 68, 0.15);
  background: rgba(239, 68, 68, 0.04);
  flex-wrap: wrap;
  gap: 8px;
}

.debt-container-header h3 {
  font-size: 0.88rem;
  font-weight: 700;
  color: #ef4444;
  letter-spacing: 0.01em;
}

.debt-total-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 20px;
  padding: 3px 12px;
  white-space: nowrap;
}

.debt-total-badge.no-debt {
  color: #10b981;
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
}

.debt-items {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: stretch;
}

/* Scrollable debt items container */
.debt-items-scroll {
  max-height: 400px;
  overflow-y: auto;
}

.debt-items-scroll::-webkit-scrollbar {
  width: 4px;
}
.debt-items-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.debt-items-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Debt item breakdown scrollbar */
.debt-item-breakdown::-webkit-scrollbar {
  width: 4px;
}
.debt-item-breakdown::-webkit-scrollbar-track {
  background: transparent;
}
.debt-item-breakdown::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Debt Payment History scrollbar */
#debtPaymentHistoryContainer .data-table-wrap::-webkit-scrollbar {
  width: 4px;
}
#debtPaymentHistoryContainer .data-table-wrap::-webkit-scrollbar-track {
  background: transparent;
}
#debtPaymentHistoryContainer .data-table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Debt Payment History table — keep last column as normal cell */
#debtPaymentHistoryTable td:last-child {
  display: table-cell !important;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
#debtPaymentHistoryTable th:last-child {
  text-align: center;
}

/* ── DEBT ITEM (columns inside debt container) ──────────────── */
.debt-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 18px;
  border-right: 1px solid rgba(239, 68, 68, 0.1);
  min-width: 0;
  align-items: center !important; /* overridden at bottom */
  width: 100%;
}

.debt-item:last-child {
  border-right: none;
}

.debt-item-type {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center !important; /* final alignment set at bottom */
}

.debt-item-amount {
  font-size: 1.4rem;
  font-weight: 800;
  color: #ef4444;
  line-height: 1;
  text-align: center !important; /* final alignment set at bottom */
}

.debt-item-amount.cleared {
  color: #10b981;
  font-size: 1.1rem;
  text-align: center !important;
}

.debt-item-breakdown {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 2px;
  flex: 1;
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
}

/* Debt item action buttons — always visible at bottom */
.debt-item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── DEBT ROW (inside breakdown) ──────────────────────────── */
.debt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
}

.debt-row-info {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  text-align: center !important;
  flex-wrap: nowrap;
  overflow: hidden;
  justify-content: center; /* final alignment */
}

.debt-row-info em {
  font-style: normal;
  color: #f59e0b;
  font-weight: 700;
  font-size: 0.82rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.debt-row-info > *:not(em) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.debt-item-breakdown .debt-row {
  border-bottom: 1px solid rgba(239, 68, 68, 0.08);
  padding-bottom: 5px;
}

.debt-item-breakdown .debt-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

/* ── CLEAR DEBT BUTTON ─────────────────────────────────────── */
.btn-debt-clear {
  background: rgba(239, 68, 68, 0.08);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1;
  font-family: inherit;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-debt-clear:hover {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

/* ── BULK PAY BUTTON ──────────────────────────────────────── */
.btn-bulk-pay {
  background: rgba(212, 187, 255, 0.08);
  color: var(--accent);
  border: 1px solid rgba(212, 187, 255, 0.22);
  border-radius: 9999px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-bulk-pay:hover {
  background: rgba(212, 187, 255, 0.18);
  border-color: rgba(212, 187, 255, 0.45);
  color: var(--accent2);
}

/* ── EMPTY STATE ───────────────────────────────────────────── */
.debt-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 18px;
}

/* ── RE-CENTER DEBT LOG TABLE COLUMNS ───────────────────────── */
.panel--debt-log .data-table td:nth-child(3),
.panel--debt-log .data-table td:nth-child(4),
.panel--debt-log .data-table td:nth-child(5) {
  text-align: center !important;
}
.panel--debt-log .data-table th:nth-child(3),
.panel--debt-log .data-table th:nth-child(4),
.panel--debt-log .data-table th:nth-child(5) {
  text-align: center !important;
}

/* ── FINAL CENTERING OVERRIDES (kept at bottom for priority) ───
   These override the earlier text-align: left defaults to ensure
   all debt-item content is centered.                          ── */
.debt-item {
  align-items: center !important;
}
.debt-item-type,
.debt-item-amount,
.debt-item-amount.cleared,
.debt-row-info {
  text-align: center !important;
}
.debt-row-info {
  justify-content: center;
}

.hidden {
  display: none !important;
}

/* ================================================================
   RESPONSIVE OVERRIDES (realty page only)
   ================================================================ */

/* Tablet (≤ 1024px) */
@media (max-width: 1024px) {
  .realty-main {
    padding: 22px 24px;
  }
  .buildings-grid,
  .apartments-grid {
    max-width: 100%;
  }
  .detail-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
}

/* Small tablet (≤ 900px) */
@media (max-width: 900px) {
  .buildings-grid {
    grid-template-columns: 1fr 1fr;
  }
  .apartments-grid {
    grid-template-columns: 1fr 1fr;
  }
  .detail-grid {
    grid-template-columns: 1fr 1fr;
  }
  .detail-grid .detail-panel:last-child {
    grid-column: 1 / -1;
  }
  .debt-items {
    grid-template-columns: 1fr 1fr;
  }
  .debt-item:nth-child(2) {
    border-right: none;
  }
  .debt-item:nth-child(3) {
    grid-column: 1 / -1;
    border-right: none;
    border-top: 1px solid rgba(239, 68, 68, 0.1);
  }
}

/* Phone (≤ 700px) */
@media (max-width: 700px) {
  .realty-main {
    padding: 16px 14px 90px 14px;
  }
  .buildings-grid {
    grid-template-columns: 1fr;
    max-width: 100%;
    gap: 14px;
  }
  .building-img {
    height: 100px;
  }
  .building-info h3 {
    font-size: 0.9rem;
  }
  .apartments-grid {
    grid-template-columns: 1fr;
    max-width: 100%;
    gap: 12px;
  }
  .apt-card {
    padding: 18px 16px;
  }
  .detail-header {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    text-align: center;
  }
  .detail-header > div {
    text-align: center;
  }
  .detail-header h2 {
    font-size: 1rem;
  }
  .detail-tenant-name {
    max-width: none;
    font-size: 0.85rem;
  }
  .btn-tenant {
    padding: 7px 12px;
    font-size: 0.78rem;
    width: 100%;
  }
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .detail-grid .detail-panel:last-child {
    grid-column: auto;
  }
  .detail-panel {
    max-height: none;
  }
  .detail-panel .data-table-wrap {
    max-height: calc(36px + 4 * 42px);
    overflow-y: auto;
    overflow-x: hidden;
  }
  .detail-panel .data-table {
    table-layout: fixed;
    width: 100%;
  }
  .detail-panel .data-table th,
  .detail-panel .data-table td {
    font-size: 0.68rem;
    padding: 7px 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
  }
  .detail-panel .data-table td:last-child {
    white-space: nowrap;
    text-align: right;
    padding: 7px 6px 7px 2px;
    overflow: visible;
    vertical-align: middle;
    width: 90px;
  }
  .detail-panel .data-table th:last-child {
    width: 90px;
  }
  .detail-panel .data-table td:last-child > * {
    vertical-align: middle;
  }
  /* Compact Pay + delete buttons so both stay fully visible */
  .detail-panel .data-table td:last-child .btn-pay {
    padding: 3px 9px;
    font-size: 0.66rem;
    flex-shrink: 0;
  }
  .detail-panel .data-table td:last-child .btn-del {
    min-width: 24px;
    min-height: 24px;
    padding: 3px 5px;
    flex-shrink: 0;
  }
  .view-heading {
    font-size: 1rem;
    margin-bottom: 18px;
  }
  .debt-container {
    margin-top: 14px;
  }
  .debt-container-header {
    padding: 11px 14px;
    gap: 6px;
  }
  .debt-container-header h3 {
    font-size: 0.82rem;
  }
  .debt-total-badge {
    font-size: 0.72rem;
    padding: 2px 10px;
  }
  .debt-items {
    grid-template-columns: 1fr;
  }
  .debt-item {
    border-right: none;
    border-bottom: 1px solid rgba(239, 68, 68, 0.1);
    padding: 14px 16px;
  }
  .debt-item:last-child {
    border-bottom: none;
  }
  .debt-item:nth-child(2) {
    border-right: none;
  }
  .debt-item:nth-child(3) {
    grid-column: auto;
    border-top: none;
  }
  .debt-item-type {
    font-size: 0.78rem;
  }
  .debt-item-amount {
    font-size: 1.25rem;
  }
  .debt-item-amount.cleared {
    font-size: 1rem;
  }
  .debt-row-info {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    font-size: 0.72rem;
  }
  .debt-row-info em {
    font-size: 0.72rem;
  }
}

/* Small phone (≤ 480px) */
@media (max-width: 480px) {
  .realty-main {
    padding: 14px 12px 90px 12px;
  }
  .building-card {
    border-radius: 12px;
  }
  .building-img {
    height: 90px;
    font-size: 2.5rem;
  }
  .building-info {
    padding: 12px 14px;
  }
  .apt-card {
    padding: 16px 14px;
    border-radius: 12px;
  }
  .debt-item {
    padding: 12px 14px;
  }
  .debt-item-amount {
    font-size: 1.1rem;
  }
  .debt-row-info {
    font-size: 0.68rem;
    gap: 4px;
  }
  .debt-row-info em {
    font-size: 0.68rem;
  }
}

/* Very small phone (≤ 360px) */
@media (max-width: 360px) {
  .buildings-grid,
  .apartments-grid {
    gap: 10px;
  }
}
