/* Multifamily Deal Analyzer */
.mfda {
  --mf-bg: #f6f7f9;
  --mf-card: #fff;
  --mf-line: #e2e5ea;
  --mf-text: #1d2430;
  --mf-muted: #6b7280;
  --mf-accent: #1e4e8c;
  --mf-accent-ink: #fff;
  --mf-good: #1f9d55;
  --mf-warn: #b7791f;
  --mf-bad: #c53030;
  color: var(--mf-text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  max-width: 1320px;
  margin: 0 auto;
}
.mfda *, .mfda *::before, .mfda *::after { box-sizing: border-box; }
.mfda-admin { margin-top: 16px; }
.mfda h3 { margin: 0 0 12px; font-size: 15px; font-weight: 650; }
.mfda small { display: block; color: var(--mf-muted); font-size: 12px; font-weight: 400; }
.mfda-muted { color: var(--mf-muted); font-size: 12.5px; margin: 8px 0 0; }

/* Toolbar */
.mfda-toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--mf-card); border: 1px solid var(--mf-line); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 16px; position: sticky; top: 32px; z-index: 20;
}
.mfda-title strong { font-size: 17px; }
.mfda-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mfda-btn {
  appearance: none; border: 1px solid var(--mf-accent); background: var(--mf-accent); color: var(--mf-accent-ink);
  border-radius: 7px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2;
}
.mfda-btn.ghost { background: transparent; color: var(--mf-accent); }
.mfda-btn.sm { padding: 5px 10px; font-size: 12.5px; }
.mfda-btn:disabled { opacity: .45; cursor: not-allowed; }
.mfda-btn:hover:not(:disabled) { filter: brightness(1.08); }
.mfda-menu { position: relative; }
.mfda-menu-pop {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); min-width: 180px;
  background: var(--mf-card); border: 1px solid var(--mf-line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px; z-index: 30;
}
.mfda-menu.open .mfda-menu-pop { display: block; }
.mfda-menu-pop button {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px;
  border-radius: 5px; font: inherit; color: var(--mf-text); cursor: pointer;
}
.mfda-menu-pop button:hover { background: var(--mf-bg); }

/* Layout */
.mfda-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 16px; align-items: start; }
.mfda-results { position: sticky; top: 110px; max-height: calc(100vh - 130px); overflow-y: auto; display: grid; gap: 12px; }
.mfda-form { display: grid; gap: 12px; }
.mfda-card { background: var(--mf-card); border: 1px solid var(--mf-line); border-radius: 10px; padding: 16px; }

/* Fields */
.mfda-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.mfda-field { display: flex; flex-direction: column; gap: 4px; }
.mfda-field.wide { grid-column: span 2; }
.mfda-field > span { font-weight: 600; font-size: 12.5px; }
.mfda input[type=text], .mfda input[type=number], .mfda select, .mfda textarea {
  width: 100%; border: 1px solid var(--mf-line); border-radius: 6px; padding: 7px 9px;
  font: inherit; color: var(--mf-text); background: #fff; min-height: 34px; max-width: none; margin: 0;
}
.mfda input:focus, .mfda select:focus, .mfda textarea:focus { outline: 2px solid rgba(30,78,140,.25); border-color: var(--mf-accent); }
.mfda input:disabled, .mfda select:disabled, .mfda textarea:disabled { background: var(--mf-bg); color: var(--mf-text); }
.mfda-affix { display: flex; align-items: stretch; }
.mfda-affix input { flex: 1; min-width: 0; }
.mfda-pre, .mfda-suf {
  display: flex; align-items: center; padding: 0 8px; background: var(--mf-bg); border: 1px solid var(--mf-line); color: var(--mf-muted);
}
.mfda-pre { border-right: 0; border-radius: 6px 0 0 6px; }
.mfda-suf { border-left: 0; border-radius: 0 6px 6px 0; }
.mfda-pre + input { border-radius: 0 6px 6px 0; }
.mfda-affix input:not(:last-child) { border-radius: 6px 0 0 6px; }

/* Units table */
.mfda-units { margin-bottom: 14px; }
.mfda-units table, .mfda-bench table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.mfda-units th, .mfda-bench th { text-align: left; font-size: 12px; color: var(--mf-muted); font-weight: 600; padding: 4px 6px; }
.mfda-units td, .mfda-bench td { padding: 3px 6px 3px 0; }
.mfda-units td:last-child { width: 32px; }
.mfda-x { background: none; border: 0; font-size: 18px; line-height: 1; color: var(--mf-muted); cursor: pointer; padding: 4px 6px; }
.mfda-x:hover { color: var(--mf-bad); }
.mfda-bench summary { cursor: pointer; font-weight: 650; }
.mfda-bench summary small { display: inline; }

/* Results */
.mfda-score { display: flex; gap: 16px; align-items: center; }
.mfda-gauge { width: 120px; height: 120px; transform: rotate(-90deg); }
.mfda-gauge circle { fill: none; stroke-width: 11; }
.mfda-gauge .trk { stroke: var(--mf-line); }
.mfda-gauge .val { stroke-linecap: round; transition: stroke-dashoffset .4s; }
.mfda-gauge text { transform: rotate(90deg); transform-origin: 60px 60px; fill: var(--mf-text); }
.mfda-gauge .n { font-size: 30px; font-weight: 700; }
.mfda-gauge .l { font-size: 11px; fill: var(--mf-muted); }
.mfda-grade { display: inline-block; color: #fff; font-weight: 800; font-size: 20px; border-radius: 8px; padding: 2px 12px; margin-bottom: 6px; }
.mfda-score h3 { margin: 0; font-size: 18px; }

.mfda-metrics, .mfda-kv, .mfda-proj, .mfda-list { width: 100%; border-collapse: collapse; }
.mfda-metrics td, .mfda-kv td { padding: 6px 0; border-bottom: 1px solid var(--mf-line); vertical-align: middle; }
.mfda-metrics tr:last-child td, .mfda-kv tr:last-child td { border-bottom: 0; }
.mfda-metrics td.v { text-align: right; font-weight: 600; padding-right: 12px; white-space: nowrap; }
.mfda-metrics td.s { width: 120px; white-space: nowrap; }
.mfda-metrics td.s b { display: inline-block; width: 26px; text-align: right; font-size: 12px; }
.mfda-bar { display: inline-block; width: 84px; height: 7px; background: var(--mf-line); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.mfda-bar i { display: block; height: 100%; border-radius: 4px; }
.mfda-na { color: var(--mf-muted); font-size: 12px; }
.mfda-kv td:last-child { text-align: right; }
.mfda-kv small { display: inline; }
.mfda .neg { color: var(--mf-bad); }

.mfda-flags { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.mfda-flags li { padding: 7px 10px 7px 12px; border-radius: 6px; border-left: 4px solid; font-size: 13px; }
.mfda-flags .bad { background: #fdecec; border-color: var(--mf-bad); }
.mfda-flags .warn { background: #fdf6e6; border-color: var(--mf-warn); }
.mfda-flags .info { background: #eef3fa; border-color: var(--mf-accent); }
.mfda-flags .good { background: #e8f6ee; border-color: var(--mf-good); }

.mfda-scroll { overflow-x: auto; }
.mfda-proj th, .mfda-proj td, .mfda-list th, .mfda-list td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--mf-line); white-space: nowrap; font-size: 12.5px; }
.mfda-proj th:first-child, .mfda-proj td:first-child, .mfda-list th:first-child, .mfda-list td:first-child { text-align: left; }
.mfda-proj th, .mfda-list th { color: var(--mf-muted); font-weight: 600; }
.mfda-list td:first-child { white-space: normal; }
.mfda-list a { font-weight: 600; color: var(--mf-accent); text-decoration: none; }
.mfda-pill { color: #fff; border-radius: 10px; padding: 1px 8px; font-weight: 700; font-size: 12px; }
.mfda-empty p { margin: 0 0 6px; }

/* Modal */
.mfda-modal { position: fixed; inset: 0; background: rgba(15,20,30,.45); z-index: 100000; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; }
.mfda-modal[hidden] { display: none; }
.mfda-modal-box { background: var(--mf-card); border-radius: 12px; padding: 20px; width: 100%; max-width: 860px; max-height: calc(100vh - 120px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.mfda-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.mfda-modal-head h3 { margin: 0; }
.mfda-copy { display: flex; gap: 6px; }

/* Toast */
.mfda-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #1d2430; color: #fff; padding: 10px 16px; border-radius: 8px; transition: all .2s; z-index: 100001; font-weight: 600;
}
.mfda-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.mfda-toast.err { background: var(--mf-bad); }

@media (max-width: 1024px) {
  .mfda-layout { grid-template-columns: 1fr; }
  .mfda-results { position: static; max-height: none; overflow: visible; }
  .mfda-toolbar { position: static; }
}
@media (max-width: 560px) {
  .mfda-field.wide { grid-column: auto; }
  .mfda-grid { grid-template-columns: 1fr; }
  .mfda-score { flex-direction: column; text-align: center; }
}

/* Print / PDF */
@media print {
  body * { visibility: hidden; }
  .mfda, .mfda * { visibility: visible; }
  .mfda { position: absolute; left: 0; top: 0; width: 100%; max-width: none; font-size: 11px; }
  .mfda-actions, .mfda-modal, .mfda-toast, .mfda-btn, .mfda-x, .mfda-saved { display: none !important; }
  .mfda-toolbar { position: static; border: 0; padding: 0 0 8px; }
  .mfda-layout { display: block; }
  .mfda-results { position: static; max-height: none; overflow: visible; display: block; }
  .mfda-card { break-inside: avoid; margin-bottom: 8px; padding: 10px; }
  .mfda-results { page-break-before: always; }
  .mfda input, .mfda select, .mfda textarea { border: 0; padding: 0; min-height: 0; background: none; }
  .mfda-pre, .mfda-suf { border: 0; background: none; padding: 0 2px; }
  .mfda-bench { display: none; }
  .mfda-flags li, .mfda-grade, .mfda-bar i, .mfda-pill { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
