:root {
    --bg-dark: #808080;          /* Gray MDI desktop background */
    --bg-workspace: #f0f0f0;     /* System Control background */
    --bg-card: #ffffff;          /* White spreadsheet background */
    --border-color: #aca899;     /* Light gray border shadow */
    --border-dark: #808080;      /* Dark gray shadow border */
    --text-primary: #000000;     /* Default black text */
    --text-secondary: #404040;   /* Secondary gray text */
    --win-active-title: linear-gradient(90deg, #0a246a 0%, #a6caf0 100%); /* Classic Windows MDI Title bar */
    --status-idle: #404040;
    --status-active: #d07000;
    --status-success: #008000;
    --status-error: #ef0000;
    --kidde-red: #d32f2f;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-workspace);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    font-size: 13px;
}

/* 1. Windows Titlebar */
.window-titlebar {
    background: linear-gradient(180deg, #ffffff 0%, #d4d0c8 100%);
    border-bottom: 1px solid var(--border-dark);
    padding: 6px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.title-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-icon {
    width: 16px;
    height: 16px;
}

#window-title-text {
    font-size: 12px;
    font-weight: bold;
    color: #000000;
}

.window-controls {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: #404040;
}

.win-btn {
    cursor: pointer;
    font-weight: bold;
}

.win-btn:hover {
    color: #000000;
}

.win-close:hover {
    color: var(--status-error);
}

/* 2. Dropdown Menu Bar */
.menu-bar {
    background-color: var(--bg-workspace);
    display: flex;
    font-size: 12px;
    border-bottom: 1px solid var(--border-color);
    user-select: none;
}

.menu-item {
    padding: 5px 10px;
    position: relative;
    cursor: pointer;
    color: #000000;
}

.menu-item:hover {
    background-color: #316ac5;
    color: #ffffff;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-dark);
    min-width: 250px;
    z-index: 9999;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.menu-item:hover .dropdown-menu {
    display: block;
}

.dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #000000;
    text-decoration: none;
    padding: 6px 12px;
    font-size: 12px;
}

.dropdown-menu a:hover {
    background-color: #316ac5;
    color: #ffffff;
}

.menu-icon {
    width: 16px;
    height: 16px;
}

.menu-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 3px 0;
}

/* 3. Toolbar ToolStrip */
.tool-bar {
    background-color: var(--bg-workspace);
    border-bottom: 1px solid var(--border-dark);
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.tool-btn {
    background: transparent;
    border: 1px solid transparent;
    padding: 3px 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    color: #000000;
    cursor: pointer;
}

.tool-btn img {
    width: 16px;
    height: 16px;
}

.tool-btn span {
    font-size: 12px;
}

.tool-btn:hover:not(.disabled) {
    background-color: #ffffff;
    border: 1px solid #316ac5;
}

.tool-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tool-separator {
    width: 1px;
    height: 18px;
    background-color: var(--border-color);
    margin: 0 4px;
}

.calc-pulse-icon {
    font-size: 13px;
    animation: rotate-cog 3s linear infinite;
    display: inline-block;
}

@keyframes rotate-cog {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 4. MDI Workspace */
.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    background-color: var(--bg-dark); /* Classic Dark Gray MDI workspace container */
    position: relative;
}

/* Left Sidebar Panel */
.sidebar {
    width: 250px;
    background-color: var(--bg-workspace);
    border-right: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 12px;
    overflow-y: auto;
    z-index: 10;
}

.sidebar-header {
    font-size: 13px;
    font-weight: bold;
    color: #000000;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.prop-group {
    margin-bottom: 10px;
}

.prop-group label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 2px;
    font-weight: bold;
}

.prop-group input {
    width: 100%;
    padding: 4px 6px;
    font-size: 12px;
    background-color: #ffffff;
    color: #000000;
    border: 1px solid var(--border-color);
    outline: none;
}

.status-badge {
    display: inline-block;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: bold;
    color: #ffffff;
    border-radius: 2px;
}

.status-idle { background-color: var(--status-idle); }
.status-active { background-color: var(--status-active); }
.status-success { background-color: var(--status-success); }
.status-error { background-color: var(--status-error); }

.logo-container {
    margin-top: 20px;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
    text-align: center;
}

.kidde-logo-glow {
    font-size: 13px;
    font-weight: bold;
    color: var(--kidde-red);
}

.branding-sub {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Main MDI Window Area */
.main-content {
    flex: 1;
    position: relative;
    overflow: auto;
    padding: 20px;
}

/* Upload Container */
.upload-container {
    background-color: var(--bg-workspace);
    border: 2px dashed var(--border-dark);
    padding: 40px;
    max-width: 500px;
    margin: 40px auto;
    text-align: center;
    border-radius: 4px;
}

.upload-box h2 {
    font-size: 16px;
    margin: 10px 0;
    color: #000000;
}

.upload-box p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.upload-btn {
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-dark);
    color: #000000;
    padding: 6px 16px;
    font-size: 12px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 1px 1px 0px #ffffff inset;
}

.upload-btn:hover {
    background-color: #ffffff;
}

/* Spinner Loader */
.loader-container {
    text-align: center;
    margin: 80px auto;
    color: #ffffff;
}

.spinner {
    width: 40px;
    height: 40px;
    position: relative;
    margin: 0 auto 20px;
}

.double-bounce1, .double-bounce2 {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #ffffff;
    opacity: 0.6;
    position: absolute;
    top: 0;
    left: 0;
    animation: sk-bounce 2.0s infinite ease-in-out;
}

.double-bounce2 {
    animation-delay: -1.0s;
}

@keyframes sk-bounce {
    0%, 100% { transform: scale(0.0); }
    50% { transform: scale(1.0); }
}

/* 5. Results MDI Sub-Windows layout */
.results-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-dark);
}

.tab-headers {
    background-color: var(--bg-workspace);
    display: flex;
    border-bottom: 1px solid var(--border-dark);
    padding: 3px 6px 0;
    gap: 2px;
}

.tab-btn {
    background-color: #e0e0e0;
    border: 1px solid var(--border-color);
    border-bottom: none;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
}

.tab-btn:hover {
    background-color: #ffffff;
}

.tab-btn.active {
    background-color: #ffffff;
    font-weight: bold;
    border-color: var(--border-dark);
    margin-bottom: -1px;
    padding-bottom: 6px;
    z-index: 5;
}

.tab-pane {
    display: none;
    flex: 1;
    padding: 10px;
    background-color: #ffffff;
    overflow-y: auto;
}

.tab-pane.active {
    display: flex;
    flex-direction: column;
}

/* Spreadsheet Grid Tables */
.table-container {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th {
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-color);
    padding: 5px 8px;
    font-weight: bold;
    text-align: left;
    position: sticky;
    top: 0;
}

td {
    border: 1px solid #e0e0e0;
    padding: 5px 8px;
    color: #000000;
}

tr:nth-child(even) {
    background-color: #f9f9f9;
}

.highlight-column {
    background-color: #f1f8ff;
    font-weight: 500;
}

/* Warning Alerts */
.alerts-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alert-item {
    padding: 8px 12px;
    border: 1px solid #d4d0c8;
    border-radius: 2px;
    font-size: 12px;
}

.alert-err {
    background-color: #ffebee;
    border-color: #ffcdd2;
    color: #c62828;
}

.alert-sys {
    background-color: #e8f5e9;
    border-color: #c8e6c9;
    color: #2e7d32;
}

/* MDI Window Panels (for dialog popups) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.modal-window {
    background-color: var(--bg-workspace);
    border: 3px solid var(--bg-workspace);
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
    width: 720px;
    max-width: 95%;
    display: flex;
    flex-direction: column;
}

.modal-header {
    background: linear-gradient(90deg, #0a246a 0%, #a6caf0 100%); /* Classic Windows MDI Title bar */
    padding: 4px 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #ffffff;
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: bold;
    font-size: 12px;
}

.modal-title-icon {
    width: 16px;
    height: 16px;
}

.modal-close-btn {
    background: #e0e0e0;
    border: 1px solid #808080;
    color: #000000;
    width: 18px;
    height: 18px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
}

.modal-close-btn:hover {
    background-color: #ff4d4d;
    color: #ffffff;
}

.modal-body {
    padding: 12px;
    background-color: var(--bg-workspace);
}

.modal-row {
    margin-bottom: 10px;
}

.modal-row label {
    font-weight: bold;
    font-size: 12px;
    margin-right: 10px;
}

.premium-select {
    padding: 3px;
    font-size: 12px;
    background-color: #ffffff;
    border: 1px solid var(--border-color);
}

.radio-group {
    display: inline-flex;
    gap: 15px;
}

.premium-radio {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-dark);
    margin-bottom: 10px;
    gap: 2px;
}

.modal-tab-btn {
    background-color: #e0e0e0;
    border: 1px solid var(--border-color);
    border-bottom: none;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}

.modal-tab-btn.active {
    background-color: #ffffff;
    font-weight: bold;
    border-color: var(--border-dark);
    border-bottom: 1px solid #ffffff;
    margin-bottom: -1px;
}

.modal-tab-pane {
    display: none;
    background-color: #ffffff;
    border: 1px solid var(--border-dark);
    padding: 6px;
}

.modal-tab-pane.active {
    display: block;
}

.modal-table-container {
    height: 180px;
    overflow-y: auto;
    background-color: #ffffff;
}

.modal-grid-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.modal-grid-table th {
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-color);
    padding: 4px;
    font-weight: bold;
}

.modal-grid-table td {
    border: 1px solid #e0e0e0;
    padding: 4px;
}

.modal-recommendation {
    margin-top: 10px;
    color: #ff0000;
    font-weight: bold;
    font-size: 12px;
}

.modal-footer {
    padding: 8px 12px;
    background-color: var(--bg-workspace);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
}

.modal-footer-btn {
    background-color: var(--bg-workspace);
    border: 1px solid var(--border-dark);
    color: #000000;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 1px 1px 0px #ffffff inset;
}

.modal-footer-btn:hover {
    background-color: #ffffff;
}

.modal-footer-right {
    display: flex;
    gap: 6px;
}

/* Log viewers */
.log-viewer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.log-viewer pre {
    background-color: #ffffff;
    color: #000000;
    border: 1px solid var(--border-color);
    padding: 8px;
    font-family: 'Consolas', monospace;
    font-size: 11px;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

/* 7. Bottom Status Bar */
.status-bar {
    background-color: var(--bg-workspace);
    border-top: 1px solid var(--border-dark);
    padding: 4px 10px;
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #000000;
    user-select: none;
}

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-separator {
    color: var(--border-color);
}

/* Grid Editor Cells */
.grid-cell {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    padding: 3px 6px;
    outline: none;
}

.grid-cell:focus {
    background-color: #ffffff;
    color: #000000;
    box-shadow: 0 0 2px #316ac5;
}

#grid-segments-table td {
    padding: 0;
    height: 24px;
}

#grid-segments-table input[type="checkbox"] {
    cursor: pointer;
    vertical-align: middle;
}

/* Enclosure list box item styling */
#enclosure-list-box div:hover {
    background-color: #316ac5;
    color: #ffffff !important;
}

/* Grid Editor Cells */
.grid-cell {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    padding: 3px 6px;
    outline: none;
}

.grid-cell:focus {
    background-color: #ffffff;
    color: #000000;
    box-shadow: 0 0 2px #316ac5;
}

#grid-segments-table td {
    padding: 0;
    height: 24px;
}

#grid-segments-table input[type="checkbox"] {
    cursor: pointer;
    vertical-align: middle;
}

/* Enclosure list box item styling */
#enclosure-list-box div:hover {
    background-color: #316ac5;
    color: #ffffff !important;
}

/* Split-Screen Mode Layout */
body.split-active .workspace {
    display: flex;
    flex-direction: row;
}

body.split-active .sidebar {
    width: 240px;
}

body.split-active .main-content {
    display: flex;
    gap: 15px;
    padding: 10px;
    overflow: hidden;
}

body.split-active #piping-network-modal {
    position: static;
    display: flex !important;
    flex: 1;
    height: 100%;
    z-index: 1;
    background-color: transparent;
}

body.split-active #piping-network-modal .modal-window {
    width: 100% !important;
    height: 100%;
    box-shadow: none;
}

body.split-active #results-view {
    flex: 1;
    height: 100%;
}

/* Reference Table Grid Styles */
#ref-table-grid th {
    background-color: #e0e0e0;
    color: #000000;
    border: 1px solid var(--border-color);
    padding: 6px;
    font-weight: bold;
    text-align: left;
}

#ref-table-grid td {
    padding: 5px;
    border: 1px solid var(--border-color);
}

/* Multi-window MDI layouts for results-container */
.results-container.tile-vertical {
    display: flex !important;
    flex-direction: row !important;
    gap: 12px;
    height: 100%;
    overflow-x: auto;
    padding: 10px;
    background-color: var(--bg-dark);
}
.results-container.tile-vertical .tab-headers {
    display: none !important;
}
.results-container.tile-vertical .tab-pane {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-width: 280px;
    height: 100%;
    border: 3px double var(--border-color);
    background: var(--bg-workspace);
    padding: 10px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    overflow: auto;
}

.results-container.tile-horizontal {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px;
    height: 100%;
    overflow-y: auto;
    padding: 10px;
    background-color: var(--bg-dark);
}
.results-container.tile-horizontal .tab-headers {
    display: none !important;
}
.results-container.tile-horizontal .tab-pane {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 200px;
    border: 3px double var(--border-color);
    background: var(--bg-workspace);
    padding: 10px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    overflow: auto;
}

.results-container.cascade {
    position: relative !important;
    height: 100%;
    background-color: var(--bg-dark);
    padding: 10px;
    overflow: hidden;
}
.results-container.cascade .tab-headers {
    display: none !important;
}
.results-container.cascade .tab-pane {
    display: flex !important;
    flex-direction: column;
    position: absolute !important;
    width: 65%;
    height: 75%;
    border: 3px double var(--border-color);
    background: var(--bg-workspace);
    box-shadow: 6px 6px 12px rgba(0,0,0,0.5);
    padding: 10px;
    overflow: auto;
    cursor: default;
}

