:root {
    --bg: #f2f8f2;
    --card-bg: #ffffff;
    --text: #173221;
    --muted: #5e7667;
    --primary: #2f855a;
    --primary-dark: #276749;
    --secondary: #e7f3ea;
    --border: #d0e3d7;
    --border-light: #e8f2ec;
    --danger: #b00020;
    --success: #28a745;
    --success-dark: #218838;
    --hover-bg: #f0f8ff;
    --shadow: 0 10px 30px rgba(9, 30, 16, 0.08);
    --shadow-lg: 0 4px 15px rgba(0, 115, 80, 0.2);
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-pill: 20px;
    --transition: all 0.2s ease;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: linear-gradient(180deg, #f6fbf6, var(--bg));
    color: var(--text);
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 24px 16px 40px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 24px;
    background: linear-gradient(135deg, #f3fbf4 0%, #e9f7ee 100%);
    border-bottom: 1px solid var(--border);
}

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

.subtitle {
    margin: 8px 0 0;
    color: var(--muted);
}

.notice {
    margin: 16px 24px 0;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #f7fbf8;
}

.notice.loading {
    color: var(--muted);
}

.notice.error {
    border-color: #efc0c7;
    background: #fff4f6;
    color: #8f1730;
}

.notice.success {
    border-color: #b5dbc3;
    background: #effaf3;
    color: #145733;
}

#order-form {
    padding: 24px;
}

.form-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.form-section:last-of-type {
    border-bottom: 0;
    margin-bottom: 8px;
}

.form-section h2 {
    margin: 0 0 14px;
    font-size: 1.15rem;
}

.grid {
    display: grid;
    gap: 12px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field label {
    display: inline-block;
    margin-bottom: 6px;
    color: #244534;
    font-weight: 600;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    transition: var(--transition);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.1);
}

.field textarea {
    min-height: 92px;
    resize: vertical;
}

.time-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-range select {
    flex: 1;
    min-width: 0;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 8px;
    background: #fff;
    color: var(--text);
    transition: var(--transition);
    cursor: pointer;
}

.time-range select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.1);
}

.time-range-sep {
    font-size: 0.9rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.products-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.btn {
    border: 0;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1em;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn.primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 2px 6px rgba(47, 133, 90, 0.25);
}

.btn.primary:hover {
    box-shadow: var(--shadow-lg);
}

.btn.secondary {
    background: var(--secondary);
    color: #1f5135;
    border: 1px solid #cde4d7;
}

.btn.secondary:hover {
    background: #dff0e5;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ========== ORDER ITEMS (repeater) ========== */

.order-items-list {
    display: grid;
    gap: 10px;
}

.order-empty-state {
    border: 1px dashed #bfd9c9;
    border-radius: 12px;
    background: #f8fcf9;
    color: var(--muted);
    text-align: center;
    padding: 18px 12px;
}

.order-item-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    background: #fcfffd;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.order-item-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #f8faf9;
    flex-shrink: 0;
}

.order-item-info {
    flex: 1;
    min-width: 0;
}

.order-item-name {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-item-meta {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-item-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}


.qty-control {
    display: inline-flex;
    align-items: center;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--card-bg);
}

.qty-control input[type="number"] {
    width: 55px;
    text-align: center;
    border: none;
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
    border-radius: 0;
    padding: 8px 4px;
    font-size: 1.05em;
    font-weight: bold;
    -moz-appearance: textfield;
    margin: 0;
    box-shadow: none;
    height: auto;
    line-height: 1;
}

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

.qty-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--secondary);
    border: none;
    cursor: pointer;
    font-size: 1.3em;
    font-weight: bold;
    color: var(--text);
    transition: var(--transition);
    padding: 0;
    line-height: 1;
}

.qty-btn:hover {
    background: var(--primary);
    color: #fff;
}

.qty-btn:active {
    transform: scale(0.95);
}

.order-item-line-total {
    font-weight: 700;
    color: var(--primary);
    font-size: 1rem;
    white-space: nowrap;
}

.remove-item-btn {
    background: transparent;
    border: 1px solid #efc0c7;
    color: var(--danger);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    transition: var(--transition);
}

.remove-item-btn:hover {
    background: #fff4f6;
}

.order-total-bar {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #cfe3d7;
    background: #f3fbf5;
    border-radius: 12px;
    padding: 12px 14px;
    font-weight: 700;
}

/* ========== MODAL ========== */

.cof-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    direction: rtl;
}

.cof-modal.hidden {
    display: none;
}

.cof-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.cof-modal-content {
    position: relative;
    background: var(--card-bg);
    margin: 3vh auto;
    padding: 0;
    border: 1px solid var(--border);
    width: 92%;
    max-width: 820px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    max-height: 94vh;
    z-index: 1;
}

.cof-modal-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.cof-modal-header h3 {
    margin: 0;
    font-size: 1.2em;
}

.cof-close-modal {
    color: var(--muted);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    background: none;
    border: none;
    line-height: 1;
}

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

/* Search bar */
.cof-modal-search {
    padding: 10px 18px;
    background: #f9fbfa;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.cof-modal-search input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1em;
    transition: var(--transition);
}

.cof-modal-search input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.1);
}

/* Category filter tabs */
.category-filters {
    padding: 10px 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-bottom: 1px solid var(--border-light);
    background: #fafcfb;
    flex-shrink: 0;
}

.category-tab {
    padding: 7px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.92em;
    font-weight: 600;
    color: var(--muted);
    transition: var(--transition);
    white-space: nowrap;
}

.category-tab:hover {
    border-color: var(--primary);
    background: var(--hover-bg);
    color: var(--primary);
}

.category-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Product grid */
.cof-modal-grid {
    padding: 14px 18px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 12px;
    background: #f9fbfa;
}

.modal-product-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    cursor: pointer;
    transition: var(--transition);
    height: 100%;
    font-family: inherit;
    font-size: inherit;
    position: relative;
}

.modal-product-card:hover {
    background-color: var(--hover-bg);
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-product-card.selected {
    border-color: var(--primary);
    background: #eef8f2;
    box-shadow: 0 0 0 2px var(--primary);
}

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

.modal-product-card.out-of-stock {
    opacity: 0.7;
    position: relative;
}

.modal-product-card.out-of-stock:hover {
    border-color: var(--border);
    transform: none;
    box-shadow: none;
}

.oos-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 0.75em;
    padding: 4px 6px;
    border-radius: 4px;
    text-align: center;
}

.modal-prod-img {
    width: 100%;
    height: 110px;
    object-fit: contain;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
}

.modal-prod-name {
    font-weight: bold;
    color: var(--text);
    font-size: 0.92em;
    line-height: 1.25;
}

.modal-prod-meta {
    font-size: 0.82em;
    color: var(--muted);
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.modal-prod-price {
    color: var(--primary);
    font-weight: bold;
}

.modal-no-products {
    grid-column: 1 / -1;
    padding: 24px;
    text-align: center;
    color: var(--muted);
    font-size: 1.05em;
}

.modal-loading {
    grid-column: 1 / -1;
    padding: 2rem;
    text-align: center;
    color: var(--muted);
    font-size: 1.1em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.modal-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: cof-spin 0.9s linear infinite;
}

@keyframes cof-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Bottom qty bar */
.modal-qty-bar {
    border-top: 2px solid var(--primary);
    padding: 14px 18px;
    background: linear-gradient(135deg, #f0f8f3 0%, #e8f4ed 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-shrink: 0;
    animation: fadeInUp 0.25s ease;
}

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

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-qty-product-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.modal-qty-name {
    font-weight: bold;
    font-size: 0.95em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-qty-price {
    color: var(--primary);
    font-weight: bold;
    font-size: 0.9em;
}

.modal-qty-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.modal-qty-controls > label {
    font-weight: bold;
    white-space: nowrap;
    margin: 0;
}

.btn-add-to-list {
    background: linear-gradient(135deg, var(--success) 0%, var(--success-dark) 100%);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius);
    font-weight: bold;
    font-size: 1em;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(40, 167, 69, 0.3);
}

.btn-add-to-list:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

/* ========== RESULT POPUP ========== */

.result-modal-content {
    position: relative;
    background: var(--card-bg);
    margin: 15vh auto;
    padding: 40px 32px 32px;
    width: min(460px, calc(100vw - 32px));
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    text-align: center;
    z-index: 1;
    animation: fadeInUp 0.3s ease;
}

.result-modal-icon {
    font-size: 3.2rem;
    margin-bottom: 12px;
    line-height: 1;
}

.result-modal-title {
    margin: 0 0 12px;
    font-size: 1.4rem;
    color: var(--text);
}

.result-modal-title.success {
    color: var(--primary);
}

.result-modal-title.error {
    color: var(--danger);
}

.result-modal-message {
    color: var(--muted);
    font-size: 1.05rem;
    line-height: 1.65;
    margin: 0 0 24px;
    white-space: pre-line;
}

.result-modal-close {
    min-width: 140px;
}

/* ========== ACTIONS / FOOTER ========== */

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

.message {
    min-height: 24px;
    margin-top: 12px;
    font-weight: 600;
}

.message.error {
    color: #8f1730;
}

.message.success {
    color: #145733;
}

.locked {
    padding: 48px 24px;
    text-align: center;
}

.locked-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
}

.locked h1 {
    font-size: 1.6rem;
    margin: 0 0 16px;
    color: var(--primary);
}

.locked p {
    color: var(--muted);
    margin: 8px 0;
    line-height: 1.6;
}

.locked-contact {
    margin-top: 20px !important;
    color: var(--text) !important;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

/* ========== RESPONSIVE ========== */

@media (max-width: 780px) {
    .grid.two {
        grid-template-columns: 1fr;
    }

    .actions {
        flex-direction: column;
    }

    .actions .btn {
        width: 100%;
    }

    .cof-modal-content {
        width: 96%;
        max-height: 90vh;
        margin: 5vh auto;
    }

    .cof-modal-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px 12px;
    }

    .modal-prod-img {
        height: 90px;
    }

    .modal-product-card {
        padding: 8px;
    }

    .modal-qty-bar {
        flex-direction: column;
        gap: 10px;
        padding: 12px 14px;
    }

    .modal-qty-product-info {
        width: 100%;
    }

    .modal-qty-controls {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .btn-add-to-list {
        width: 100%;
        text-align: center;
    }

    .order-item-card {
        gap: 6px;
        padding: 7px 10px;
    }

    .order-item-img {
        width: 36px;
        height: 36px;
    }

    .order-item-controls {
        gap: 5px;
    }

    .qty-btn {
        width: 28px;
        height: 28px;
        font-size: 1em;
    }

    .qty-control input[type="number"] {
        width: 36px;
        padding: 5px 2px;
        font-size: 0.9em;
    }

    .order-item-line-total {
        font-size: 0.85rem;
    }

    .remove-item-btn {
        padding: 5px 7px;
        font-size: 0.8em;
    }

    .category-filters {
        padding: 8px 12px;
        gap: 6px;
    }

    .category-tab {
        padding: 6px 12px;
        font-size: 0.85em;
    }
}
