/* --- STYLES FOR INDIVIDUAL MATRIX/VECTOR CALCULATOR INPUT PAGES --- */

/* Page Level Layout: Flexible Wrapper */
.calculator-page-wrapper {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    box-sizing: border-box;
}

.calculator-main-col {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
}

/*
 * Right Sidebar Column & Sidebar Ad Slot:
 * HIDDEN BY DEFAULT to completely eliminate flashes/layout shifts on page load or refresh.
 * Only activated when the viewport has sufficient width (>= 1200px) for the calculator
 * and sidebar to comfortably coexist side-by-side.
 * When viewport is < 1200px, it stays display: none and NEVER stacks underneath.
 */
.calculator-sidebar-col {
    display: none;
}

.ad-slot.ad-slot-sidebar {
    display: none;
}

@media (min-width: 1200px) {
    .calculator-sidebar-col {
        display: flex;
        flex-direction: column;
        width: 320px;
        flex-shrink: 0;
        gap: 20px;
        align-self: stretch;
    }

    .ad-slot.ad-slot-sidebar {
        display: flex;
        position: sticky;
        top: 85px;
    }
}

.calculator-title {
    font-size: 1.85rem;
    font-weight: 700;
    text-align: center;
    margin: 0 0 1.25rem 0;
    color: var(--text-main);
}

.calculator-container {
    padding: 0;
    width: 100%;
    box-sizing: border-box;
}

/* ============================================================================
   DIMENSION CONTROLS TOOLBAR
   ============================================================================ */

/* Desktop Layout (Comfortable, horizontal, spacious) */
.dimension-input-area {
    margin-bottom: 20px;
    padding: 14px 20px;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    box-sizing: border-box;
    width: 100%;
}

.dimension-controls-left {
    display: flex;
    align-items: center;
    gap: 14px 18px;
    flex-wrap: wrap;
}

.dim-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dim-group-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main);
    margin-right: 2px;
    white-space: nowrap;
}

.dim-group label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.dim-group input[type="number"] {
    width: 60px;
    height: 36px;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--bg-card);
    color: var(--text-main);
    box-sizing: border-box;
}

.dim-group input[type="number"]:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.25);
}

.dim-group select,
.calc-select {
    height: 36px;
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--bg-card);
    color: var(--text-main);
    cursor: pointer;
    box-sizing: border-box;
}

.dim-group select:focus,
.calc-select:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.25);
}

.dim-btn-generate {
    padding: 8px 18px;
    font-size: 0.95rem;
}

/* Quick Tools Bar */
.matrix-quick-tools {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tool-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.tool-btn:hover {
    background: var(--bg-sidebar);
    border-color: var(--link-color);
    color: var(--link-color);
}

/* Validation Message */
.dim-validation-msg {
    font-size: 0.85rem;
    color: #dc3545;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 6px 12px;
    display: none;
    text-align: center;
    margin: -10px 0 16px 0;
    width: 100%;
    box-sizing: border-box;
}

/* Tablet & Mobile Responsive Dimension Layout (<= 768px) */
@media (max-width: 768px) {
    .dimension-input-area {
        padding: 12px 14px;
        margin-bottom: 16px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .dimension-controls-left {
        flex-direction: column;
        align-items: center;
        gap: 8px;
        width: 100%;
    }

    .dim-group {
        justify-content: center;
        width: 100%;
        gap: 6px;
    }

    .dim-group input[type="number"] {
        width: 50px;
        height: 34px;
    }

    .dim-btn-generate {
        width: 100%;
        max-width: 220px;
        text-align: center;
    }

    .matrix-quick-tools {
        justify-content: center;
        width: 100%;
    }

    .matrix-quick-tools .tool-btn {
        width: 100%;
        max-width: 220px;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .dimension-input-area {
        padding: 10px 12px;
    }

    .dim-group-title {
        font-size: 0.88rem;
    }

    .dim-group label {
        font-size: 0.85rem;
    }

    .dim-group input[type="number"] {
        width: 46px;
        height: 32px;
        font-size: 0.9rem;
    }

    .calculator-title {
        font-size: 1.5rem;
    }
}

/* ============================================================================
   MATRIX INPUT GRIDS & WORKSPACE
   ============================================================================ */

.matrix-input-grids-container {
    display: flex;
    align-items: center; 
    justify-content: center;
    gap: 18px; 
    margin: 20px 0;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
}

/* Individual matrix entry box */
.matrix-entry {
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-card);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.matrix-header-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}

.matrix-header-box h4 {
    margin: 0;
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 600;
}

/* Area where the table for matrix cell inputs is rendered */
.matrix-grid-area {
    overflow-x: auto;
    max-width: 100%;
    padding-bottom: 2px;
    box-sizing: border-box;
}

.matrix-grid-area table.matrix-input-table {
    border-collapse: separate;
    border-spacing: 4px;
    margin: 0 auto; 
}

.matrix-grid-area td {
    padding: 0;
}

.matrix-grid-area input.matrix-cell {
    width: 54px; 
    height: 36px;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px;
    box-sizing: border-box; 
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--bg-card);
    color: var(--text-main);
}

.matrix-grid-area input.matrix-cell:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.matrix-grid-area input.matrix-cell.input-error {
    border-color: #dc3545;
    background-color: #f8d7da;
}

.operator-display {
    font-size: 2.2rem;
    align-self: center;
    padding: 0 12px;
    font-weight: 700;
    color: var(--text-main);
}

/* General button for calculations */
.calc-button {
    padding: 10px 24px;
    background-color: #007bff; 
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    white-space: nowrap;
}
.calc-button:hover {
    background-color: #0069d9;
}
.calc-button:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.5);
}

/* Container for displaying results */
.results-display {
    margin-top: 30px;
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-card);
    width: 100%; 
    box-sizing: border-box; 
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.results-display h3 {
    margin: 0;
    font-size: 1.35rem;
    color: var(--text-main);
}

.export-btn-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.export-btn {
    padding: 5px 12px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.export-btn:hover {
    background: var(--bg-sidebar);
    border-color: var(--link-color);
    color: var(--link-color);
}

/* The single continuous calculation block with unbroken blue left accent border */
.calc-step { 
    margin-bottom: 18px;
    padding: 18px 20px; 
    border-left: 4px solid #0d6efd;
    background-color: var(--bg-body);
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;     
    box-sizing: border-box;
    border-radius: 0 4px 4px 0;
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.calc-step .katex {
    display: block; 
    max-width: 100%;       
    box-sizing: border-box;
    margin-left: auto;  
    margin-right: auto; 
    text-align: left;
}

.calc-step .katex-display { 
    margin-top: 0.3em; 
    margin-bottom: 0.3em;
}

/* 4x4 Minor Rows inside the unified calc-step container - seamless flow without boxes */
.minor-rows-wrapper {
    margin: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.minor-row-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 6px 0;
    background: transparent;
    border: none;
    box-shadow: none;
    flex-wrap: wrap;
}

.minor-row-math {
    overflow: visible;
    display: inline-flex;
    align-items: center;
}

.minor-row-math .katex {
    display: inline-block;
    text-align: left;
    line-height: normal;
}

.minor-view-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--link-color);
    font-size: 0.84rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
}

.minor-view-btn:hover {
    background: var(--bg-sidebar);
    border-color: var(--link-color);
    color: var(--link-color);
    text-decoration: none;
}

.minor-view-btn .katex {
    display: inline-block;
    vertical-align: baseline;
}

/* Note inside the single continuous calc-step container (for >4x4) */
.calc-step-note-inside {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

/* --- MODAL DIALOG FOR MINOR DRILL-DOWN STEPS --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
    box-sizing: border-box;
}

.modal-dialog {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 100%;
    max-width: 660px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    box-sizing: border-box;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    margin: 0;
    font-size: 1.15rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 6px;
}

.modal-close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
    transition: color 0.15s;
}

.modal-close-btn:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 18px;
    overflow-y: auto;
    max-height: calc(90vh - 130px);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding: 12px 18px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-body);
    border-radius: 0 0 8px 8px;
}

.modal-footer-close {
    padding: 6px 18px;
    font-size: 0.9rem;
}

/* Error message styling */
#error_message {
    margin-top: 15px;
    padding: 10px 15px;
    border: 1px solid #f5c6cb;
    background-color: #f8d7da;
    color: #721c24;
    border-radius: 4px;
}
#error_message:empty {
    display: none;
}

/* --- REUSABLE ADVERTISING SLOTS --- */
.ad-slot {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.ad-slot.ad-slot-sidebar {
    display: none;
}

@media (min-width: 1200px) {
    .ad-slot.ad-slot-sidebar {
        display: flex;
        position: sticky;
        top: 85px;
    }
}

.ad-slot-bottom {
    margin-top: 0;
}

.ad-box-sidebar {
    width: 100%;
    max-width: 300px;
    box-sizing: border-box;
}

.ad-box-sidebar ins.adsbygoogle {
    max-width: 300px;
}

.ad-box-bottom {
    width: 100%;
    max-width: 728px;
    box-sizing: border-box;
}

.ad-box-bottom:not(:empty) {
    margin-top: 28px;
}

/* Mobile & Tablet Grids & Cell Responsive Adjustments */
@media (max-width: 768px) {
    .matrix-input-grids-container {
        flex-direction: column;
        align-items: center; 
    }
    .operator-display {
        transform: rotate(90deg); 
        padding: 10px 0 !important;
        margin: 2px 0;
    }
}

@media (max-width: 480px) {
    .matrix-grid-area input.matrix-cell {
        width: 46px;
        height: 34px;
        font-size: 0.88rem;
        padding: 2px;
    }
    .matrix-entry {
        padding: 10px 8px;
        width: 100%;
    }
}
