@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
    --primary: hsl(347, 85%, 51%);
    --primary-hover: hsl(347, 85%, 44%);
    --primary-active: hsl(347, 85%, 38%);
    --primary-light: rgba(236, 24, 70, 0.08);
    --secondary: hsl(215, 15%, 30%);
    --secondary-hover: hsl(215, 15%, 22%);
    --bg-page: hsl(210, 20%, 97%);
    --bg-card: hsl(0, 0%, 100%);
    --text-main: hsl(215, 25%, 15%);
    --text-muted: hsl(215, 15%, 45%);
    --border-color: hsl(214, 20%, 88%);
    --border-color-focus: hsl(347, 85%, 51%);
    --focus-ring: rgba(236, 24, 70, 0.15);
    --shadow-subtle: 0 4px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px -1px rgba(0, 0, 0, 0.01);
    --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.04), 0 1px 3px 0 rgba(0, 0, 0, 0.01);
    --shadow-input-hover: 0 2px 4px rgba(0, 0, 0, 0.02);
    --font-sans: 'Plus Jakarta Sans', Arial, sans-serif;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-page);
    color: var(--text-main);
    padding: 40px 20px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 900px;
    margin: auto;
}

form {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
}

.header {
    text-align: center;
    margin-bottom: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.logo {
    max-height: 80px;
    max-width: 100%;
    height: auto;
    margin-bottom: 16px;
    transition: transform var(--transition-normal);
}

.logo:hover {
    transform: scale(1.03);
}

.header h1 {
    color: var(--text-main);
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, hsl(347, 85%, 51%), hsl(347, 85%, 34%));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.card {
    margin-top: 30px;
    margin-bottom: 30px;
    padding: 24px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    box-shadow: var(--shadow-subtle);
}

.card h2 {
    background: linear-gradient(135deg, hsl(347, 85%, 51%), hsl(347, 85%, 41%));
    color: white;
    padding: 14px 20px;
    margin: -24px -24px 24px -24px;
    border-radius: 11px 11px 0 0;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    box-shadow: 0 4px 10px rgba(236, 24, 70, 0.12);
}

label {
    display: block;
    margin-bottom: 8px;
    margin-top: 16px;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-main);
    letter-spacing: 0.1px;
}

input,
textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    color: var(--text-main);
    background-color: hsl(0, 0%, 100%);
    box-shadow: var(--shadow-subtle);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:hover,
textarea:hover {
    border-color: hsl(214, 20%, 75%);
    box-shadow: var(--shadow-input-hover);
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--border-color-focus);
    box-shadow: 0 0 0 4px var(--focus-ring);
}

textarea {
    resize: vertical;
    line-height: 1.6;
}

input[readonly] {
    background-color: hsl(210, 20%, 96%);
    border-color: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

input[readonly]:hover {
    border-color: var(--border-color);
    box-shadow: none;
}

.grid-2,
.grid-3 {
    display: grid;
    gap: 20px;
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.materials-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.materials-header h2 {
    margin-bottom: 0;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th,
td {
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

th {
    background: hsl(210, 20%, 96%);
    color: var(--text-main);
    font-weight: 600;
    text-align: left;
}

table input {
    padding: 8px 12px;
    font-size: 0.9rem;
    box-shadow: none;
    border-width: 1px;
}

.remove-row {
    background: hsl(347, 85%, 95%);
    color: hsl(347, 85%, 51%);
    border: 1px solid hsl(347, 85%, 90%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
    transition: all var(--transition-fast);
}

.remove-row:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.08);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
    box-shadow: 0 4px 6px rgba(236, 24, 70, 0.12);
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(236, 24, 70, 0.2);
}

.btn:active {
    background: var(--primary-active);
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(236, 24, 70, 0.12);
}

.btn.secondary {
    background: hsl(210, 10%, 90%);
    color: var(--text-main);
    box-shadow: none;
}

.btn.secondary:hover {
    background: hsl(210, 10%, 82%);
    box-shadow: none;
}

.btn.small {
    padding: 8px 14px;
    font-size: 0.85rem;
}

#signature-pad {
    width: 100%;
    height: 220px;
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    background: hsl(210, 20%, 99%);
    touch-action: none;
    transition: border-color var(--transition-fast);
}

#signature-pad:hover {
    border-color: var(--primary-hover);
}

.signature-actions {
    margin-top: 14px;
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
}

input[type="file"] {
    background: hsl(210, 20%, 98%);
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: none;
}

input[type="file"]:hover {
    background: hsl(210, 20%, 96%);
    border-color: var(--primary-hover);
}

input[type="file"]::file-selector-button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-family: var(--font-sans);
    margin-right: 15px;
    transition: all var(--transition-fast);
}

input[type="file"]::file-selector-button:hover {
    background: var(--primary-hover);
}

.submit-btn {
    width: 100%;
    background: linear-gradient(135deg, hsl(347, 85%, 51%), hsl(347, 85%, 41%));
    color: white;
    border: none;
    padding: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    font-family: var(--font-sans);
    letter-spacing: 0.5px;
    transition: all var(--transition-fast);
    box-shadow: 0 6px 20px rgba(236, 24, 70, 0.2);
    margin-top: 20px;
}

.submit-btn:hover {
    background: linear-gradient(135deg, hsl(347, 85%, 54%), hsl(347, 85%, 44%));
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(236, 24, 70, 0.3);
}

.submit-btn:active {
    transform: translateY(0);
    box-shadow: 0 4px 10px rgba(236, 24, 70, 0.15);
}

/* Status Overlay Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 480px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--border-color);
    transform: scale(0.95);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-card {
    transform: scale(1);
}

.modal-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.modal-state.hidden {
    display: none !important;
}

.modal-state h3 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
}

.modal-state p {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.modal-state .btn {
    margin-top: 10px;
    padding: 12px 24px;
}

/* Spinner Animation */
.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--primary-light);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 8px;
}

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

/* Success Checkmark Animation */
.success-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 8px;
}

.success-circle {
    stroke: hsl(142, 70%, 45%);
    stroke-width: 2;
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-miterlimit: 10;
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.success-check {
    transform-origin: 50% 50%;
    stroke: hsl(142, 70%, 45%);
    stroke-width: 3;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.6s forwards;
}

@keyframes stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

/* Error Cross Icon */
.error-icon {
    width: 60px;
    height: 60px;
    background: hsl(347, 85%, 95%);
    color: var(--primary);
    font-size: 2rem;
    font-weight: bold;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--primary);
    margin-bottom: 8px;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@media (max-width: 768px) {
    body {
        padding: 20px 10px;
    }

    form {
        padding: 24px;
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .card {
        padding: 20px;
    }

    .card h2 {
        margin: -20px -20px 20px -20px;
        padding: 12px 16px;
        font-size: 1.05rem;
    }
}
/* ─────────────────────────────────────────────────────────────
   Connectivity / outbox pill
   ───────────────────────────────────────────────────────────── */

.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-card);
    box-shadow: var(--shadow-subtle);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color var(--transition-fast), color var(--transition-fast);
}

.sync-pill[hidden] {
    display: none;
}

.sync-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.sync-pill.is-online  { color: hsl(150, 60%, 32%); border-color: hsl(150, 45%, 80%); }
.sync-pill.is-offline { color: var(--text-muted); }
.sync-pill.is-pending { color: hsl(35, 85%, 38%); border-color: hsl(35, 80%, 78%); }
.sync-pill.is-error   { color: var(--primary); border-color: hsl(347, 70%, 82%); }

/* ─────────────────────────────────────────────────────────────
   Restored draft banner
   ───────────────────────────────────────────────────────────── */

.draft-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 12px 16px;
    border: 1.5px solid hsl(35, 80%, 82%);
    border-radius: 12px;
    background: hsl(40, 90%, 96%);
    color: hsl(35, 60%, 28%);
    font-size: 0.9rem;
}

.draft-banner[hidden] {
    display: none;
}

/* ─────────────────────────────────────────────────────────────
   "Now" buttons beside the time inputs
   ───────────────────────────────────────────────────────────── */

.input-with-action {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-with-action input {
    flex: 1;
    min-width: 0;
}

.input-with-action .now-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

/* ─────────────────────────────────────────────────────────────
   Photo thumbnails
   ───────────────────────────────────────────────────────────── */

.photo-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.photo-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.photo-grid:empty {
    margin-top: 0;
}

.photo-thumb {
    position: relative;
    aspect-ratio: 4 / 3;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-page);
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(21, 29, 48, 0.72);
    color: #fff;
    font-size: 0.8rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.photo-remove:hover {
    background: var(--primary);
}

/* ─────────────────────────────────────────────────────────────
   Offline modal state
   ───────────────────────────────────────────────────────────── */

.offline-icon {
    font-size: 2.6rem;
    line-height: 1;
    margin-bottom: 8px;
}

#viewInSharePointBtn {
    display: inline-block;
    margin-bottom: 10px;
    text-decoration: none;
}

#viewInSharePointBtn[hidden] {
    display: none;
}

/* ─────────────────────────────────────────────────────────────
   Materials table

   The spinner arrows on the Qty field ate most of a narrow cell and left
   the digits unreadable, and four columns never fit a phone at all.
   ───────────────────────────────────────────────────────────── */

#materialsTable input[type="number"]::-webkit-outer-spin-button,
#materialsTable input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#materialsTable input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Give Qty and Remove only the room they need, so Material and Serial
   Number keep the rest. */
#materialsTable th:nth-child(2),
#materialsTable td:nth-child(2) {
    width: 120px;
}

#materialsTable th:nth-child(4),
#materialsTable td:nth-child(4) {
    width: 84px;
    text-align: center;
}

/* On a phone each material becomes its own labelled card instead of a row
   in a table that has to be scrolled sideways. */
@media (max-width: 640px) {
    .table-wrapper {
        overflow-x: visible;
        border: none;
        border-radius: 0;
    }

    #materialsTable thead {
        display: none;
    }

    #materialsTable,
    #materialsTable tbody,
    #materialsTable tr,
    #materialsTable td {
        display: block;
        width: 100%;
    }

    #materialsTable tr {
        border: 1.5px solid var(--border-color);
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
        background: var(--bg-card);
    }

    #materialsTable tr:last-child {
        margin-bottom: 0;
    }

    #materialsTable td,
    #materialsTable td:nth-child(2),
    #materialsTable td:nth-child(4) {
        border: none;
        padding: 0 0 14px 0;
        width: 100%;
    }

    #materialsTable td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 6px;
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--text-muted);
    }

    #materialsTable td input {
        padding: 12px 14px;
        font-size: 1rem;   /* 16px, so iOS does not zoom the page on focus */
    }

    /* The remove control gets a proper tap target and a label of its own. */
    #materialsTable td:nth-child(4) {
        width: 100%;
        padding-bottom: 0;
        text-align: left;
    }

    #materialsTable td:nth-child(4)::before {
        content: none;
    }

    #materialsTable .remove-row {
        width: 100%;
        height: 42px;
        border-radius: 8px;
        font-size: 0.9rem;
        gap: 6px;
    }

    #materialsTable .remove-row::after {
        content: 'Remove';
        font-weight: 600;
    }

    .materials-header {
        flex-wrap: wrap;
        gap: 12px;
    }
}
