/* ===== Dialogs and forms (create order, log delivery, edit order) ===== */

.modal {
    --form-bg: var(--orrs-panel);
    --form-field: var(--orrs-bg);
    --form-border: var(--orrs-border);
    --form-text: var(--orrs-text);
    --form-muted: var(--orrs-muted);
    --form-accent: var(--orrs-orange);
    --form-danger: var(--orrs-red);

    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    margin: auto;   /* centre it; the site's reset removes the browser default */
    padding: 0;
    border: 1px solid var(--form-border);
    border-top: 4px solid var(--form-accent);
    background: var(--form-bg);
    color: var(--form-text);
    font-family: 'Oxanium', Verdana, sans-serif;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.modal.modal-small { width: min(460px, calc(100vw - 32px)); }

.modal::backdrop { background: rgba(10, 11, 13, 0.65); }

.modal form {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 24px 26px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-title {
    margin: 0;
    font: 700 18px 'Orbitron', Tahoma, sans-serif;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--form-accent);
}

.modal-close {
    background: none;
    border: none;
    color: var(--form-muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
}

.modal-close:hover { color: var(--form-text); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid .span-2 { grid-column: span 2; }

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--form-muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.form-field input,
.form-field select,
.line-table input {
    font: 500 15px 'Oxanium', Verdana, sans-serif;
    color: var(--form-text);
    background: var(--form-field);
    border: 1px solid var(--form-border);
    border-radius: 0;
    padding: 10px 12px;
    width: 100%;
    box-sizing: border-box;
    color-scheme: dark;
}

.form-field input:focus,
.form-field select:focus,
.line-table input:focus {
    outline: 2px solid var(--form-accent);
    outline-offset: -1px;
}

.form-hint {
    margin: 0;
    font-size: 13px;
    color: var(--form-muted);
}

/* line items table in the create form */
.line-table-wrap { overflow-x: auto; }

.line-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

.line-table th {
    text-align: left;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--form-muted);
    padding: 0 6px 6px;
}

.line-table td { padding: 4px 6px; }
.line-table .col-num { width: 92px; }
.line-table .col-category { width: 130px; }

.line-table select {
    font: 500 15px 'Oxanium', Verdana, sans-serif;
    color: var(--form-text);
    background: var(--form-field);
    border: 1px solid var(--form-border);
    border-radius: 0;
    padding: 8px 6px;
    width: 100%;
    color-scheme: dark;
}
.line-table .col-amount { width: 110px; text-align: right; white-space: nowrap; }
.line-table .col-remove { width: 36px; }
.line-table input { padding: 8px 10px; }

.line-remove {
    background: none;
    border: none;
    color: var(--form-muted);
    font-size: 20px;
    cursor: pointer;
}

.line-remove:hover { color: var(--form-danger); }
.line-remove:disabled { visibility: hidden; }

.form-totals {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid var(--form-border);
    font-weight: 600;
}

.form-totals strong { color: var(--form-accent); }

.form-error {
    margin: 0;
    padding: 10px 14px;
    border-radius: 0;
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid var(--form-danger);
    color: #ffb4ab;
}

.form-error[hidden] { display: none; }

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

/* buttons usable on any page */
.form-btn {
    font: 700 12px 'Oxanium', Verdana, sans-serif;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    border-radius: 0;
    padding: 10px 18px;
    border: 1px solid var(--form-border, #4c525a);
    background: transparent;
    color: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.form-btn:hover:not(:disabled) { border-color: var(--orrs-orange); }
.form-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form-btn-primary {
    background: var(--orrs-orange);
    border-color: var(--orrs-orange);
    color: var(--orrs-on-accent);
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}

.form-btn-primary:hover:not(:disabled) { background: var(--orrs-orange-hover); border-color: var(--orrs-orange-hover); }

.form-btn-danger { color: #ff7b6b; border-color: rgba(231, 76, 60, 0.6); }
.form-btn-danger:hover:not(:disabled) { background: rgba(231, 76, 60, 0.15); border-color: #e74c3c; }

.form-btn-small { padding: 6px 12px; font-size: 13px; }

@media (max-width: 600px) {
    .modal form { padding: 18px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }

    /* order lines stack into a small labelled card each instead of a wide table:
         Material ...................
         Category   Qty (SCU)  Min Q
         Price      Amount         ×   */
    .line-table-wrap { overflow-x: visible; }
    .line-table, .line-table tbody { display: block; min-width: 0; }
    .line-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }
    .line-table tr {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-areas:
            "mat mat mat"
            "cat qty minq"
            "price amt rm";
        gap: 8px;
        padding: 12px 0;
        border-bottom: 1px solid var(--form-border);
    }
    .line-table td,
    .line-table .col-num,
    .line-table .col-category,
    .line-table .col-amount,
    .line-table .col-remove { display: block; width: auto; padding: 0; }

    .line-table td:nth-child(1) { grid-area: mat; }
    .line-table td:nth-child(2) { grid-area: cat; }
    .line-table td:nth-child(3) { grid-area: qty; }
    .line-table td:nth-child(4) { grid-area: minq; }
    .line-table td:nth-child(5) { grid-area: price; }
    .line-table td:nth-child(6) {
        grid-area: amt;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding-bottom: 9px;
        text-align: left;
        font-weight: 600;
    }
    .line-table td:nth-child(7) { grid-area: rm; align-self: end; text-align: right; }

    .line-table td:nth-child(-n+6)::before {
        display: block;
        margin-bottom: 4px;
        font-size: 11px;
        letter-spacing: 1px;
        text-transform: uppercase;
        text-align: left;
    }
    .line-table td:nth-child(1)::before { content: 'Material'; }
    .line-table td:nth-child(2)::before { content: 'Category'; }
    .line-table td:nth-child(3)::before { content: 'Qty (SCU)'; }
    .line-table td:nth-child(4)::before { content: 'Min Q'; }
    .line-table td:nth-child(5)::before { content: 'Price / unit'; }
    .line-table td:nth-child(6)::before { content: 'Amount'; }

    .line-table input,
    .line-table select { width: 100%; min-width: 0; }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.form-field input:read-only {
    color: var(--form-muted);
    background: transparent;
    cursor: default;
}
