/* 登入遮罩 */
html.access-locked,
html.access-locked body { overflow: hidden !important; }
html.access-locked body > * { visibility: hidden; }
html.access-locked body > .access-gate { visibility: visible !important; }
.access-gate {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 18% 15%, rgba(199,155,82,.25), transparent 35%),
    radial-gradient(circle at 86% 85%, rgba(167,84,53,.28), transparent 38%),
    #20211f;
  transition: opacity .24s ease, visibility .24s ease;
}
.access-gate.access-unlocking { opacity: 0; visibility: hidden !important; }
.access-card {
  width: min(100%, 420px);
  padding: 34px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 22px;
  background: rgba(255,253,248,.98);
  color: #20211f;
  box-shadow: 0 28px 80px rgba(0,0,0,.38);
}
.access-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 24px;
  border-radius: 50%;
  background: #20211f;
  color: #efbd78;
  font: 800 16px/1 "Microsoft JhengHei", sans-serif;
  letter-spacing: .08em;
}
.access-eyebrow { margin: 0 0 8px; color: #a75435; font-size: 11px; font-weight: 800; letter-spacing: .17em; }
.access-card h1 { margin: 0; font-size: 34px; line-height: 1.18; letter-spacing: -.025em; }
.access-copy { margin: 14px 0 24px; color: #72746e; font-size: 14px; line-height: 1.75; }
.access-card label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 800; }
.access-input-row { position: relative; }
.access-input-row input {
  width: 100%;
  min-height: 52px;
  padding: 0 68px 0 15px;
  border: 1px solid #cfc7ba;
  border-radius: 11px;
  outline: none;
  background: #fff;
  color: #20211f;
  font: inherit;
  font-size: 16px;
  transition: border-color .18s, box-shadow .18s;
}
.access-input-row input:focus { border-color: #a75435; box-shadow: 0 0 0 3px rgba(167,84,53,.13); }
.access-toggle {
  position: absolute;
  top: 50%;
  right: 7px;
  min-width: 52px;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #72746e;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.access-error { min-height: 22px; margin: 7px 0 3px; color: #a43c2b; font-size: 13px; }
.access-submit {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 11px;
  background: #20211f;
  color: #fff;
  font: inherit;
  font-weight: 800;
  letter-spacing: .05em;
  cursor: pointer;
}
.access-submit:hover { background: #a75435; }
.access-submit:disabled { cursor: wait; opacity: .72; }
.access-card small { display: block; margin-top: 15px; color: #8b8c87; text-align: center; line-height: 1.6; }
.access-denied { animation: access-shake .3s ease; }
@keyframes access-shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }

/* 手機與平板適配 */
.card,
.grid > * { min-width: 0; }
@media (max-width: 950px) {
  .left-nav {
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .left-nav::-webkit-scrollbar { display: none; }
  .left-nav a { flex: 0 0 auto; }
  .left-nav a[style] { padding: 20px 9px 17px !important; font-size: 12px !important; }
  .wrap { width: 100%; max-width: 100%; padding-right: 16px; padding-left: 16px; }
  .card { max-width: 100%; overflow: hidden; }
  .card > div[style*="overflow-x:auto"],
  #newCatalog div[style*="overflow-x:auto"] {
    max-width: 100%;
    overflow-x: auto !important;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  #newCatalog article > div[style*="grid-template-columns:minmax"],
  #newCatalog article div[style*="grid-template-columns:repeat(3"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  html { scroll-padding-top: 66px; }
  .left-nav { height: 56px; padding: 0 8px; }
  .left-nav a,
  .left-nav a[style] { padding: 17px 9px 14px !important; font-size: 12px !important; }
  .wrap { padding: 76px 12px 52px; }
  header { padding-bottom: 19px; }
  header h1 { font-size: clamp(34px, 11vw, 46px); }
  .meta { font-size: 13px; }
  .grid { gap: 11px; margin-top: 14px; }
  .card { padding: 15px; border-radius: 12px; }
  .metric { grid-column: span 12; }
  .metric b { font-size: 30px; }
  h2 { font-size: 19px; }
  table { min-width: 680px; font-size: 12px; }
  th, td { padding: 9px 7px; }
  .gallery-grid { gap: 8px; }
  .thumb span { right: 6px; left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .anchor { scroll-margin-top: 65px; }
  .access-gate { align-items: center; padding: 16px; }
  .access-card { padding: 26px 20px 23px; border-radius: 18px; }
  .access-mark { margin-bottom: 19px; }
  .access-card h1 { font-size: 29px; }
  .access-copy { margin-bottom: 20px; }
  .access-input-row input,
  .access-submit { min-height: 50px; }
}
@media (max-width: 380px) {
  .wrap { padding-right: 10px; padding-left: 10px; }
  .card { padding: 13px; }
  .gallery-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .access-gate { transition: none; }
  .access-denied { animation: none; }
}

/* 完整新家預算與冷氣報價 */
.budget-intro { margin-bottom: 16px; }
.budget-intro h2 { margin: 4px 0 8px; font-size: 30px; }
.budget-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}
.budget-metric {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 17px;
  border-radius: 12px;
  background: var(--paper);
}
.budget-metric span { color: var(--muted); font-size: 12px; font-weight: 800; }
.budget-metric b { font-size: clamp(22px, 2.8vw, 32px); line-height: 1.15; }
.budget-metric small { color: var(--muted); line-height: 1.45; }
.budget-metric.budget-total { background: #20211f; color: #fff; }
.budget-metric.budget-total span,
.budget-metric.budget-total small { color: #c9c6bd; }
.budget-sync-status { margin: 12px 0 0; color: var(--muted); font-size: 12px; text-align: right; }
.budget-sync-status[data-state="saved"] { color: #32633e; }
.budget-sync-status[data-state="saving"] { color: #8d662b; }
.budget-sync-status[data-state="error"] { color: #a43c2b; }
.budget-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.budget-group { padding: 20px; }
.budget-group-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.budget-group-head h3 { margin: 3px 0 4px; font-size: 21px; }
.budget-group-head p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.budget-group-head > b { flex: 0 0 auto; font-size: 21px; }
.budget-table-wrap { width: 100%; margin-top: 15px; overflow-x: auto; overscroll-behavior-x: contain; }
.budget-table { min-width: 520px; }
.budget-input {
  display: inline-flex;
  align-items: center;
  width: 130px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.budget-input span { padding-left: 9px; color: var(--muted); }
.budget-input input { width: 100%; padding: 7px 8px 7px 3px; border: 0; outline: 0; background: transparent; font: inherit; text-align: right; }
.budget-status { display: inline-block; padding: 4px 8px; border-radius: 999px; background: #eee8dc; color: #706552; font-size: 11px; font-weight: 800; white-space: nowrap; }
.budget-status.is-quoted { background: #e3f0e6; color: #32633e; }
.aircon-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.aircon-total { flex: 0 0 auto; padding: 14px 18px; border-radius: 12px; background: #20211f; color: #fff; }
.aircon-total span { display: block; color: #c9c6bd; font-size: 11px; }
.aircon-total b { display: block; margin-top: 3px; font-size: 25px; }
.aircon-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(240px, .65fr); gap: 18px; align-items: start; margin-top: 18px; }
.aircon-sheet { position: relative; display: block; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: #fff; }
.aircon-sheet img { display: block; width: 100%; height: auto; }
.aircon-sheet span { position: absolute; right: 8px; bottom: 8px; left: 8px; padding: 9px 10px; border-radius: 8px; background: rgba(32,33,31,.86); font-size: 12px; font-weight: 800; text-align: center; }
.privacy-note { margin: 15px 0 0; padding: 12px 14px; border-radius: 10px; background: #f4f0e7; color: var(--muted); font-size: 12px; line-height: 1.65; }

@media (max-width: 950px) {
  .budget-groups { grid-template-columns: 1fr; }
  .aircon-layout { grid-template-columns: 1fr; }
  .aircon-sheet { max-width: 620px; }
}
@media (max-width: 600px) {
  .budget-summary { grid-template-columns: 1fr; }
  .budget-metric { padding: 14px; }
  .budget-group { padding: 15px; }
  .budget-group-head { display: block; }
  .budget-group-head > b { display: block; margin-top: 10px; }
  .aircon-head { display: block; }
  .aircon-total { display: inline-block; margin-top: 12px; }
}

/* 手動新增預算 */
.custom-budget-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(3, minmax(130px, .7fr));
  gap: 10px;
  align-items: end;
  margin-top: 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}
.custom-budget-title { align-self: center; }
.custom-budget-title b,
.custom-budget-title span { display: block; }
.custom-budget-title span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.custom-budget-form label > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 800; }
.custom-budget-form input,
.custom-budget-form select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.custom-budget-form button {
  min-height: 42px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.custom-budget-group { grid-column: 1 / -1; }
.custom-budget-empty { margin: 15px 0 0; padding: 14px; border-radius: 9px; background: var(--paper); color: var(--muted); font-size: 13px; }
.budget-delete { padding: 6px 9px; border: 1px solid #d6a79a; border-radius: 7px; background: #fff7f4; color: #93442e; font: inherit; font-size: 12px; cursor: pointer; }
.removed-budget-group { grid-column: 1 / -1; }
.removed-budget-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.removed-budget-list > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 9px; background: var(--paper); }
.removed-budget-list span { min-width: 0; overflow-wrap: anywhere; }
.removed-budget-list small { display: block; margin-bottom: 2px; color: var(--muted); }
.removed-budget-list button { flex: 0 0 auto; padding: 6px 9px; border: 1px solid #9cb9a9; border-radius: 7px; background: #f4faf6; color: #32633e; font: inherit; font-size: 12px; cursor: pointer; }
html, body { max-width: 100%; overflow-x: clip; }

@media (max-width: 700px) {
  html { scroll-padding-top: 12px; scroll-padding-bottom: 74px; }
  body { padding: 0 0 calc(70px + env(safe-area-inset-bottom, 0px)) !important; }
  .wrap { width: 100%; max-width: 100%; padding: 24px 10px calc(92px + env(safe-area-inset-bottom, 0px)) !important; overflow-x: clip; }
  .anchor { scroll-margin-top: 14px !important; scroll-margin-bottom: 76px; }

  /* 五個主要入口固定在手機底部，不需要左右滑動。 */
  .left-nav {
    inset: auto 0 0 0 !important;
    width: 100% !important;
    height: calc(62px + env(safe-area-inset-bottom, 0px)) !important;
    padding: 0 4px env(safe-area-inset-bottom, 0px) !important;
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch !important;
    gap: 0 !important;
    overflow: hidden !important;
    border-top: 1px solid #3c3c38;
    box-shadow: 0 -8px 24px rgba(0,0,0,.18);
  }
  .left-nav .nav-brand,
  .left-nav .nav-foot,
  .left-nav > a { display: none !important; }
  .left-nav > a[href="#overview"],
  .left-nav > a[href="#home-budget"],
  .left-nav > a[href="#aircon"],
  .left-nav > a[href="#details"],
  .left-nav > a[href="#new-full"] {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 0;
    height: 100%;
    padding: 5px 2px !important;
    border: 0 !important;
    border-top: 3px solid transparent !important;
    background: transparent;
    color: #aaa;
    font-size: 0 !important;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
  }
  .left-nav > a[href="#overview"]::after { content: "總覽"; }
  .left-nav > a[href="#home-budget"]::after { content: "預算"; }
  .left-nav > a[href="#aircon"]::after { content: "冷氣"; }
  .left-nav > a[href="#details"]::after { content: "比對"; }
  .left-nav > a[href="#new-full"]::after { content: "資料"; }
  .left-nav > a::after { font-size: 12px; font-weight: 800; }
  .left-nav > a.active { color: #fff !important; border-top-color: #d9b477 !important; }

  header { gap: 12px; }
  header h1 { font-size: clamp(31px, 10vw, 43px); }
  .card { max-width: 100%; padding: 14px; overflow: visible; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .grid > *, .metric, .wide, .side, .gallery { grid-column: 1 !important; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .thumb { min-width: 0; }
  img { max-width: 100%; }

  .custom-budget-form { grid-template-columns: 1fr; align-items: stretch; }
  .removed-budget-list { grid-template-columns: 1fr; }
  .custom-budget-title { margin-bottom: 3px; }
  .budget-table-wrap,
  .card > div[style*="overflow-x:auto"],
  #newCatalog div[style*="overflow-x:auto"] {
    width: 100%;
    max-width: 100%;
    overflow: visible !important;
  }
  .responsive-card-table {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    border-collapse: separate;
  }
  .responsive-card-table thead { display: none; }
  .responsive-card-table tbody,
  .responsive-card-table tfoot { display: grid; gap: 9px; width: 100%; }
  .responsive-card-table tfoot { margin-top: 9px; }
  .responsive-card-table tr {
    display: block;
    width: 100%;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
  }
  .responsive-card-table td,
  .responsive-card-table tfoot th {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-width: 0;
    padding: 9px 10px !important;
    border-bottom: 1px solid #ece6dc;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  .responsive-card-table td:last-child,
  .responsive-card-table tfoot th:last-child { border-bottom: 0; }
  .responsive-card-table td::before,
  .responsive-card-table tfoot th::before {
    content: attr(data-label);
    flex: 0 0 38%;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-align: left;
  }
  .responsive-card-table td > *,
  .responsive-card-table tfoot th > * { min-width: 0; }
  .budget-input { width: min(150px, 100%); }
  .budget-input input { min-width: 0; }
  .budget-sync-status { text-align: left; }
}

@media (max-width: 380px) {
  .gallery-grid { grid-template-columns: 1fr; }
  .responsive-card-table td::before,
  .responsive-card-table tfoot th::before { flex-basis: 34%; }
}
