/* =========================================================
   LALLIAN — House Affordability Calculator (LOCKED STANDARD)
   Mobile-first • Desktop 2-column • Donut + legend locked
   Colors: P&I #0f4fa8 • Taxes #8b5cf6 • Insurance #10b981 • Other #f97316
   ========================================================= */

:root{
  --bg:#eef2f6;
  --card:#ffffff;
  --text:#0f1428;
  --muted:rgba(15,20,40,.65);
  --border:rgba(15,20,40,.12);

  --pi:#0f4fa8;
  --tax:#8b5cf6;
  --ins:#10b981;
  --oth:#f97316;

  --shadow: 0 10px 30px rgba(15,20,40,.08);
  --radius: 16px;
  --radius-sm: 12px;

  --pad:14px;
  --gap:14px;
  --control-h:44px;
}

/* Respect HTML hidden attribute everywhere (prevents stuck modals/tooltips) */
html body [hidden],
html body .tt-pop[hidden],
html body .tt-pop[aria-hidden="true"]{
  display:none !important;
}

body{ background:var(--bg); color:var(--text); }

/* Header back button (matches mortgage.php pattern) */
/* Header back link (matches mortgage.php: right aligned, underline on hover) */
.head-row{
  display:flex;
  justify-content:flex-end;
  margin-bottom:8px;
}

.back-link{
  color: var(--text);
  font-weight: 800;
  font-size: 14px;
  text-decoration: none;
}

.back-link:hover{
  text-decoration: underline;
}


.calc-wrap{
  max-width:1180px;
  margin:0 auto;
  padding:14px 14px 40px;
}

.calc-head{ padding:6px 2px 14px; }
.calc-head h1{
  margin:0 0 6px;
  font-size:22px;
  line-height:1.2;
}

.muted{ color:var(--muted); }
.tiny{ font-size:12px; line-height:1.35; }

.calc-grid{
  display:grid;
  grid-template-columns: 1fr;
  gap:var(--gap);
  align-items:start;
}

/* Cards */
.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:var(--pad);
}
.card h2{ margin:0 0 12px; font-size:16px; }

/* Form */
.form .field{ margin-bottom:12px; }
.label{
  display:flex;
  align-items:center;
  gap:8px;
  font-weight:800;
  margin-bottom:6px;
}
.notice{ margin-top:6px; }

/* grids */
.grid-2{
  display:grid;
  grid-template-columns: 1fr;
  gap:12px;
}

/* Income type tiles */
.seg{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}
.seg-opt{
  border:1px solid var(--border);
  border-radius:var(--radius-sm);
  background:#fff;
  padding:10px 12px;
  min-height:52px;

  display:flex;
  align-items:center;
  gap:10px;

  cursor:pointer;
  user-select:none;
}
.seg-opt input{ width:16px; height:16px; margin:0; flex:0 0 auto; }
.seg-opt span{ font-weight:900; line-height:1.15; }

/* Affix inputs */
.affix{
  display:flex;
  align-items:center;
  border:1px solid var(--border);
  border-radius:var(--radius-sm);
  background:#fff;
  overflow:hidden;
  height:var(--control-h);
}
.affix .pre,
.affix .suf{
  display:flex;
  align-items:center;
  height:100%;
  padding:0 12px;
  font-size:13px;
  font-weight:900;
  color:var(--muted);
  white-space:nowrap;
}
.input{
  width:100%;
  height:100%;
  border:0;
  outline:none;
  padding:0 12px;
  font-size:14px;
  background:transparent;
  color:var(--text);
}

/* Mortgage-style unit dropdown inside the input */
.affix.has-unit .unit{
  height:100%;
  border:0;
  border-left:1px solid var(--border);
  background:#fff;
  padding:0 12px;
  font-weight:900;
  color:var(--text);
  cursor:pointer;
  appearance:none;
  min-width:74px;
}
.affix.has-unit .unit:focus{ outline:none; }

/* Select (standalone) */
.select{
  border:1px solid var(--border);
  border-radius:var(--radius-sm);
  height:var(--control-h);
  padding:0 12px;
  background:#fff;
  font-weight:800;
}

/* Buttons */
.actions{
  display:flex;
  gap:10px;
  margin-top:12px;
}
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  border-radius:var(--radius-sm);
  border:1px solid var(--border);
  padding:10px 12px;
  font-weight:900;
  font-size:14px;
  text-decoration:none;
  cursor:pointer;
  background:#fff;
  color:var(--text);
}
.btn-primary{
  background:var(--pi);
  border-color:transparent;
  color:#fff;
}
.btn-ghost{ background:#fff; }
.btn-mini{
  padding:8px 10px;
  font-size:12px;
  border-radius:12px;
}

/* Field header row (label + mini button) */
.field-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:6px;
}

/* Tooltip ? */
.tt{
  width:20px;
  height:20px;
  border-radius:999px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--muted);
  font-weight:900;
  font-size:12px;
  line-height:1;
  cursor:pointer;
}

/* Link-like mini button under text */
.link-btn{
  border:0;
  background:transparent;
  color:var(--pi);
  font-weight:800;
  cursor:pointer;
  padding:0;
}

/* Repeater */
.rep{
  display:grid;
  gap:10px;
}
.rep-row{
  display:grid;
  grid-template-columns: 1fr 1.1fr 36px;
  gap:10px;
  align-items:center;
}
.rep-row .input{
  border:1px solid var(--border);
  border-radius:var(--radius-sm);
  height:var(--control-h);
  padding:0 12px;
  background:#fff;
}
.rep-row .affix .input{
  border:0;
  border-radius:0;
  height:100%;
  padding:0 12px;
}
.rep-x{
  width:36px;
  height:36px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  cursor:pointer;
  font-size:18px;
  font-weight:900;
  line-height:1;
}

/* Compact row (fixes broken layout area) */
/* ---------------------------------------------------------
   Compact row: Close costs + Maint on same line, Total DTI below
--------------------------------------------------------- */
.compact-3{
  display:grid;
  grid-template-columns: 1fr;   /* mobile */
  gap:12px;
  margin-top:6px;
}

@media (min-width: 680px){
  .compact-3{
    grid-template-columns: 1fr 1fr;  /* 2-up */
  }
  .compact-3 .field:last-child{
    grid-column: 1 / -1;            /* Total DTI full-width under */
  }
}

/* IMPORTANT: keep Total DTI on bottom even on desktop */
@media (min-width: 980px){
  .compact-3{
    grid-template-columns: 1fr 1fr;  /* still 2-up */
  }
  .compact-3 .field:last-child{
    grid-column: 1 / -1;            /* still full-width under */
  }
}


/* Checkbox row */
.check{
  display:flex;
  gap:8px;
  align-items:center;
  font-size:14px;
  color:var(--text);
  font-weight:800;
  margin-bottom:8px;
}

/* Results column */
.calc-right{
  display:grid;
  gap:var(--gap);
}
.result-top{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}
.badge{
  border:1px solid var(--border);
  color:var(--muted);
  background:#fff;
  border-radius:999px;
  padding:7px 10px;
  font-size:12px;
  font-weight:900;
  white-space:nowrap;
}

/* Big number */
.big-number{
  margin-top:8px;
  padding:12px;
  border-radius:14px;
  border:1px solid var(--border);
  background:#fff;
}
.big-label{
  color:var(--muted);
  font-size:12px;
  font-weight:900;
}
.big-value{
  font-size:28px;
  font-weight:900;
  letter-spacing:-0.02em;
  margin-top:4px;
  color:var(--pi); /* match pie/donut blue */
}

/* Summary line */
.sum-inline{
  display:block;
  margin-top:6px;
}
.sum-inline strong{ font-weight:900; }

/* KV tiles */
.kv-row{
  display:grid;
  grid-template-columns: 1fr;
  gap:10px;
  margin-top:12px;
}
.kv{
  border:1px solid var(--border);
  border-radius:14px;
  padding:10px 12px;
  background:#fff;
}
.kv-label{
  color:var(--muted);
  font-size:12px;
  font-weight:900;
}
.kv-value{
  font-size:16px;
  font-weight:900;
  margin-top:2px;
}

/* downloads row */
.dl-row{
  display:grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap:10px;
  margin-top:12px;
}

/* Lines */
.lines{ display:grid; gap:10px; }
.line{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:center;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff;
}
.line.total{ border-color: rgba(15,79,168,.35); }
.line strong{ font-weight:900; white-space:nowrap; }

/* Donut */
.donut-wrap{
  display:grid;
  grid-template-columns: 1fr;
  gap:12px;
  align-items:center;
}
.donut{
  width:220px;
  height:220px;
  border-radius:999px;
  margin:4px auto 0;
  position:relative;

  background:
    conic-gradient(
      var(--pi) 0 calc(var(--p1)*1%),
      var(--tax) calc(var(--p1)*1%) calc((var(--p1) + var(--p2))*1%),
      var(--ins) calc((var(--p1) + var(--p2))*1%) calc((var(--p1) + var(--p2) + var(--p3))*1%),
      var(--oth) calc((var(--p1) + var(--p2) + var(--p3))*1%) 100%
    );
}
.donut::after{
  content:"";
  position:absolute;
  inset:18px;
  background:#fff;
  border-radius:999px;
  border:1px solid var(--border);
}
.donut-center{
  position:absolute;
  inset:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  text-align:center;
  z-index:2;
  padding:20px;
}
.donut-value{
  font-weight:900;
  font-size:20px;
  margin-top:4px;
}
.legend{ display:grid; gap:10px; }
.leg-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  border:1px solid var(--border);
  border-radius:14px;
  padding:10px 12px;
  background:#fff;
}
.sw{
  width:12px;
  height:12px;
  border-radius:4px;
  display:inline-block;
  margin-right:8px;
}
.sw-pi{ background:var(--pi); }
.sw-tax{ background:var(--tax); }
.sw-ins{ background:var(--ins); }
.sw-oth{ background:var(--oth); }

/* Language tabs */
.lang-tabs{
  display:flex;
  gap:10px;
  margin-bottom:10px;
}
.tab{
  border:1px solid var(--border);
  background:#fff;
  border-radius:999px;
  padding:8px 12px;
  font-weight:900;
  cursor:pointer;
  color:var(--text);
}
.tab.is-active{
  background: rgba(15,79,168,.10);
  border-color: rgba(15,79,168,.25);
}
.bullets{
  margin:10px 0 0;
  padding-left:18px;
}
.bullets li{
  margin:6px 0;
}

/* Tooltip modal */
.tt-pop{
  position:fixed;
  inset:0;
  background:rgba(15,20,40,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:9999;
}
.tt-box{
  width:min(520px, 100%);
  background:#fff;
  border-radius:16px;
  border:1px solid var(--border);
  box-shadow:var(--shadow);
  padding:14px;
}
.tt-close{
  width:36px;
  height:36px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  cursor:pointer;
  font-size:18px;
  font-weight:900;
  float:right;
}
.tt-title{
  font-weight:900;
  margin:6px 0 10px;
  font-size:16px;
}
.tt-body{
  padding-top:8px;
  color:var(--text);
  line-height:1.45;
  font-size:14px;
}

@media (max-width: 420px){
  .label{ font-size:13px; }
  .seg-opt{ min-height:50px; }
  .rep-row{ grid-template-columns: 1fr 1fr 36px; }
}

@media (min-width: 680px){
  .compact-3{
    grid-template-columns: 1fr 1fr;
  }
  .compact-3 .field:last-child{
    grid-column: 1 / -1;
  }
}

@media (min-width: 980px){
  .calc-grid{
    grid-template-columns: 1.05fr .95fr;
  }
  .grid-2{
    grid-template-columns: 1fr 1fr;
  }
  .kv-row{
    grid-template-columns: 1fr 1fr 1fr;
  }
  .donut-wrap{
    grid-template-columns: 260px 1fr;
    gap:14px;
  }
  .calc-right{
    position:sticky;
    top:16px;
    align-self:start;
  }
  .compact-3{
    grid-template-columns: 1fr 1fr 1fr;
  }
  .compact-3 .field:last-child{
    grid-column:auto;
  }
}

@media print{
  body{ background:#fff; }
  .calc-head, form, .actions, .dl-row, .tt-pop { display:none !important; }
  .calc-grid{ grid-template-columns: 1fr !important; }
  .card{ box-shadow:none; }
}

/* ---------------------------------------------------------
   FIX: dropdown caret (down arrow) for unit selects + DTI select
--------------------------------------------------------- */
/* ---------------------------------------------------------
   Unit dropdown inside affix (caret + width FIX)
--------------------------------------------------------- */

/* ---------------------------------------------------------
   Unit dropdown inside affix (mortgage-style: stays on ONE line)
--------------------------------------------------------- */
.affix.has-unit{
  display:flex;
  align-items:stretch;
  flex-wrap:nowrap;          /* prevent unit dropping down */
}

.affix.has-unit .pre{
  flex:0 0 auto;
}

.affix.has-unit .input{
  flex:1 1 auto;
  min-width:0;               /* allow shrinking without breaking layout */
}

/* the unit select */
.affix.has-unit .unit{
  flex:0 0 84px;             /* fixed width so %/yr and $/yr fit */
  width:84px;
  border:0;
  border-left:1px solid var(--border);
  background:#fff;

  padding:0 34px 0 10px;     /* caret space */
  font-weight:900;
  color:var(--text);
  cursor:pointer;

  appearance:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 20 20'%3E%3Cpath fill='%236b7280' d='M5.5 7.5l4.5 5 4.5-5'/%3E%3C/svg%3E");
  background-repeat:no-repeat;
  background-position:right 12px center;
  background-size:16px 16px;
}

/* slightly narrower on tiny screens if needed */
@media (max-width: 420px){
  .affix.has-unit .unit{
    flex-basis:76px;
    width:76px;
  }
}



/* Standalone select (DTI preset) */
.select{
  padding-right: 38px;                 /* space for caret */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 20 20'%3E%3Cpath fill='%236b7280' d='M5.5 7.5l4.5 5 4.5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
  appearance: none;
}

/* optional: keep consistent in Safari */
select::-ms-expand{ display:none; }
/* Explanation accordion */
.explain-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}

.acc{
  display:grid;
  gap:10px;
  margin-top:12px;
}

.acc-item{
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff;
  overflow:hidden;
}

.acc-sum{
  list-style:none;
  cursor:pointer;
  padding:12px 12px;
  font-weight:900;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.acc-sum::-webkit-details-marker{ display:none; }

.acc-sum::after{
  content:"";
  width:16px;
  height:16px;
  flex:0 0 16px;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 20 20'%3E%3Cpath fill='%236b7280' d='M5.5 7.5l4.5 5 4.5-5'/%3E%3C/svg%3E");
  background-repeat:no-repeat;
  background-position:center;
  background-size:16px 16px;
  transition: transform .15s ease;
}

details[open] > .acc-sum::after{
  transform: rotate(180deg);
}

.acc-body{
  padding: 0 12px 12px;
}

.acc-body .bullets{
  margin:10px 0 0;
}
/* =========================================
   Affordability – circular checkbox
========================================= */
.check.aff-check{
  display: inline-flex;
  align-items: center;
  gap: 6px;              /* bring text closer */
  margin-top: 8px;
  cursor: pointer;
}

/* hide native checkbox */
.check.aff-check input{
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid #cbd5e1;   /* subtle gray */
  border-radius: 50%;          /* circle */
  display: inline-grid;
  place-content: center;
  margin: 0;
  cursor: pointer;
  background: #fff;
}

/* checked state */
.check.aff-check input:checked{
  border-color: #2563eb;       /* brand blue */
  background: #2563eb;
}

/* inner dot */
.check.aff-check input:checked::before{
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

/* label text */
.check.aff-check span{
  font-size: 0.95rem;
  line-height: 1;
  white-space: nowrap;
}

