/* Add to Template Button Styles */
.add-to-template-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid #1E194A;
    color: #1E194A;
    cursor: pointer;
    font-size: 14px;
    margin-left: 10px;
    transition: all 0.2s;
    border-radius: 4px;
}

.add-to-template-btn:hover {
    background: #1E194A;
    color: white;
}

.add-to-template-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.button-section .add-to-template-btn {
    margin-left: 0;
    margin-right: 10px;
}

/* Modal Open State */
body.modal-open {
    overflow: hidden;
}

/* Create Order Template Button in Empty State */
.create-order-template-from-empty,
#create-order-template-from-empty-btn,
#create-order-template-from-empty-btn-2 {
    pointer-events: auto !important;
    cursor: pointer !important;
    z-index: 10001 !important;
    position: relative !important;
}

.templates-empty {
    pointer-events: auto !important;
    z-index: 1;
    position: relative;
}

/* Message Display Styles */
.template-message-container {
    animation: slideDown 0.3s ease-out;
}

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

.template-message {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.message-icon {
    font-size: 18px;
    font-weight: bold;
    display: inline-block;
    min-width: 20px;
    text-align: center;
}

.message-close:hover {
    opacity: 1 !important;
    color: #000;
}

.message-success .message-icon {
    font-size: 18px;
}

.message-error .message-icon {
    font-size: 18px;
}

.message-warning .message-icon {
    font-size: 18px;
}

.templates-loading {
    text-align: center;
    padding: 20px;
}

/* Cart page templates list - hidden by default, shown when needed */
.order-template-modal .templates-list {
    display: none;
}

.template-items-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.templates-empty {
    display: none;
    padding: 20px;
}

.templates-empty p {
    text-align: center;
    margin-bottom: 20px;
    color: #666;
}

.templates-error {
    display: none;
    text-align: center;
    padding: 20px;
    color: red;
}

/* Only hide modal-footer within the select template modal, not the create template modal */
#order-template-modal .modal-footer {
    display: none;
}

#order-template-modal .modal-footer.show {
    display: block;
}

/* Create template modal footer should always be visible */
#create-template-modal .modal-footer {
    display: block !important;
}

/* Homepage Templates Popup Styles */
#templates-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#templates-popup.show {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    align-items: center;
    justify-content: center;
}

/* Homepage popup templates list - always visible when popup is shown */
#templates-popup .templates-list {
    min-height: 200px;
    display: block;
}

.templates-items {
    list-style: none;
    padding: 0;
    margin: 0;
}

.templates-items .template-item {
    padding: 15px;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.template-info {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.templates-items .template-name {
    font-weight: 600;
    color: #1e194a;
    font-size: 14px;
    margin-bottom: 5px;
}

.templates-items .template-date {
    font-size: 12px;
    color: #6c757d;
}

.templates-items .template-product-count {
    display: block;
    font-size: 12px;
    color: #666;
    margin-top: 3px;
}

.order-template-btn {
    margin-left: 15px;
    padding: 10px 20px;
    font-weight: 600;
    border-radius: 4px;
    transition: background 0.2s;
}

.order-template-btn:hover {
    background: #0052a3;
}

.loading, .empty, .error {
    text-align: center;
    padding: 40px;
    color: #666;
}

.empty-state-popup {
    text-align: center;
    padding: 20px 0;
}

.empty-state-popup .empty-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state-popup h3 {
    color: #1E194A;
    margin-bottom: 10px;
    font-size: 18px;
    font-weight: 600;
}

.empty-state-popup p {
    color: #1E194A;
    margin-bottom: 25px;
    font-size: 14px;
}

.create-template-link {
    display: inline-block;
    padding: 12px 24px;
    background: #0066cc;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    transition: background 0.2s;
}

.create-template-link:hover {
    background: #0052a3;
    color: #fff;
}

/* Inline Styles Extracted from Templates */

/* Modal Display States */
.order-template-modal {
    display: none;
}

.templates-loading {
    text-align: center;
    padding: 20px;
}

.templates-list {
    display: none;
}

.template-items-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.templates-empty {
    display: none;
    padding: 20px;
}

.templates-empty p {
    text-align: center;
    margin-bottom: 20px;
    color: #666;
}

.templates-error {
    display: none;
    text-align: center;
    padding: 20px;
    color: red;
}

/* Note: Removed global .modal-footer rule as it was hiding buttons in other modals */
/* Only our specific order template modals should have hidden footers, which is handled above */

/* Message Container */
.template-message-container {
    display: none;
    margin-bottom: 15px;
}

.template-message {
    padding: 12px 16px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.message-text {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.message-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-close:hover {
    opacity: 1;
}

/* Inline Form Styles */
.create-template-form-inline {
    display: flex;
    flex-direction: column;
    margin-top: 20px;
}

.create-template-form-inline label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #1E194A;
    font-size: 14px !important;
}

.create-template-form-inline label span {
    color: red;
}

.create-template-form-inline input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #1E194A;
    box-sizing: border-box;
}

.template-name-error-inline {
    display: none;
    color: red;
    margin-top: 5px;
    font-size: 12px;
}

.create-template-form-inline .action-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

button.cancel-create-template-inline {
    background: transparent !important;
    color: #1E194A !important;
    font-size: 14px !important;
}

.cancel-create-template-inline {
    border-radius: 4px;
    cursor: pointer;
}

/* Create Template Form */
.create-template-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.create-template-form input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #1E194A;
}

.template-name-error {
    display: none;
    color: red;
    margin-top: 5px;
    font-size: 12px;
}

.create-template-modal .modal-footer {
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    text-align: right;
}

.cancel-create-template {
    margin-right: 10px;
}

/* Create Order Template Button in Empty State */
.create-order-template-from-empty,
#create-order-template-from-empty-btn,
#create-order-template-from-empty-btn-2 {
    padding: 12px 24px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px !important;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    pointer-events: auto;
    z-index: 10001;
    position: relative;
}

/* Template Item Styles (for dynamically created items) */
.template-item {
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    cursor: pointer;
    transition: background-color 0.2s;
}

.template-name {
    font-weight: bold;
}

.template-date {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

.template-product-count {
    font-size: 12px;
    color: #666;
    margin-top: 3px;
}

.stock-detail-label {
    display: inline-block;
}

.toggle-warehouse-list {
    display: inline-block;
    text-decoration: none;
    cursor: pointer;
    color: inherit;
    transition: opacity 0.2s;
}

.toggle-warehouse-list:hover {
    opacity: 0.8;
}

.template-source-available,
.template-source-alternate,
.template-out-of-stock {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}

.template-source-available {
    color: #27AE60;
}

.template-source-alternate {
   color: #F2994A;
}

.template-out-of-stock {
    color: #EB5757;
}

.template-out-of-stock svg path,
.template-out-of-stock svg rect {
    stroke: #EB5757;

}

.stock-status.alternate svg path,
.template-source-alternate svg path {
    fill: #F2994A;
}

.template-source-available svg path {
    fill: #27AE60;
}

.template-source-available,
.template-source-alternate,
.template-source-selected {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1.4;
    color: white;
}

.template-source-available {
    color: #27AE60;
}

.template-source-alternate {
    color: #F2994A;
}

.template-source-selected {
    color: #667eea;
}

.template-source-available svg,
.template-source-alternate svg,
.template-source-selected svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.template-out-of-stock svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* Warehouse popup overlay */
body.warehouse-popup-open {
    overflow: hidden;
}

.warehouse-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10002;
    display: none;
}

body.warehouse-popup-open .warehouse-popup-overlay {
    display: block;
}

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

/* Template Edit Page - Custom Warehouse Popup Classes */
.template-warehouse-list {
    display: none !important;
    position: fixed !important;
    background: white !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
    min-width: 400px !important;
    max-width: 600px !important;
    z-index: 10003 !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    animation: fadeIn 0.3s ease-in;
}

.template-warehouse-list.template-show {
    display: block !important;
}

.template-warehouse-inner {
    padding: 20px;
}

.template-warehouse-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
}

.template-warehouse-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: bold;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.template-warehouse-close {
    cursor: pointer;
    color: #666;
    transition: color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: transparent;
    padding: 0;
    border: none;
}

.template-warehouse-close:hover {
    color: #000;
    background: #f5f5f5;
}

.template-selected-product {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.template-product-details {
    display: flex;
    flex-direction: column;
}

.template-product-name {
    font-weight: bold;
    margin-bottom: 5px;
    color: #333;
    font-size: 16px;
}

.template-product-sku {
    font-size: 12px;
    color: #666;
}

.template-product-sku span {
    font-weight: 600;
    margin-right: 5px;
}

.template-product-sku p {
    margin: 0;
    display: inline;
}

.template-warehouse-table {
    max-height: 300px;
    overflow-y: auto;
}

.template-warehouse-table table {
    width: 100%;
    border-collapse: collapse;
}

.template-warehouse-table th,
.template-warehouse-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.template-warehouse-table th {
    background-color: #f5f5f5;
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 1;
}

.template-warehouse-table th.name,
.template-warehouse-table td:first-child {
    width: 35%;
}

.template-warehouse-table th.qty,
.template-warehouse-table td:nth-child(2) {
    text-align: center;
    width: 15%;
}

.template-warehouse-table th.quantity,
.template-warehouse-table td:nth-child(3) {
    text-align: center;
    width: 30%;
}

.template-warehouse-table th.action,
.template-warehouse-table td:nth-child(4) {
    text-align: center;
    width: 20%;
}

/* Quantity Control Styling */
.qty-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.qty-control button {
    width: 32px;
    height: 32px;
    border: 1px solid #e0e0e0;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    color: #333;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-control button:hover {
    background: #f5f5f5;
    border-color: #667eea;
}

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

.qty-control .warehouse-qty-input {
    width: 50px;
    height: 32px;
    text-align: center;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    background: white;
}

/* Template Warehouse Footer */
.template-warehouse-footer {
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #f8f9fa;
}

.template-warehouse-footer .action {
    padding: 10px 20px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    border: none;
}

.template-warehouse-footer .action.secondary {
    background: transparent;
    color: #1E194A !important;
    border: 1px solid #ccc;
    margin-right: 0;
}

/* Template warehouse overlay */
body.template-warehouse-open {
    overflow: hidden;
}

.empty-state-popup a.create-template-link {
    font-size: 14px !important;
    font-weight: 600;
}
div#templates-popup .templates-actions {
    display: flex;
    justify-content: center;
}

div#templates-popup .templates-actions  a.manage-templates-btn {
    font-size: 14px;
    font-weight: 600;
    color: #DE0021;
    padding: 0 5px 1px;
    border-bottom: 1px solid #DE0021;
    transition: border 0.3s ease-out;
}

div#templates-popup .templates-actions  a.manage-templates-btn:hover {
    border-color: #fff;
}

div#order-template-modal .template-items-list {
    display: flex;
    flex-direction: column;
    gap: 10px;    
}

div#order-template-modal .template-items-list .template-item {
    border: 1px solid #BABABA;
    border-radius: 6px;
    line-height: 1;
}

div#order-template-modal .template-items-list .template-item .template-name {
    font-size: 14px;
    margin-bottom: 10px;
    color: #1E194A;
    text-transform: capitalize;
}

div#order-template-modal .template-items-list .template-item .template-date,
div#order-template-modal .template-items-list .template-item .template-product-count {
    color: #646464;
    font-weight: 600;
}

div#create-template-modal .create-template-form label {
    font-size: 14px !important;
    color: #1E194A !important;
}
#create-template-modal .modal-footer button.cancel-create-template {
    background: transparent !important;
    color: #1E194A !important;
}