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

:root {
    --primary-color: #3498db;
    --primary-dark: #2980b9;
    --secondary-color: #2ecc71;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --dark-color: #2c3e50;
    --light-color: #ecf0f1;
    --gray-color: #95a5a6;
    --sidebar-width: 320px;
    --right-panel-width: 200px;
    --navbar-height: 60px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f6fa;
    color: #333;
    line-height: 1.6;
}

/* Navbar */
.navbar {
    background: linear-gradient(135deg, var(--dark-color), #34495e);
    color: white;
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: bold;
}

.nav-brand i {
    color: var(--primary-color);
}

.nav-links {
    display: flex;
    gap: 5px;
}

.nav-links a {
    color: white;
    text-decoration: none;
    padding: 10px 15px;
    border-radius: 5px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-links a:hover,
.nav-links a.active {
    background-color: rgba(255,255,255,0.1);
}

.nav-toggle {
    display: none;
    font-size: 1.5rem;
    cursor: pointer;
}

/* Main Container */
.main-container {
    display: flex;
    margin-top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid #ddd;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 15px 20px;
    background: var(--light-color);
    border-bottom: 1px solid #ddd;
}

.sidebar-header h3 {
    font-size: 1rem;
    color: var(--dark-color);
}

/* Collapsible Sections */
.collapsible-section {
    border-bottom: 1px solid #eee;
}

.collapsible {
    background-color: white;
    color: var(--dark-color);
    cursor: pointer;
    padding: 15px 20px;
    width: 100%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background-color 0.3s;
}

.collapsible:hover {
    background-color: #f8f9fa;
}

.collapsible.active {
    background-color: #e8f4fc;
    border-left: 3px solid var(--primary-color);
}

.collapsible i {
    width: 20px;
    color: var(--primary-color);
}

.content {
    display: none;
    padding: 15px 20px;
    background-color: white;
}

.content.show {
    display: block;
}

/* Form Groups */
.form-group {
    margin-bottom: 15px;
}

/* Inline label + input on the same line (Shape bay fields) */
.form-group.form-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group.form-row label {
    flex: 0 0 47%;
    margin-bottom: 0;
    font-size: 0.82rem;
}

.form-group.form-row input,
.form-group.form-row select {
    flex: 1;
    min-width: 0;
}

/* Bay zones in Building Shape (Span = blue, Length = green) */
.bay-zone {
    border-radius: 8px;
    padding: 12px 12px 2px;
    margin-bottom: 12px;
    border: 1px solid;
}

.bay-zone-span {
    background: #eaf2f8;
    border-color: #bcd9ea;
}

.bay-zone-length {
    background: #eafaf1;
    border-color: #bfe6cf;
}

.bay-zone-title {
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 2px solid;
}

.bay-zone-span .bay-zone-title {
    color: #1a5276;
    border-color: #1a5276;
}

.bay-zone-length .bay-zone-title {
    color: #1e8449;
    border-color: #1e8449;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.85rem;
    color: #666;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 0.9rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Province info (read-only display) */
.province-info {
    display: flex;
    gap: 10px;
    margin: -5px 0 15px;
    padding: 10px;
    background: #eef6ff;
    border: 1px solid #cfe3f7;
    border-radius: 6px;
}

.province-info-item {
    flex: 1;
    text-align: center;
}

.province-info-item .label {
    display: block;
    font-size: 0.72rem;
    color: #666;
    margin-bottom: 3px;
}

.province-info-item .value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-success {
    background-color: var(--secondary-color);
    color: white;
}

.btn-success:hover {
    background-color: #27ae60;
}

.btn-secondary {
    background-color: var(--gray-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-block {
    width: 100%;
    margin-bottom: 10px;
    justify-content: center;
}

.button-group {
    padding: 15px 20px;
    display: flex;
    gap: 10px;
}

.button-group .btn {
    flex: 1;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-container {
    flex: 1;
    background: white;
    border-bottom: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

.canvas-header {
    padding: 10px 20px;
    background: var(--light-color);
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.canvas-header h2 {
    font-size: 1rem;
    color: var(--dark-color);
}

.view-controls {
    display: flex;
    gap: 5px;
}

.view-group {
    margin-left: 10px;
    padding-left: 10px;
    border-left: 1px solid #ddd;
}

.btn-view {
    width: 35px;
    height: 35px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.btn-view:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-view.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-view img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    display: block;
}

#threeContainer {
    flex: 1;
    position: relative;
}

#viewLabel {
    position: absolute;
    top: 10px;
    right: 12px;
    background: rgba(26, 82, 118, 0.88);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 3px 12px;
    border-radius: 12px;
    pointer-events: none;
    z-index: 5;
}

/* Results Panel */
.results-panel {
    height: 300px;
    background: white;
    border-top: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

.results-header {
    padding: 10px 20px;
    background: var(--light-color);
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.results-header h2 {
    font-size: 1rem;
    color: var(--dark-color);
}

.results-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray-color);
}

.placeholder i {
    margin-bottom: 15px;
}

/* Right Panel */
.right-panel {
    width: var(--right-panel-width);
    background: white;
    border-left: 1px solid #ddd;
    padding: 15px;
    overflow-y: auto;
}

.panel-section {
    margin-bottom: 20px;
}

.panel-section h3 {
    font-size: 0.9rem;
    color: var(--dark-color);
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.info-item .label {
    color: #666;
}

.info-item .value {
    font-weight: 600;
    color: var(--primary-color);
}

/* Report Modal */
.report-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.report-modal.show {
    display: flex;
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px;
    background: var(--dark-color);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Report modal: definite height so flex body + iframe fill correctly */
#reportModal .modal-content {
    height: 90vh;
}

/* Report iframe container */
#reportContent {
    padding: 0;
    overflow: hidden;
}

.modal-footer {
    padding: 15px 20px;
    background: var(--light-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    z-index: 3000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-overlay.show {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Report Styles */
.report-section {
    margin-bottom: 30px;
}

.report-section h3 {
    font-size: 1.1rem;
    color: var(--dark-color);
    margin-bottom: 15px;
    padding-bottom: 5px;
    border-bottom: 2px solid var(--primary-color);
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
}

.report-table th,
.report-table td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

.report-table th {
    background: var(--light-color);
    font-weight: 600;
}

.report-table tr:hover {
    background: #f8f9fa;
}

/* Horizontal scroll wrapper for wide tables (e.g. pnet zone table) */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 15px;
}

.pnet-table {
    width: auto;
    min-width: 720px;
    white-space: nowrap;
}

.pnet-table th,
.pnet-table td {
    text-align: center;
}

.pnet-table td:first-child {
    text-align: left;
    font-weight: 600;
    min-width: 170px;
}

.pnet-table td:last-child {
    text-align: left;
    font-weight: 400;
}

.formula-title {
    font-family: 'Courier New', monospace;
    background: #f4f6f7;
    padding: 8px 12px;
    border-left: 3px solid var(--primary-color);
    margin: 10px 0;
    font-size: 0.9em;
}

.lead-line {
    font-size: 0.95rem;
    margin: 8px 0;
    color: #333;
}

.formula-box {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    margin: 10px 0;
    font-family: 'Courier New', monospace;
    border-left: 3px solid var(--primary-color);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .right-panel {
        width: 180px;
    }
}

@media (max-width: 992px) {
    .nav-links {
        display: none;
        position: absolute;
        top: var(--navbar-height);
        left: 0;
        right: 0;
        background: var(--dark-color);
        flex-direction: column;
        padding: 10px;
    }

    .nav-links.show {
        display: flex;
    }

    .nav-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: var(--navbar-height);
        left: -320px;
        height: calc(100vh - var(--navbar-height));
        z-index: 999;
        transition: left 0.3s;
    }

    .sidebar.show {
        left: 0;
    }

    .right-panel {
        display: none;
    }

    .main-content {
        margin-left: 0;
    }
}

@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 50vh;
        position: relative;
        top: 0;
    }

    .canvas-container {
        min-height: 300px;
    }

    .results-panel {
        height: auto;
        min-height: 200px;
    }

    .button-group {
        flex-direction: column;
    }

    .modal-content {
        width: 95%;
        height: 95vh;
    }
}

/* Database Modal */
.db-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.db-modal.show {
    display: flex;
}

.db-modal-content {
    width: 95%;
    max-width: 900px;
}

.db-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.db-stat-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.db-stat-item h4 {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 8px;
}

.db-stat-item span {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.status-badge {
    font-size: 0.9rem !important;
    padding: 5px 12px;
    border-radius: 15px;
}

.status-ok {
    background: var(--secondary-color);
    color: white !important;
}

.status-error {
    background: var(--danger-color);
    color: white !important;
}

.db-table-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.db-table {
    margin-bottom: 0;
}

.db-table th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.db-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
    margin: 0 2px;
}

.text-center {
    text-align: center;
}

/* Print Styles */
@media print {    .navbar,
    .sidebar,
    .right-panel,
    .button-group,
    .view-controls {
        display: none !important;
    }

    .main-container {
        margin-top: 0;
    }

    .main-content {
        width: 100%;
    }

    .canvas-container {
        display: none;
    }

    .results-panel {
        height: auto;
    }
}