/* ══════════════════════════════════════════════════════
   Estima — Materials Module
   Self-contained styles. Uses the same CSS variables
   as index.html so colours always stay in sync.
   ══════════════════════════════════════════════════════ */

/* ── Floating side panel ─────────────────────────────── */
#estima-float {
  position: fixed;
  top: 90px;
  right: 12px;
  transform: none;
  z-index: 999;
  display: flex;
  align-items: stretch;
  gap: 0;
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1),
              opacity  0.28s ease;
}

/* Collapsed state — panel slides off-screen to the right */
#estima-float.ef-collapsed #ef-panel {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}
#estima-float.ef-collapsed #ef-toggle {
  border-radius: 8px 0 0 8px;
}

/* Toggle tab on the left edge of the panel */
#ef-toggle {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  cursor: pointer;
  background: var(--s2, #18181B);
  border: 1px solid var(--b1, #2A2A30);
  border-right: none;
  border-radius: 8px 0 0 8px;
  padding: 10px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--amber, #F59E0B);
  font-family: 'Syne', sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  user-select: none;
  transition: background 0.18s;
  box-shadow: -3px 0 16px rgba(0,0,0,0.5);
}
#ef-toggle:hover { background: var(--s3, #222226); }
#ef-toggle svg { flex-shrink: 0; }

/* Main panel */
#ef-panel {
  width: 180px;
  background: var(--s1, #111113);
  border: 1px solid var(--b1, #2A2A30);
  border-right: none;
  border-radius: 12px 0 0 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1),
              opacity  0.28s ease;
  box-shadow: -4px 0 24px rgba(0,0,0,0.55);
  max-height: 80vh;
}

.ef-top-bar {
  height: 2px;
  background: linear-gradient(90deg, var(--steel-d,#0284C7), var(--amber,#F59E0B));
  flex-shrink: 0;
}

.ef-header {
  padding: 11px 13px 8px;
  border-bottom: 1px solid var(--b1, #2A2A30);
  flex-shrink: 0;
}
.ef-header-title {
  font-family: 'Syne', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--white, #F4F4F5);
}
.ef-header-sub {
  font-size: 0.6rem;
  color: var(--muted, #71717A);
  margin-top: 2px;
}

.ef-body {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--b2,#3A3A42) transparent;
}
.ef-body::-webkit-scrollbar { width: 4px; }
.ef-body::-webkit-scrollbar-track { background: transparent; }
.ef-body::-webkit-scrollbar-thumb { background: var(--b2,#3A3A42); border-radius: 4px; }

/* ── Material rate rows inside float panel ─────────────── */
.ef-section-label {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted, #71717A);
  padding: 9px 13px 4px;
  border-bottom: 1px solid rgba(42,42,48,0.5);
}

.ef-mat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 13px;
  border-bottom: 1px solid rgba(42,42,48,0.35);
  gap: 6px;
}
.ef-mat-row:last-child { border-bottom: none; }
.ef-mat-name {
  font-size: 0.72rem;
  color: var(--concrete, #A1A1AA);
  flex: 1;
  line-height: 1.3;
}
.ef-mat-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex-shrink: 0;
}
.ef-mat-price {
  font-size: 0.73rem;
  font-weight: 500;
  color: var(--white, #F4F4F5);
  white-space: nowrap;
}
.ef-trend {
  font-size: 0.62rem;
  font-weight: 600;
}
.ef-trend.up    { color: var(--red, #EF4444); }
.ef-trend.down  { color: var(--green, #22C55E); }
.ef-trend.stable{ color: var(--muted, #71717A); }

/* ── News rows inside float panel ──────────────────────── */
.ef-news-row {
  padding: 8px 13px;
  border-bottom: 1px solid rgba(42,42,48,0.35);
}
.ef-news-row:last-child { border-bottom: none; }
.ef-news-title {
  font-size: 0.71rem;
  color: var(--concrete, #A1A1AA);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ef-news-meta {
  font-size: 0.6rem;
  color: var(--muted, #71717A);
  margin-top: 3px;
}

/* Full resources link */
.ef-footer {
  padding: 9px 13px;
  border-top: 1px solid var(--b1, #2A2A30);
  flex-shrink: 0;
}
.ef-resources-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--amber, #F59E0B);
  text-decoration: none;
  padding: 6px;
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: 6px;
  background: rgba(245,158,11,0.05);
  transition: background 0.18s, border-color 0.18s;
  cursor: pointer;
}
.ef-resources-link:hover {
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.35);
}

/* ── Market snapshot card (below PDF button) ─────────── */
#estima-market-snapshot {
  margin-top: 12px;
  background: linear-gradient(135deg,
    rgba(245,158,11,0.06),
    rgba(245,158,11,0.02));
  border: 1px solid rgba(245,158,11,0.18);
  border-radius: 12px;
  overflow: hidden;
  display: none; /* shown by JS after estimate */
  animation: fadeUp 0.3s ease;
}
@keyframes fadeUp {
  from { opacity:0; transform:translateY(6px); }
  to   { opacity:1; transform:translateY(0); }
}

.ms-topbar {
  height: 2px;
  background: linear-gradient(90deg, var(--amber-d,#D97706), var(--amber,#F59E0B));
}

.ms-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  border-bottom: 1px solid rgba(245,158,11,0.1);
}
.ms-title {
  font-size: 0.63rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--amber, #F59E0B);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ms-updated {
  font-size: 0.58rem;
  color: var(--muted, #71717A);
}

.ms-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 4px 0;
}
.ms-item {
  padding: 7px 14px;
  border-bottom: 1px solid rgba(42,42,48,0.4);
  border-right: 1px solid rgba(42,42,48,0.4);
}
.ms-item:nth-child(even) { border-right: none; }
.ms-item:nth-last-child(-n+2) { border-bottom: none; }
.ms-item-name {
  font-size: 0.65rem;
  color: var(--muted, #71717A);
  margin-bottom: 2px;
}
.ms-item-price {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--white, #F4F4F5);
  display: flex;
  align-items: center;
  gap: 4px;
}
.ms-trend {
  font-size: 0.68rem;
  font-weight: 700;
}
.ms-trend.up     { color: var(--red, #EF4444); }
.ms-trend.down   { color: var(--green, #22C55E); }
.ms-trend.stable { color: var(--muted, #71717A); }

.ms-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid rgba(42,42,48,0.4);
}
.ms-source {
  font-size: 0.6rem;
  color: var(--muted, #71717A);
}
.ms-source a {
  color: var(--steel, #38BDF8);
  text-decoration: none;
}
.ms-source a:hover { text-decoration: underline; }
.ms-view-all {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--amber, #F59E0B);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  text-decoration: none;
}
.ms-view-all:hover { text-decoration: underline; }

/* ── Spinner (loading state) ─────────────────────────── */
.ef-loading {
  padding: 18px 13px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted, #71717A);
}
.ef-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--b2, #3A3A42);
  border-top-color: var(--amber, #F59E0B);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile — float becomes bottom pull-up ──────────── */
@media (max-width: 1023px) {
  #estima-float {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    transform: none !important;
    flex-direction: column-reverse;
    align-items: stretch;
    /* Only as tall as its contents — collapsed = just the toggle bar */
    height: auto;
  }

  #ef-toggle {
    writing-mode: horizontal-tb;
    flex-direction: row;
    justify-content: center;
    border-radius: 12px 12px 0 0;
    border-right: 1px solid var(--b1, #2A2A30);
    border-bottom: none;
    padding: 10px 16px;
    font-size: 0.65rem;
    box-shadow: 0 -3px 16px rgba(0,0,0,0.5);
    /* Fixed height so we know exactly how tall the toggle bar is */
    height: 44px;
    flex-shrink: 0;
  }

  #ef-panel {
    border-radius: 16px 16px 0 0;
    border-right: 1px solid var(--b1, #2A2A30);
    max-height: 55vh;
    width: 100%;
    /* Collapsed: slide fully below screen so it has zero touch footprint */
    transform: none;
    transition: max-height 0.3s cubic-bezier(0.4,0,0.2,1),
                opacity    0.3s ease;
  }

  /* Collapsed: panel has zero height and is invisible — no touch area at all */
  #estima-float.ef-collapsed #ef-panel {
    transform: none;
    max-height: 0 !important;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
  }

  /* Expanded: panel grows up from toggle bar */
  #estima-float:not(.ef-collapsed) #ef-panel {
    max-height: 55vh;
    opacity: 1;
    pointer-events: auto;
  }

  .ms-grid { grid-template-columns: 1fr 1fr; }

  /* Push page content up so toggle bar doesn't overlap bottom of page */
  body { padding-bottom: 44px; }
}
