/* ============================================================
   Flats Manager — Offers Table
   fm-offers-table.css
   ============================================================ */

:root {
  --fmt-bg:           #ffffff;
  --fmt-bg-head:      #0f172a;
  --fmt-bg-row:       #ffffff;
  --fmt-bg-row-alt:   #f8fafc;
  --fmt-bg-row-hover: #f1f5f9;
  --fmt-border:       #e2e8f0;
  --fmt-text:         #1e293b;
  --fmt-text-muted:   #64748b;
  --fmt-text-head:    #f8fafc;
  --fmt-accent:       #0ea5e9;
  --fmt-accent-dark:  #0284c7;
  --fmt-radius:       6px;
  /* --fmt-font:         'DM Sans', system-ui, sans-serif; */
  /* --fmt-font-mono:    'DM Mono', 'Fira Mono', monospace; */
  --fmt-shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --fmt-shadow-pop:   0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.10);

  /* Status colours */
  --fmt-status-available:   #16a34a;
  --fmt-status-reservation: #d97706;
  --fmt-status-sold:        #dc2626;
  --fmt-status-soon:        #2563eb;
  --fmt-status-next_stage:  #6b7280;
}

/* ── Wrapper ──────────────────────────────────────────────── */

.fm-offers-wrap {
  /* font-family: var(--fmt-font); */
  font-size: 14px;
  color: var(--fmt-text);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--fmt-radius);
  box-shadow: var(--fmt-shadow);
  border: 1px solid var(--fmt-border);
  background: var(--fmt-bg);
}

.fm-offers-empty {
  padding: 2rem;
  text-align: center;
  color: var(--fmt-text-muted);
}

/* ── Table grid ───────────────────────────────────────────── */

.fm-offers-table {
  display: grid;
  min-width: max-content;
  width: 100%;
}

/* ── Rows ─────────────────────────────────────────────────── */

.fm-row {
  display: flex;
}
.fm-row .fm-cell {
  flex: 1;
  text-align: center;
}

.fm-row--head .fm-cell {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--fmt-bg-head);
  color: var(--fmt-text-head);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 10px 5px;
  border-bottom: 2px solid var(--fmt-accent);
  white-space: nowrap;
  user-select: none;
}

.fm-row--data .fm-cell {
  padding: 10px 5px;
  border-bottom: 1px solid var(--fmt-border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fmt-bg-row);
  transition: background .12s;
}

/* Alternating rows via JS class */
.fm-row--data.fm-row-alt .fm-cell {
  background: var(--fmt-bg-row-alt);
}

/* Hover: highlight all cells in row via CSS sibling trick is unreliable
   — we use JS to add .fm-row-hover */
.fm-row--data.fm-row-hover .fm-cell {
  background: var(--fmt-bg-row-hover);
}

/* ── Sortable header ──────────────────────────────────────── */

.fm-cell--head.fm-sortable {
  cursor: pointer;
}

.fm-cell--head.fm-sortable:hover {
  background: #1e293b;
}

.fm-cell--head.fm-sort-active {
  color: var(--fmt-accent);
}

.fm-sort-icon {
  display: inline-block;
  margin-left: 5px;
  opacity: .45;
  font-size: 10px;
}

.fm-sort-icon::after { content: '↕'; }
[data-sort-dir="asc"]  .fm-sort-icon::after { content: '↑'; opacity: 1; }
[data-sort-dir="desc"] .fm-sort-icon::after { content: '↓'; opacity: 1; }

.fm-cell--head.fm-sort-active .fm-sort-icon { opacity: 1; }

/* ── Values ───────────────────────────────────────────────── */

.fm-val {
  line-height: 1.4;
}

.fm-num {
  /* font-family: var(--fmt-font-mono); */
  font-size: 13px;
}

/* ── Status badges ────────────────────────────────────────── */

.fm-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}

.fm-badge--available   { background: #dcfce7; color: var(--fmt-status-available);   }
.fm-badge--reservation { background: #fef3c7; color: var(--fmt-status-reservation); }
.fm-badge--sold        { background: #fee2e2; color: var(--fmt-status-sold);        }
.fm-badge--soon        { background: #dbeafe; color: var(--fmt-status-soon);        }
.fm-badge--next_stage  { background: #f3f4f6; color: var(--fmt-status-next_stage);  }

/* ── Price cell ───────────────────────────────────────────── */

.fm-price-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

.fm-price {
  font-weight: 600;
  color: var(--fmt-text);
}

.fm-price-m2 {
  /* font-family: var(--fmt-font-mono); */
  font-size: 11px;
  color: var(--fmt-text-muted);
}

/* ── Price history trigger ────────────────────────────────── */

.fm-ph-trigger {
  cursor: pointer;
  font-size: 14px;
  transition: ease 0.4s all;
}

.fm-ph-trigger:hover svg {
  color: var(--fmt-accent);
  transform: scale(1.2);
}
.fm-ph-trigger svg {
  width: 16px;
  height: 16px;
  display: inline-block;
  margin-left: 3px;
  transition: ease 0.4s all;
}
/* ── Buttons ──────────────────────────────────────────────── */

.fm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 13px;
  border-radius: var(--fmt-radius);
  /* font-family: var(--fmt-font); */
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background .14s, color .14s, border-color .14s, transform .1s;
  background: var(--fmt-accent);
  color: #fff;
  border-color: var(--fmt-accent);
}

.fm-btn:active { transform: scale(.97); }

.fm-btn:hover {
  background: var(--fmt-accent-dark);
  border-color: var(--fmt-accent-dark);
  color: #fff;
}

/* ── Price history popup ──────────────────────────────────── */

.fm-ph-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 9998;
  backdrop-filter: blur(2px);
}

.fm-ph-overlay[hidden],
.fm-ph-popup[hidden] {
  display: none;
}

.fm-ph-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  background: var(--fmt-bg);
  border-radius: 10px;
  box-shadow: var(--fmt-shadow-pop);
  width: min(560px, 94vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fmPopIn .18s cubic-bezier(.34,1.56,.64,1);
}

@keyframes fmPopIn {
  from { opacity: 0; transform: translate(-50%, -48%) scale(.95); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.fm-ph-popup__inner {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.fm-ph-popup__title {
  margin: 0;
  padding: 18px 22px 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--fmt-text);
  border-bottom: 1px solid var(--fmt-border);
  /* font-family: var(--fmt-font); */
}

.fm-ph-popup__close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--fmt-text-muted);
  line-height: 1;
  padding: 0;
  border-radius: 4px;
  width: 25px;
  height: 25px;
  display: flex;
  justify-content: center;
  transition: background .12s, color .12s;
}

.fm-ph-popup__close:hover {
  background: #f1f5f9;
  color: var(--fmt-text);
}

.fm-ph-popup__body {
  padding: 16px 22px;
  overflow-y: auto;
  /* font-family: var(--fmt-font); */
}

/* History table inside popup */
.fm-ph-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.fm-ph-table th {
  text-align: left;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--fmt-text-muted);
  border-bottom: 1px solid var(--fmt-border);
}

.fm-ph-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--fmt-border);
  vertical-align: middle;
}

.fm-ph-table tr:last-child td { border-bottom: none; }

.fm-ph-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  /* font-family: var(--fmt-font-mono); */
  font-size: 12px;
}

.fm-ph-change .fm-ph-old {
  color: var(--fmt-text-muted);
  text-decoration: line-through;
}

.fm-ph-change .fm-ph-arrow { color: var(--fmt-text-muted); }

.fm-ph-change .fm-ph-new {
  font-weight: 600;
  color: var(--fmt-text);
}

.fm-ph-empty {
  text-align: center;
  padding: 24px;
  color: var(--fmt-text-muted);
  font-size: 13px;
}

/* ── Column sizing hints ──────────────────────────────────── */

.fm-col-card,
.fm-col-floorplan,
.fm-col-ask       { max-width: 80px; }
.fm-col-building,
.fm-col-number,
.fm-col-name       { max-width: 80px; }
.fm-col-rooms,
.fm-col-floor,
.fm-col-floors       { max-width: 80px; }
.fm-col-area_garden,
.fm-col-area_plot       { max-width: 90px; }
.fm-col-area       { max-width: 120px; }

/* ── Responsive: card layout on mobile ───────────────────── */

@media (max-width: 991px) {
    .fm-row--head {
        display: none;
    }
    .fm-offers-wrap {
        box-shadow: unset;
        border: unset;
    }
    .fm-offers-table {
        padding: 10px;
        row-gap: 20px;
    }
    .fm-row--data {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 10px;
        border: 1px solid #e3e8ef;
        border-radius: 5px;
        padding: 0 10px;
    }
    .fm-row--data .fm-cell {
        max-width: 100%;
        background: transparent!important;
        justify-content: space-between;
        border-bottom: 0;
    }
    .fm-row--data .fm-cell::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--fmt-text-muted);
        margin-right: 12px;
        white-space: nowrap;
    }
    .fm-row--data .fm-col-name,
    .fm-row--data .fm-col-status {
        order: -1;
        font-weight: 600;
    }
}
@media (max-width: 400px) {
    .fm-row--data {
        grid-template-columns: 100%;
    }
}