/**
 * MSHB Profit Projector styles
 * Scoped under .mshb-projector so the WordPress theme's header/footer are untouched.
 */

.mshb-projector {
    --mshb-brand: #1f3060;
    --mshb-brand-light: #2a4a8a;
    --mshb-accent: #27ae60;
    --mshb-danger: #c0392b;
    --mshb-card: #ffffff;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: #333;
    background: #f8f9fa;
    /* Break out of theme's max-width content container so the tool fills the viewport. */
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    margin-top: 0;
    margin-bottom: 0;
}

.mshb-projector * { box-sizing: border-box; }

.mshb-projector-header {
    background: var(--mshb-brand);
    color: white;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.mshb-projector-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.mshb-projector-title h1 { font-size: 22px; font-weight: 600; margin: 0; color: white; }
.mshb-projector-title span { font-size: 13px; opacity: 0.8; }

.mshb-projector .layout { display: flex; }

.mshb-projector .sidebar {
    width: 340px;
    min-width: 340px;
    background: var(--mshb-card);
    border-right: 1px solid #ddd;
    padding: 20px;
    overflow-y: auto;
}
.mshb-projector .sidebar h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--mshb-brand);
    margin: 18px 0 10px;
    border-bottom: 2px solid var(--mshb-brand);
    padding-bottom: 4px;
}
.mshb-projector .sidebar h2:first-child { margin-top: 0; }

.mshb-projector .field { margin-bottom: 10px; }
.mshb-projector .field label {
    display: block;
    font-size: 12px;
    color: #555;
    margin-bottom: 2px;
    font-weight: 500;
}
.mshb-projector .field input,
.mshb-projector .field select {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    color: #333;
}
.mshb-projector .field input:focus,
.mshb-projector .field select:focus {
    outline: none;
    border-color: var(--mshb-brand-light);
    box-shadow: 0 0 0 2px rgba(41, 128, 185, 0.15);
}

.mshb-projector .field-row { display: flex; gap: 10px; }
.mshb-projector .field-row .field { flex: 1; }

.mshb-projector .effective-rate-display {
    font-weight: 700;
    color: var(--mshb-accent);
    font-size: 20px;
    line-height: 36px;
}

.mshb-projector .toggle-group {
    display: flex;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
}
.mshb-projector .toggle-group button {
    flex: 1;
    padding: 7px;
    border: none;
    background: white;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    color: #333;
}
.mshb-projector .toggle-group button.active {
    background: var(--mshb-brand);
    color: white;
}
.mshb-projector .toggle-hint { font-size: 11px; color: #888; margin-top: 2px; }

.mshb-projector .btn {
    background: var(--mshb-brand);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    width: 100%;
    margin-top: 10px;
}
.mshb-projector .btn:hover { background: var(--mshb-brand-light); }
.mshb-projector .btn-reset { background: #95a5a6; margin-top: 6px; }
.mshb-projector .btn-reset:hover { background: #7f8c8d; }

.mshb-projector .main {
    flex: 1;
    padding: 20px;
    overflow-x: auto;
    background: white;
    min-width: 0; /* prevent flex item from forcing horizontal scroll on the row */
}

.mshb-projector .property-context {
    background: #fef9e7;
    border: 1px solid #f4d03f;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 14px;
    font-size: 13px;
    line-height: 1.4;
}
.mshb-projector .property-context-address { font-size: 14px; }
.mshb-projector .property-context-specs { color: #7a5d00; font-size: 12px; margin-top: 2px; }

.mshb-projector .summary-cards {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}
.mshb-projector .card {
    background: var(--mshb-card);
    border-radius: 6px;
    padding: 10px 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #eee;
    min-width: 0; /* allow grid track to shrink card below intrinsic content */
    overflow: hidden;
}
.mshb-projector .card .label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mshb-projector .card .value {
    font-size: 19px;
    font-weight: 700;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mshb-projector .card .value.positive { color: var(--mshb-accent); }
.mshb-projector .card .value.negative { color: var(--mshb-danger); }
.mshb-projector .card .sub {
    font-size: 10px;
    color: #999;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mshb-projector .card.highlight { border: 2px solid #e74c3c; }

/* Below ~1500px the 8-card row gets cramped — drop to 4 across (two rows). */
@media (max-width: 1500px) {
    .mshb-projector .summary-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .mshb-projector .summary-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.mshb-projector .table-scroll { overflow-x: auto; }
.mshb-projector table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.mshb-projector th,
.mshb-projector td {
    padding: 6px 12px;
    text-align: right;
    white-space: nowrap;
}
.mshb-projector td:first-child,
.mshb-projector th:first-child {
    text-align: left;
    background: inherit;
    min-width: 240px;
    font-weight: 500;
}
.mshb-projector .section-header td {
    font-size: 14px;
    font-weight: 700;
    color: var(--mshb-brand);
    padding-top: 14px;
    background: #f0f4f8 !important;
}
.mshb-projector .blank-row td { height: 10px; border: none; }
.mshb-projector .subtotal td { border-top: 2px solid #aaa; font-weight: 600; }
.mshb-projector .grand-total td {
    border-top: 3px solid var(--mshb-brand);
    font-weight: 700;
    font-size: 14px;
    background: #f0f4f8 !important;
}
.mshb-projector .irr-row td {
    background: var(--mshb-brand) !important;
    color: white !important;
    font-size: 16px;
    font-weight: 700;
    border: none;
}
.mshb-projector .year-header th {
    background: var(--mshb-brand);
    color: white;
    font-weight: 600;
    font-size: 12px;
}
.mshb-projector .yr0-col { background: #fef9e7 !important; }
.mshb-projector .year-header .yr0-col { background: #b7950b !important; }
.mshb-projector tbody tr:hover td { background: #fafde8; }
.mshb-projector .section-header:hover td,
.mshb-projector .grand-total:hover td { background: #f0f4f8 !important; }
.mshb-projector .irr-row:hover td { background: var(--mshb-brand) !important; }

.mshb-projector .neg { color: var(--mshb-danger); }
.mshb-projector .pos { color: var(--mshb-accent); }

.mshb-projector .info-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: #3498db;
    border-radius: 50%;
    text-align: center;
    line-height: 16px;
    font-size: 11px;
    color: white;
    margin-left: 6px;
    font-style: italic;
    font-weight: 700;
    cursor: help;
}

.mshb-projector .disclaimer {
    margin-top: 20px;
    padding: 14px 18px;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 11px;
    color: #888;
    line-height: 1.5;
}

/* ===== Modal ===== */
.mshb-modal[hidden] { display: none; }
.mshb-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mshb-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}
.mshb-modal-card {
    position: relative;
    background: white;
    border-radius: 8px;
    padding: 28px 32px;
    width: min(560px, 92vw);
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.mshb-modal-card h2 {
    margin: 0 0 6px;
    color: var(--mshb-brand);
    font-size: 22px;
}
.mshb-modal-card p { margin: 0 0 16px; font-size: 14px; color: #555; }
.mshb-modal-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #888;
}
.mshb-modal-close:hover { color: #333; }
.mshb-modal-fallback { background: #fef9e7; padding: 12px; border-radius: 4px; }
body.mshb-modal-open { overflow: hidden; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .mshb-projector .layout { flex-direction: column; }
    .mshb-projector .sidebar {
        width: 100%;
        min-width: 0;
        border-right: none;
        border-bottom: 1px solid #ddd;
        /* Sticky doesn't make sense in a stacked column layout. */
        position: static;
        max-height: none;
    }
}

/* ===== Print (Ctrl+P / window.print fallback) =====
   The downloadable PDF is built from data via jsPDF; this only styles a manual
   browser print. The projector renders deep inside the WP theme's markup, so we
   can't rely on `body > *` sibling hiding — instead hide everything via visibility
   (ancestors stay in flow but render blank) and re-show only the projector subtree. */
@media print {
    body * { visibility: hidden; }
    .mshb-projector,
    .mshb-projector * { visibility: visible; }
    .mshb-projector .sidebar,
    .mshb-projector .mshb-projector-header,
    .mshb-modal { display: none !important; }
    .mshb-projector { position: absolute; left: 0; top: 0; width: 100%; margin: 0; }
    .mshb-projector .main { padding: 0; overflow: visible; }
    .mshb-projector .layout { display: block; }
    .mshb-projector table { font-size: 10px; }
    .mshb-projector .summary-cards { gap: 8px; }
    .mshb-projector .card { min-width: 130px; padding: 8px 12px; box-shadow: none; }
    .mshb-projector .card .value { font-size: 18px; }
}
