/* Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: #1a1a2e;
    color: #eee;
    line-height: 1.6;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px;
}

/* Header */
header {
    background: #16213e;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
}

h1 {
    font-size: 1.3rem;
    color: #6c63ff;
    margin-bottom: 10px;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-primary {
    background: #6c63ff;
    color: white;
}

.btn-primary:hover {
    background: #5a52d5;
}

.btn-secondary {
    background: #2a2a4a;
    color: #aaa;
}

.btn-secondary:hover {
    background: #3a3a5a;
}

/* Table Container */
.table-container {
    background: #16213e;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 80px;
}

/* Desktop Table Header */
.table-header {
    display: none;
    /* Hidden on mobile, shown on desktop */
    background: #0f1624;
    padding: 12px 15px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
}

/* Door List */
.door-list {
    max-height: calc(100vh - 250px);
    overflow-y: auto;
}

/* Door Item - Card Style for Mobile */
.door-item {
    background: #1e2a47;
    padding: 8px 12px;
    /* Reduced padding */
    margin: 4px 0;
    /* Minimal margin */
    border-radius: 6px;
    border-left: 3px solid #6c63ff;
    display: flex;
    /* Flex container */
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.door-item:hover {
    background: #253352;
}

/* Compact Mobile Layout */
.door-info {
    flex: 1;
    min-width: 50%;
}

.door-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.door-id {
    display: inline-block;
    background: #6c63ff;
    color: white;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 0.8rem;
    margin: 0;
}

.door-code {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
    color: #fff;
    white-space: nowrap;
}

.door-desc {
    font-size: 0.85rem;
    color: #bbb;
    margin-left: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: none;
    /* Hide description on very small screens? Or keep? */
}

/* Show description on slightly larger mobile screens */
@media (min-width: 400px) {
    .door-desc {
        display: block;
    }
}

.status-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin: 0;
}

.tag {
    padding: 2px 8px;
    /* Slightly more padding */
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    /* Bold for readability */
    color: #fff;
    /* Default white text */
}

.tag.wear {
    background: #ffd93d;
    /* Yellow */
    color: #333;
    /* Dark text for contrast */
}

.tag.key {
    background: #ff6b6b;
    /* Red */
    color: white;
}

.tag.dirty {
    background: #a29bfe;
    /* Purple */
    color: white;
}

.tag.ok {
    background: #6bcf7f;
    /* Green */
    color: white;
}

.tag.none {
    background: #555;
    color: #ccc;
}

/* Action Buttons Container - Compact Right Side */
.door-actions-container {
    display: flex;
    gap: 6px;
    align-items: center;
}

.door-actions {
    margin: 0;
    display: flex;
    gap: 0;
}

/* Icon-Only Buttons for Mobile compactness */
.btn-icon-mobile {
    background: transparent;
    border: 1px solid #444;
    color: #aaa;
    padding: 6px;
    border-radius: 4px;
    font-size: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-icon-mobile:hover {
    border-color: #6c63ff;
    color: #6c63ff;
}

.btn-primary-mobile {
    background: #6c63ff;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}


/* Footer */
.summary-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #16213e;
    border-top: 2px solid #6c63ff;
    padding: 10px;
    display: flex;
    justify-content: space-around;
    font-size: 0.75rem;
    z-index: 100;
}

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

.count {
    display: block;
    font-size: 1.2rem;
    font-weight: bold;
    color: #6c63ff;
}

.badge {
    color: #888;
    text-transform: uppercase;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #16213e;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-actions {
    margin-top: 20px;
}

.modal-actions .btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

.close-modal {
    float: right;
    font-size: 1.8rem;
    cursor: pointer;
    color: #888;
    line-height: 1;
}

.close-modal:hover {
    color: #fff;
}

h2 {
    margin-bottom: 20px;
    color: #6c63ff;
}

.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    color: #aaa;
}

.input-group input {
    width: 100%;
    padding: 10px;
    background: #1e2a47;
    border: 1px solid #333;
    border-radius: 6px;
    color: white;
    font-size: 1rem;
}

.input-group input:focus {
    outline: none;
    border-color: #6c63ff;
}

.checklist {
    margin-bottom: 20px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    padding: 12px;
    background: #1e2a47;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
}

.checkbox-container:hover {
    background: #253352;
}

.checkbox-container input {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    cursor: pointer;
}

.file-label {
    display: block;
    padding: 15px;
    background: #1e2a47;
    border: 2px dashed #6c63ff;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    color: #6c63ff;
    margin-bottom: 15px;
}

.file-label:hover {
    background: #253352;
}

input[type="file"] {
    display: none;
}

#file-name-display {
    text-align: center;
    color: #888;
    font-size: 0.85rem;
}

#preview-image {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 15px;
}

/* Desktop Styles */
@media (min-width: 769px) {
    .app-container {
        padding: 20px;
    }

    h1 {
        font-size: 1.8rem;
    }

    /* Show table header on desktop */
    .table-header {
        display: grid;
        grid-template-columns: 60px 0.8fr 2.7fr 140px 110px;
        gap: 15px;
    }

    /* Desktop grid layout */
    .door-item {
        display: grid;
        grid-template-columns: 60px 2fr 2fr 100px 100px;
        gap: 15px;
        align-items: center;
        margin: 0;
        border-radius: 0;
        border-left: none;
        border-bottom: 1px solid #0f1624;
        padding: 15px;
        background: transparent;
    }

    .door-item:hover {
        background: #253352;
    }

    /* Unwrap mobile structure for desktop grid */
    .door-info {
        display: contents;
        /* Allows children to be grid items */
    }

    .door-header {
        display: contents;
        /* ID and Location become grid items */
    }

    /* Order: ID | Location | Tags | Image | Action */

    /* We need to re-order the DOM or use Grid Area? */
    /* If we use display: contents, inner children become grid items. */
    /* Structure: [ [ID] [Location] ] [Tags] [ [Img] [Rec] ] */
    /* Children: ID, Location, Tags, ActionsContainer */
    /* Grid columns needs to match that count? No layout is: ID, Location, Tags, Actions */
    /* Wait, structure is: 
       .door-info -> [ .door-header -> [ID, Loc], Tags ]
       .door-actions-container -> [Img, Rec] 
    */
    /* display: contents on .door-info and .door-header puts ID, Loc, Tags, ActionsCont as direct children of .door-item grid. */
    /* That makes 4 items: ID, Loc, Tags, ActionsContainer. */
    /* Grid Template: 60px 2fr 2fr 200px (merged actions) */

    .door-item {
        grid-template-columns: 60px 0.8fr 2.7fr 140px 110px;
    }

    .table-header {
        grid-template-columns: 60px 0.8fr 2.7fr 140px 110px;
    }

    .door-code,
    .door-desc {
        white-space: normal;
        /* Wrap text on desktop */
        overflow: visible;
    }

    .door-id {
        margin: 0;
        text-align: center;
    }

    .door-code {
        margin: 0;
        font-size: 1rem;
    }

    .door-desc {
        display: block;
        margin: 0;
    }

    .status-tags {
        margin: 0;
    }

    .door-actions-container {
        display: flex;
        gap: 10px;
        justify-content: flex-end;
    }

    .btn-icon-mobile {
        width: auto;
        height: auto;
        padding: 8px 12px;
        border: 1px solid #444;
    }

    .btn-primary-mobile {
        width: auto;
        padding: 8px 16px;
    }

    /* Add text back to record button on desktop? */
    .btn-primary-mobile::after {
        content: " Record";
    }

    .summary-footer {
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        max-width: 1160px;
        border-radius: 8px;
        bottom: 20px;
    }
}

.tag.issue {
    background: #ff9f43;
    /* Orange */
    color: white;
}