*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #0f172a;
    color: #e5e7eb;
}

a {
    color: inherit;
    text-decoration: none;
}

body {
    min-height: 100vh;
}

/* Topbar */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(90deg, #111827, #1f2937);
    border-bottom: 1px solid rgba(148, 163, 184, 0.3);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar h1 {
    margin: 0;
    font-size: 1.4rem;
}

.subtitle {
    margin: 0.15rem 0 0;
    font-size: 0.9rem;
    color: #9ca3af;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-pill {
    padding: 0.3rem 0.6rem;
    background: rgba(31, 41, 55, 0.9);
    border-radius: 999px;
    font-size: 0.85rem;
}

/* Layout */

.container {
    padding: 1rem;
    max-width: 1100px;
    margin: 0 auto;
}

.card {
    background: rgba(15, 23, 42, 0.95);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(148, 163, 184, 0.35);
}

.card h2 {
    margin-top: 0;
}

/* Auth */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #1f2937, #020617);
}

.auth-card {
    width: 100%;
    max-width: 360px;
    padding: 1.75rem 1.5rem;
    background: rgba(15, 23, 42, 0.95);
    border-radius: 0.9rem;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.4);
}

.auth-card h1 {
    margin: 0 0 0.2rem 0;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    background: #4b5563;
    color: #f9fafb;
    text-decoration: none;
    transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.5);
}

.btn-primary {
    background: #2563eb;
}

.btn-success {
    background: #16a34a;
}

.btn-danger {
    background: #dc2626;
}

.btn-ghost {
    background: transparent;
    border: 1px solid rgba(148, 163, 184, 0.7);
}

.btn-small {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

/* Inline form (for delete button in header) */

.inline-form {
    display: inline;
    margin: 0;
}

/* Forms */

.form {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
}

.field span {
    color: #e5e7eb;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"],
textarea {
    border-radius: 0.55rem;
    border: 1px solid rgba(148, 163, 184, 0.7);
    background: rgba(15, 23, 42, 0.9);
    padding: 0.45rem 0.6rem;
    color: #e5e7eb;
    font-size: 0.9rem;
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

/* Alerts */

.alert {
    padding: 0.5rem 0.75rem;
    border-radius: 0.6rem;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.7);
    color: #fecaca;
}

.alert-success {
    background: rgba(16, 185, 129, 0.18);
    border: 1px solid rgba(16, 185, 129, 0.7);
    color: #bbf7d0;
}

/* Toolbar & search */

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.search-form {
    display: flex;
    gap: 0.5rem;
    flex: 1;
}

.search-input {
    flex: 1;
}

.table-wrapper {
    overflow-x: auto;
}

/* Table */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table th,
.data-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid rgba(55, 65, 81, 0.7);
    text-align: left;
}

/* Disable sticky table header so it doesn't hide the first row */
.data-table th {
    background: rgba(17, 24, 39, 0.9);
}

.col-description {
    max-width: 260px;
}

/* Status pills */

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
}

.status-good {
    background: rgba(22, 163, 74, 0.2);
    border: 1px solid rgba(22, 163, 74, 0.8);
    color: #bbf7d0;
}

.status-damaged {
    background: rgba(220, 38, 38, 0.18);
    border: 1px solid rgba(220, 38, 38, 0.9);
    color: #fecaca;
}

/* Form grid */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.8rem;
}

.radio-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
}

.help-text {
    font-size: 0.78rem;
    color: #9ca3af;
}

/* Details */

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.75rem;
    margin: 0 0 0.75rem 0;
}

.details-grid dt {
    font-size: 0.78rem;
    color: #9ca3af;
}

.details-grid dd {
    margin: 0;
}

/* Photos */

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
}

.photo-item {
    background: rgba(15, 23, 42, 0.9);
    border-radius: 0.6rem;
    padding: 0.4rem;
    border: 1px solid rgba(55, 65, 81, 0.9);
}

.photo-item img {
    display: block;
    max-width: 100%;
    height: auto;
    max-height: 140px;
    object-fit: contain;
    border-radius: 0.4rem;
    margin: 0 auto;
}
.photo-item figcaption {
    margin-top: 0.3rem;
    font-size: 0.75rem;
    color: #9ca3af;
}

/* Responsive */

@media (max-width: 640px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form {
        width: 100%;
    }
}

/* Lightbox modal for photo viewing */

.lightbox-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.lightbox {
    position: relative;
    width: min(96vw, 1200px);
    height: min(96vh, 900px);
    background: #020617;
    border-radius: 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.6);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}


.lightbox-image-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 0.5rem;
    background: #020617;
}

.lightbox-image-wrap img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.08s ease-out;
}

.lightbox-caption {
    font-size: 0.8rem;
    color: #e5e7eb;
    text-align: center;
    margin-top: 0.15rem;
}

.lightbox-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.lightbox-controls-left,
.lightbox-controls-right {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

/* Reuse .btn styles but slightly smaller for toolbar buttons */
.lightbox-btn {
    padding: 0.25rem 0.55rem;
    font-size: 0.78rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    background: rgba(15, 23, 42, 0.95);
    cursor: pointer;
    color: #e5e7eb;
}

.lightbox-btn:hover {
    background: rgba(30, 64, 175, 0.8);
}

/* Row highlight in table */

#receivings-table tr.row-active {
    background: rgba(37, 99, 235, 0.18);
}

/* Cursor for panning in lightbox */
.lightbox-image-wrap {
    cursor: grab;
}

.lightbox-image-wrap.dragging {
    cursor: grabbing;
}

/* Camera capture block */

.camera-block {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.camera-area {
    border-radius: 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.6);
    padding: 0.5rem;
    background: rgba(15, 23, 42, 0.95);
}

.camera-preview-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    max-height: 260px;
    overflow: hidden;
    border-radius: 0.5rem;
    background: #020617;
    margin-bottom: 0.4rem;
}

.camera-video,
.camera-canvas {
    max-width: 100%;
    max-height: 260px;
}

.camera-controls {
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.camera-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.camera-thumbs img {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: 0.4rem;
    border: 1px solid rgba(55, 65, 81, 0.9);
}


/* Combined photo upload / camera controls */
.photo-input-combined {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.35rem;
}

/* Hide raw file input; triggered via 'Upload from device' button */
.field input[type="file"][name="photos[]"] {
    display: none;
}


.photo-item .photo-delete-form {
    margin-top: 0.35rem;
}

.photo-item .photo-delete-form .btn-small {
    padding-inline: 0.55rem;
}

.status-missing {
    background: rgba(234, 179, 8, 0.20);
    border: 1px solid rgba(234, 179, 8, 0.90);
    color: #fef9c3;
}


th a.sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    gap: 0.15rem;
    align-items: center;
}

th a.sort-link:hover {
    text-decoration: underline;
}


.badge-completed {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: rgba(22, 163, 74, 0.20);
    border: 1px solid rgba(22, 163, 74, 0.9);
    color: #bbf7d0;
}

.badge-not-completed {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: rgba(148, 163, 184, 0.2);
    border: 1px solid rgba(148, 163, 184, 0.8);
    color: #e5e7eb;
}


.data-table tbody tr.row-completed {
    opacity: 0.6;
}

.data-table tbody tr.row-completed td {
    color: #9ca3af;
}

.data-table tbody tr.row-completed a.btn {
    opacity: 0.9;
}


.col-complete-toggle {
    width: 2.25rem;
    text-align: center;
}

.col-complete-toggle input[type="checkbox"] {
    transform: scale(1.1);
    cursor: pointer;
}


.status-incorrect {
    background: rgba(59, 130, 246, 0.20);
    border: 1px solid rgba(59, 130, 246, 0.90);
    color: #dbeafe;
}


/* PDF attachment thumbnail */
.photo-item-pdf .pdf-thumb {
    width: 100%;
    height: 140px;
    border-radius: 0.75rem;
    border: 1px solid rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    background: repeating-linear-gradient(
        -45deg,
        #f5f5f5,
        #f5f5f5 6px,
        #e5e5e5 6px,
        #e5e5e5 12px
    );
}

.photo-item-pdf .pdf-icon {
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    border: 1px solid rgba(0,0,0,0.15);
    background: #ffffff;
}



.lightbox-image-wrap iframe.lightbox-pdf {
    width: 100%;
    height: 100%;
    border: none;
    background: #020617;
}



.lightbox-image-wrap {
    position: relative;
    height: 90vh;
    max-height: 90vh;
}

.lightbox-content-layer {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
}

.lightbox-content-layer img {
    max-width: 100%;
    max-height: 90vh;
}

.lightbox-content-layer iframe.lightbox-pdf {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 90vh;
}

.lightbox-gesture-layer {
    position: absolute;
    inset: 0;
    cursor: grab;
}

.lightbox-image-wrap.dragging .lightbox-gesture-layer {
    cursor: grabbing;
}
