/**
 * WooCommerce Order Templates Stylesheet
 * 
 * Styles für die Bestellvorlagen-Funktionalität
 * 
 * @package WooCommerce Rental Lists
 * @since 1.1.0
 */

/* =========================================
   Allgemeine Styles
   ========================================= */

.woocommerce-order-templates {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5em;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.woocommerce-order-templates h1 {
    font-size: 1.8em;
    margin-bottom: 0.5em;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 0.5em;
}

.woocommerce-order-templates h2 {
    font-size: 1.3em;
    margin: 1.5em 0 1em;
    color: #444;
    display: flex;
    align-items: center;
    gap: 0.5em;
    flex-wrap: wrap;
}

.woocommerce-order-templates h2 .button {
    margin-left: auto;
}

.order-templates-intro {
    color: #666;
    line-height: 1.6;
    margin-bottom: 1.5em;
}

.section-icon {
    font-size: 1.2em;
}

/* =========================================
   Benachrichtigungen
   ========================================= */

.order-template-messages {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 1.5em;
}

.order-template-messages.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.order-template-messages.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.order-template-messages.info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* =========================================
   Formulare
   ========================================= */

.order-template-form .form-row {
    margin-bottom: 1em;
}

.order-template-form label {
    display: block;
    margin-bottom: 0.4em;
    font-weight: 500;
    color: #333;
}

.order-template-form label .required {
    color: #e53935;
}

.order-template-form label .optional {
    font-weight: normal;
    color: #888;
    font-size: 0.9em;
}

.order-template-form input[type="text"],
.order-template-form input[type="email"],
.order-template-form input[type="number"],
.order-template-form textarea,
.order-template-form select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.order-template-form input:focus,
.order-template-form textarea:focus,
.order-template-form select:focus {
    border-color: #8BC34A;
    box-shadow: 0 0 0 3px rgba(139, 195, 74, 0.15);
    outline: none;
}

.order-template-form textarea {
    resize: vertical;
    min-height: 60px;
}

.order-template-form .form-row-checkbox label {
    display: flex;
    align-items: center;
    gap: 0.5em;
    font-weight: normal;
    cursor: pointer;
}

.order-template-form .form-row-checkbox input[type="checkbox"] {
    width: auto;
}

.order-template-form .form-actions {
    display: flex;
    gap: 0.8em;
    margin-top: 1.5em;
}

.field-hint {
    font-size: 0.85em;
    color: #888;
    margin-top: 0.3em;
}

/* Formular-Wrapper (einklappbar) */
.create-template-form-wrapper {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 1.5em;
    margin-bottom: 1.5em;
}

/* =========================================
   Buttons
   ========================================= */

.woocommerce-order-templates .button {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #ddd;
    background-color: #f5f5f5;
    color: #333;
}

.woocommerce-order-templates .button:hover {
    background-color: #eee;
    border-color: #ccc;
}

.woocommerce-order-templates .button-primary {
    background-color: #8BC34A;
    border-color: #8BC34A;
    color: #fff;
}

.woocommerce-order-templates .button-primary:hover {
    background-color: #7CB342;
    border-color: #7CB342;
}

.woocommerce-order-templates .button-primary:disabled {
    background-color: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
}

.woocommerce-order-templates .button-small {
    padding: 6px 12px;
    font-size: 0.85em;
}

.woocommerce-order-templates .button-link-delete {
    background: none;
    border: none;
    color: #e53935;
    padding: 6px 10px;
}

.woocommerce-order-templates .button-link-delete:hover {
    background-color: #ffebee;
}

.woocommerce-order-templates .button.loading {
    opacity: 0.7;
    pointer-events: none;
}

.woocommerce-order-templates .button.loading::after {
    content: "";
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 0.5em;
}

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

.button-icon {
    font-size: 1.1em;
}

/* =========================================
   Vorlagen-Liste
   ========================================= */

.templates-list {
    display: flex;
    flex-direction: column;
    gap: 1em;
}

.no-templates-message {
    text-align: center;
    padding: 3em 2em;
    background-color: #f9f9f9;
    border-radius: 8px;
}

.no-templates-message .empty-state-icon {
    font-size: 3em;
    margin-bottom: 0.3em;
}

.no-templates-message .hint {
    color: #888;
    font-size: 0.95em;
}

/* =========================================
   Vorlagen-Karte
   ========================================= */

.template-card {
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    background-color: #fff;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.template-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.2em 1.5em;
    background-color: #fafafa;
    border-bottom: 1px solid #eee;
    gap: 1em;
}

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

.template-name {
    font-size: 1.15em;
    font-weight: 600;
    margin: 0 0 0.3em;
    color: #333;
}

.template-description {
    color: #666;
    font-size: 0.9em;
    margin: 0 0 0.5em;
    line-height: 1.4;
}

.template-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1em;
    font-size: 0.85em;
    color: #888;
}

.template-meta .meta-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
}

.template-meta .delivery-badge {
    background-color: #e3f2fd;
    color: #1976d2;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.85em;
}

.template-actions {
    display: flex;
    gap: 0.5em;
    flex-shrink: 0;
}

.template-toggle-details .toggle-icon {
    transition: transform 0.2s;
    display: inline-block;
    margin-left: 0.3em;
}

.template-card.expanded .template-toggle-details .toggle-icon {
    transform: rotate(180deg);
}

/* =========================================
   Vorlagen-Details (eingeklappt)
   ========================================= */

.template-details {
    padding: 1.5em;
    background-color: #fff;
}

.template-empty {
    text-align: center;
    padding: 2em;
    color: #888;
    background-color: #f9f9f9;
    border-radius: 6px;
}

.template-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8em;
    margin-top: 1.5em;
    padding-top: 1.5em;
    border-top: 1px solid #eee;
}

/* =========================================
   Produkt-Tabelle in Vorlage
   ========================================= */

.template-items-wrapper {
    overflow-x: auto;
}

.template-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

.template-items-table th,
.template-items-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

.template-items-table th {
    background-color: #f5f5f5;
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    color: #666;
}

.template-items-table tbody tr:hover {
    background-color: #fafafa;
}

.template-items-table .col-sort {
    width: 30px;
    text-align: center;
}

.template-items-table .col-thumbnail {
    width: 50px;
}

.template-items-table .col-thumbnail img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
}

.template-items-table .col-sku {
    width: 100px;
}

.template-items-table .col-sku code {
    background-color: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

.template-items-table .col-name {
    min-width: 200px;
}

.template-items-table .col-name a {
    color: #333;
    text-decoration: none;
}

.template-items-table .col-name a:hover {
    color: #8BC34A;
}

.template-items-table .col-ve {
    width: 80px;
    color: #666;
}

.template-items-table .col-price {
    width: 100px;
    text-align: right;
}

.template-items-table .col-actions {
    width: 50px;
    text-align: center;
}

/* Sortier-Handle */
.sort-handle {
    cursor: grab;
    color: #bbb;
    font-size: 1.2em;
    user-select: none;
}

.sort-handle:hover {
    color: #888;
}

.template-item.ui-sortable-helper {
    background-color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.template-item.ui-sortable-placeholder {
    background-color: #e8f5e9;
    visibility: visible !important;
}

/* Entfernen-Button */
.remove-template-item {
    background: none;
    border: none;
    color: #ccc;
    font-size: 1.2em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.remove-template-item:hover {
    color: #e53935;
    background-color: #ffebee;
}

/* =========================================
   Excel Import Bereich
   ========================================= */

.excel-import-section {
    margin-top: 2em;
    padding-top: 2em;
    border-top: 2px solid #eee;
}

.import-instructions {
    background-color: #f5f5f5;
    border-radius: 8px;
    padding: 1.2em 1.5em;
    margin-bottom: 1.5em;
}

.import-instructions p {
    margin: 0 0 0.8em;
}

.import-instructions ol {
    margin: 0;
    padding-left: 1.5em;
}

.import-instructions li {
    margin-bottom: 0.4em;
    color: #555;
}

.excel-import-form {
    max-width: 500px;
}

.excel-import-form input[type="file"] {
    padding: 10px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    width: 100%;
    cursor: pointer;
    transition: border-color 0.2s;
}

.excel-import-form input[type="file"]:hover {
    border-color: #8BC34A;
}

.import-result {
    margin-top: 1.5em;
    padding: 1em 1.5em;
    border-radius: 8px;
}

.import-result.success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
}

.import-result.error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
}

/* =========================================
   Modal Styles
   ========================================= */

.order-template-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
}

.order-template-modal .modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.order-template-modal .modal-content {
    position: relative;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    background-color: #fff;
    border-radius: 12px;
    padding: 1.8em;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.order-template-modal .modal-content.modal-large {
    max-width: 800px;
}

.order-template-modal .modal-close {
    position: absolute;
    top: 15px;
    right: 18px;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.order-template-modal .modal-close:hover {
    color: #333;
}

.order-template-modal h3 {
    margin: 0 0 1.2em;
    font-size: 1.3em;
    color: #333;
    padding-right: 30px;
}

.order-template-modal .modal-actions {
    display: flex;
    gap: 0.8em;
    margin-top: 1.5em;
    padding-top: 1.5em;
    border-top: 1px solid #eee;
}

/* =========================================
   Produkte hinzufügen Modal
   ========================================= */

.product-search-wrapper {
    position: relative;
    margin-bottom: 1.2em;
}

.product-search-wrapper input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
}

.product-search-wrapper .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

/* Kategorien-Akkordeon */
.categories-accordion {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 1.2em;
}

.category-group {
    border-bottom: 1px solid #eee;
}

.category-group:last-child {
    border-bottom: none;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 0.5em;
    padding: 12px 16px;
    cursor: pointer;
    background-color: #fafafa;
    transition: background-color 0.2s;
}

.category-header:hover {
    background-color: #f0f0f0;
}

.category-toggle {
    font-size: 0.8em;
    color: #888;
    transition: transform 0.2s;
}

.category-group.expanded > .category-header .category-toggle {
    transform: rotate(90deg);
}

.category-name {
    font-weight: 500;
    flex: 1;
}

.category-count {
    color: #888;
    font-size: 0.9em;
}

.category-products {
    padding: 0;
    background-color: #fff;
}

.products-loading {
    padding: 1em;
    text-align: center;
    color: #888;
}

/* Unterkategorien */
.subcategories {
    padding-left: 1.5em;
}

.subcategory .category-header {
    background-color: #fff;
    padding: 10px 16px;
}

/* Produkt-Liste im Modal */
.product-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.product-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
}

.product-list-item:hover {
    background-color: #f9f9f9;
}

.product-list-item:last-child {
    border-bottom: none;
}

.product-list-item.selected {
    background-color: #e8f5e9;
}

.product-list-item .product-checkbox {
    flex-shrink: 0;
}

.product-list-item .product-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

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

.product-list-item .product-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-list-item .product-sku {
    font-size: 0.85em;
    color: #888;
}

.product-list-item .product-price {
    font-weight: 500;
    color: #333;
    flex-shrink: 0;
}

.product-list-item .already-in-template {
    font-size: 0.8em;
    color: #8BC34A;
    background-color: #e8f5e9;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Ausgewählte Produkte */
.selected-products-wrapper {
    background-color: #f9f9f9;
    border-radius: 8px;
    padding: 1em;
    margin-bottom: 1em;
}

.selected-products-wrapper h4 {
    margin: 0 0 0.8em;
    font-size: 1em;
    color: #333;
}

.selected-products-list {
    max-height: 150px;
    overflow-y: auto;
}

.selected-products-list .no-selection {
    color: #888;
    font-style: italic;
    margin: 0;
}

.selected-product-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background-color: #fff;
    border-radius: 4px;
    margin-bottom: 4px;
}

.selected-product-item .remove-selected {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 2px 6px;
}

.selected-product-item .remove-selected:hover {
    color: #e53935;
}

/* =========================================
   Responsive Anpassungen
   ========================================= */

@media (max-width: 768px) {
    .woocommerce-order-templates {
        padding: 1em;
    }
    
    .woocommerce-order-templates h2 {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.8em;
    }
    
    .woocommerce-order-templates h2 .button {
        margin-left: 0;
    }
    
    .template-header {
        flex-direction: column;
        gap: 1em;
    }
    
    .template-actions {
        width: 100%;
        justify-content: flex-start;
    }
    
    .template-meta {
        flex-direction: column;
        gap: 0.5em;
    }
    
    .template-detail-actions {
        flex-direction: column;
    }
    
    .template-detail-actions .button {
        width: 100%;
        justify-content: center;
    }
    
    .template-items-table .col-thumbnail,
    .template-items-table .col-ve {
        display: none;
    }
    
    .order-template-modal .modal-content {
        width: 95%;
        padding: 1.2em;
        max-height: 95vh;
    }
    
    .order-template-form .form-actions {
        flex-direction: column;
    }
    
    .order-template-form .form-actions .button {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .template-items-table .col-sku,
    .template-items-table .col-price {
        display: none;
    }
    
    .categories-accordion {
        max-height: 200px;
    }
}
