/* Base styles and variables */
:root {
    --primary-color: #004E98;
    --secondary-color: #FF6B35;
    --background-color: #F8F9FA;
    --text-color: #2D3748;
    --border-color: #E2E8F0;
    --error-color: #DC2626;
    --success-color: #059669;
    --hover-color: #EDF2F7;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--background-color);
    position: relative;
    min-width: 320px;
    max-width: 100vw;
}

/* View Container */
.view-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Login View Styles */
.login-box {
    max-width: 400px;
    width: 90%;
    margin: auto;
    padding: 2rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

.login-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.875rem;
}

/* Button Styles */
.primary-button {
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.2s ease;
}

.primary-button:hover {
    background-color: #003d77;
}

.secondary-button {
    background-color: transparent;
    color: var(--primary-color);
    padding: 0.5rem 1rem;
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    font-size: 0.95rem;
}

.secondary-button:hover {
    background-color: var(--hover-color);
}

/* Content Layout Styles */
.content-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* Top Bar Layout */
.top-bar {
    background: white;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1500;
    height: 60px;
    width: 100%;
    max-width: 100vw;
}

.top-bar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    position: relative;
}

.app-title {
    font-size: 1.25rem;
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 1rem;
}

.user-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 40px;
}

.main-content {
    display: flex;
    gap: 1.5rem;
    margin-top: 80px;
    padding: 1rem;
    width: 100%;
    position: relative;
		align-items: flex-start;
}

/* Navigation Container Styles */
.navigation-container {
    width: 35%;
    min-width: 400px;
    max-width: 600px;
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    position: sticky;
    top: 80px;
}

.breadcrumbs {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.breadcrumb-item {
    color: var(--primary-color);
    cursor: pointer;
}

.hierarchy-navigation {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.5rem;
}

/* Navigation Items */
.nav-item {
    position: relative;
    padding: 0.75rem 1rem 0.75rem 2rem;
    margin-left: 0.5rem;
    border-left: 2px solid var(--border-color);
    font-size: 0.95rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.nav-item:hover {
    background-color: var(--hover-color);
    border-left-color: var(--primary-color);
}

.nav-item-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.nav-item-name {
    font-weight: 500;
}

.count-info {
    font-size: 0.8em;
    color: #666;
    margin-left: 8px;
}

.nav-parent {
    padding: 0.75rem;
    margin-bottom: 1rem;
    background-color: #FFE4D6;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.nav-parent:hover {
    background-color: #FFD6C2;
}

.nav-parent-icon {
    margin-right: 0.5rem;
}

/* Content Display Styles */
.content-display {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    min-height: calc(100vh - 96px);
    margin-top: 0;
}

/* Equipment Content Layout */
.equipment-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
    font-size: 0.9rem;
    margin-bottom: 2rem;
		align-items: start;
}

.content-section {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    height: 100%;
		display: flex;
		flex-direction: column;
}

.section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.section h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

/* Maintenance Buttons */
.maintenance-buttons {
    display: flex;
    gap: 1rem;
    margin: 1.5rem 0;
    flex-wrap: wrap;
    justify-content: center;
}

.maintenance-buttons button {
    flex: 1;
    min-width: 200px;
    max-width: 300px;
    padding: 0.75rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    text-align: center;
    transition: background-color 0.2s ease;
    min-height: 44px;
}

.maintenance-buttons button:hover {
    background-color: var(--secondary-color);
}

/* Equipment Details */
.equipment-details h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

.subunit-header, .failure-mode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background-color: var(--hover-color);
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 0.5rem;
    min-height: 44px;
}

.toggle-icon {
    font-size: 0.8rem;
    color: var(--primary-color);
}

.maintainable-items, .actions-list {
    padding: 1rem;
    margin-left: 1rem;
    border-left: 2px solid var(--border-color);
}

/* Maintenance Sections */
.maintenance-section {
    background: var(--background-color);
    border-radius: 4px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.pm-task, .hazard, .issue, .scenario {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

/* Navigation Toggle Button */
.nav-toggle {
    display: none;
    position: fixed;
    top: 10px;
    right: calc(80px + 1.5rem);
    z-index: 1600;
    background: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    align-items: center;
    justify-content: center;
}

/* Loading and Error States */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2100;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 1rem;
    color: var(--primary-color);
}

.error-message {
    color: var(--error-color);
    background-color: #FEE2E2;
    padding: 0.75rem;
    border-radius: 4px;
    margin: 1rem 0;
    text-align: center;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    text-align: right;
}

.close-button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile Responsive Styles */
@media screen and (max-width: 768px) {
    .top-bar {
        height: 50px;
        padding: 0;
        position: fixed;
        width: 100%;
        left: 0;
        right: 0;
    }

    .top-bar-content {
        display: flex;
        align-items: center;
        height: 100%;
        padding: 0 100px 0 16px;
        position: relative;
        width: 100%;
    }

    .app-title {
        font-size: 1.1rem;
        position: absolute;
        left: 16px;
        padding: 0;
        margin: 0;
        max-width: calc(100% - 140px);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-controls {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        display: flex;
        align-items: center;
        z-index: 1510;
    }

    .nav-toggle {
        position: fixed;
        top: 7px;
        right: 120px;
        width: auto;
        min-width: 44px;
        height: 36px;
        z-index: 2000;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        background: var(--primary-color);
        border-radius: 4px;
        border: none;
        padding: 0 12px;
        margin: 0;
    }

    .nav-toggle span {
        display: inline;
        font-size: 0.9rem;
        text-align: center;
        margin: 0;
    }

    .navigation-container {
        position: fixed;
        top: 50px;
        right: 0;
        bottom: 0;
        width: 85%;
        max-width: 300px;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        background: white;
        z-index: 1900;
        padding: 16px;
        padding-top: 24px;
        overflow-y: auto;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
        -webkit-overflow-scrolling: touch;
    }

    .navigation-container.active {
        transform: translateX(0);
    }

    /* When nav is open, ensure menu button shows "Close" */
    .nav-open .nav-toggle {
        background-color: var(--secondary-color);
    }

    .content-display {
        width: 100%;
        padding: 1rem;
        margin-top: 60px;
    }

    .content-display.active {
        display: block;
    }

    .main-content {
        margin-top: 50px;
        padding: 16px;
        height: calc(100% - 50px);
        overflow-y: auto;
        width: 100%;
        max-width: 100%;
    }

    .equipment-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 0.5rem;
    }

    .content-section {
        margin-bottom: 1.5rem;
    }

    .maintenance-buttons {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.5rem;
    }

    .maintenance-buttons button {
        width: 100%;
        max-width: none;
        min-height: 44px;
    }
    
    .secondary-button {
        height: 36px;
        padding: 0 12px;
        font-size: 0.9rem;
        margin: 0;
        white-space: nowrap;
    }

    .navigation-container .nav-item {
        font-size: 1.1rem;
        padding: 1rem;
        margin-left: 0.5rem;
    }

    .navigation-container .breadcrumbs {
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
        margin: 1rem;
    }

    body.nav-open {
        overflow: hidden;
    }

    .equipment-details h2 {
        font-size: 1.3rem;
    }

    .content-section h3 {
        font-size: 1.1rem;
    }

    .view-container {
        height: 100%;
        width: 100%;
        max-width: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Utility Classes */
.text-sm {
    font-size: 0.875rem;
}

/* Tree view enhancements */
.nav-item::before {
    content: "";
    position: absolute;
    left: -2px;
    top: 50%;
    width: 1.5rem;
    height: 2px;
    background: var(--border-color);
}

.nav-item:hover::before {
    background: var(--primary-color);
}

/* Indentation levels for hierarchy */
.nav-level-1 { margin-left: 0.75rem; }
.nav-level-2 { margin-left: 1.5rem; }
.nav-level-3 { margin-left: 2.25rem; }
.nav-level-4 { margin-left: 3rem; }

/* Desktop optimization */
@media (min-width: 1024px) {
    .maintenance-buttons button {
        max-width: 250px;
    }

    .content-section {
        min-height: 400px;
    }

    .equipment-content {
        min-height: 500px;
    }

    .navigation-container {
        display: block !important;
        transform: none !important;
    }
}

/* No JavaScript Warning */
.noscript-warning {
    background: var(--error-color);
    color: white;
    text-align: center;
    padding: 1rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
}

/* Extra small screen adjustments */
@media screen and (max-width: 380px) {
    .app-title {
        max-width: calc(100% - 130px);
        font-size: 1rem;
    }

    .nav-toggle {
        right: 110px;
        width: 32px;
        height: 32px;
    }

    .top-bar-content {
        padding: 0 90px 0 12px;
    }

    .secondary-button {
        padding: 0 8px;
        font-size: 0.85rem;
    }

    .user-controls {
        right: 4px;
    }
}