/**
 * cTickets Widget Styles
 * @version 1.0.0
 * Изолированные стили с namespace 'ctw'
 */

:root {
    --ctw-primary: #1D6385;
    --ctw-accent: #509DC2;
    --ctw-error: #ef4444;
    --ctw-success: #10b981;
    --ctw-warning: #f59e0b;
    --ctw-text: #1f2937;
    --ctw-text-light: #6b7280;
    --ctw-bg: #ffffff;
    --ctw-bg-secondary: #f8f9fa;
    --ctw-bg-tertiary: #f1f3f5;
    --ctw-border: #dee2e6;
    --ctw-border-focus: #1D6385;
    --ctw-shadow: rgba(0, 0, 0, 0.08);
    --ctw-shadow-lg: rgba(0, 0, 0, 0.12);
    --ctw-overlay: rgba(0, 0, 0, 0.5);
    --ctw-radius: 8px;
    --ctw-radius-lg: 12px;
    --ctw-transition: all 0.2s ease;
}

/* Reset для изоляции стилей */
.ctw-modal *,
.ctw-card *,
.ctw-button {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Кнопка виджета */
.ctw-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.5;
    text-decoration: none;
    color: #ffffff;
    background: linear-gradient(135deg, var(--ctw-primary) 0%, var(--ctw-accent) 100%);
    border: none;
    border-radius: var(--ctw-radius);
    cursor: pointer;
    transition: var(--ctw-transition);
    box-shadow: 0 4px 12px rgba(29, 99, 133, 0.3);
}

.ctw-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(29, 99, 133, 0.4);
}

.ctw-button:active {
    transform: translateY(0);
}

/* Модальное окно */
.ctw-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transition: var(--ctw-transition);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.ctw-modal.active {
    opacity: 1;
    visibility: visible;
}

.ctw-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--ctw-overlay);
    backdrop-filter: blur(4px);
}

.ctw-modal-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    background: #ffffff;
    border-radius: var(--ctw-radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ctw-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px;
    border-bottom: 1px solid #e9ecef;
    background: #ffffff;
}

.ctw-modal-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--ctw-text);
    margin: 0;
}

.ctw-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--ctw-text-light);
    cursor: pointer;
    transition: var(--ctw-transition);
}

.ctw-modal-close:hover {
    background: var(--ctw-border);
    color: var(--ctw-text);
}

.ctw-modal-body {
    padding: 28px;
    overflow-y: auto;
    flex: 1;
    background: #ffffff;
}

/* Loader */
.ctw-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

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

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

/* Событие */
.ctw-event {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ctw-event-image {
    width: 100%;
    border-radius: var(--ctw-radius);
    overflow: hidden;
    aspect-ratio: 16/9;
}

.ctw-event-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ctw-event-info {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ctw-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 6px;
    width: fit-content;
}

.ctw-badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--ctw-success);
}

.ctw-badge-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--ctw-error);
}

.ctw-badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--ctw-warning);
}

.ctw-event-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ctw-event-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ctw-text-light);
    font-size: 14px;
}

.ctw-event-detail svg {
    flex-shrink: 0;
    color: var(--ctw-primary);
}

.ctw-event-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--ctw-primary);
}

.ctw-event-description {
    color: var(--ctw-text-light);
    font-size: 14px;
    line-height: 1.6;
}

.ctw-event-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.ctw-event-footer {
    padding-top: 16px;
    border-top: 1px solid var(--ctw-border);
    text-align: center;
    font-size: 12px;
    color: var(--ctw-text-light);
}

.ctw-event-footer a {
    color: var(--ctw-primary);
    text-decoration: none;
    font-weight: 600;
}

.ctw-event-footer a:hover {
    text-decoration: underline;
}

/* Кнопки */
.ctw-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--ctw-radius);
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    flex: 1;
    font-family: inherit;
}

.ctw-btn-primary {
    background: var(--ctw-primary);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(29, 99, 133, 0.2);
}

.ctw-btn-primary:hover {
    background: #1a5a7a;
    box-shadow: 0 4px 12px rgba(29, 99, 133, 0.3);
    transform: translateY(-1px);
}

.ctw-btn-primary:active {
    transform: translateY(0);
}

.ctw-btn-primary[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background: #adb5bd;
}

.ctw-btn-secondary {
    background: #ffffff;
    color: var(--ctw-primary);
    border: 1px solid #dee2e6;
}

.ctw-btn-secondary:hover {
    background: #f8f9fa;
    border-color: var(--ctw-primary);
}

.ctw-btn-block {
    width: 100%;
}

/* Ошибка */
.ctw-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--ctw-text);
}

.ctw-error svg {
    color: var(--ctw-error);
    margin-bottom: 16px;
}

.ctw-error h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.ctw-error p {
    font-size: 14px;
    color: var(--ctw-text-light);
}

/* Карточка события */
.ctw-card {
    display: flex;
    flex-direction: column;
    background: var(--ctw-bg);
    border: 1px solid var(--ctw-border);
    border-radius: var(--ctw-radius);
    overflow: hidden;
    transition: var(--ctw-transition);
    box-shadow: 0 2px 8px var(--ctw-shadow);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.ctw-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--ctw-shadow);
}

.ctw-card-image {
    width: 100%;
    aspect-ratio: 16/9;
    overflow: hidden;
}

.ctw-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ctw-card-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ctw-card-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--ctw-text);
    line-height: 1.4;
}

.ctw-card-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    color: var(--ctw-text-light);
}

.ctw-card-price {
    font-size: 20px;
    font-weight: 700;
    color: var(--ctw-primary);
}

/* Адаптивность */
@media (max-width: 640px) {
    .ctw-modal-container {
        width: 95%;
        max-height: 95vh;
    }

    .ctw-modal-header {
        padding: 16px 20px;
    }

    .ctw-modal-title {
        font-size: 18px;
    }

    .ctw-modal-body {
        padding: 20px;
    }

    .ctw-event-actions {
        flex-direction: column;
    }

    .ctw-btn {
        width: 100%;
    }

    .ctw-event-image {
        aspect-ratio: 4/3;
    }
}

/* Анимации */
.ctw-modal.active .ctw-modal-container {
    animation: ctw-slideUp 0.3s ease;
}

@keyframes ctw-slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* Accessibility */
.ctw-modal:focus-visible,
.ctw-btn:focus-visible,
.ctw-button:focus-visible {
    outline: 2px solid var(--ctw-primary);
    outline-offset: 2px;
}

.ctw-modal-close:focus-visible {
    outline: 2px solid var(--ctw-primary);
    outline-offset: 2px;
}

/* Checkout Flow Styles */

/* Step Indicator */
.ctw-step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--ctw-border);
}

.ctw-step {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    background: var(--ctw-bg-secondary);
    color: var(--ctw-text-light);
    border: 2px solid var(--ctw-border);
    transition: var(--ctw-transition);
}

.ctw-step.active {
    background: linear-gradient(135deg, var(--ctw-primary) 0%, var(--ctw-accent) 100%);
    color: #ffffff;
    border-color: var(--ctw-primary);
    box-shadow: 0 2px 8px rgba(29, 99, 133, 0.3);
}

.ctw-step.completed {
    background: var(--ctw-success);
    color: #ffffff;
    border-color: var(--ctw-success);
}

/* Checkout Step */
.ctw-checkout-step {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ctw-step-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--ctw-text);
    margin: 0 0 16px 0;
}

/* Event Meta Compact */
.ctw-event-image-small {
    width: 100%;
    border-radius: var(--ctw-radius);
    overflow: hidden;
    aspect-ratio: 21/9;
    margin-bottom: 12px;
}

.ctw-event-image-small img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ctw-event-meta-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--ctw-bg-secondary);
    border-radius: var(--ctw-radius);
}

.ctw-meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--ctw-text-light);
}

.ctw-meta-item svg {
    flex-shrink: 0;
    color: var(--ctw-primary);
}

/* Ticket Types */
.ctw-ticket-types {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ctw-ticket-type {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: var(--ctw-radius);
    gap: 20px;
    transition: all 0.2s ease;
}

.ctw-ticket-type:hover {
    border-color: #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.ctw-ticket-info {
    flex: 1;
}

.ctw-ticket-info h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--ctw-text);
    margin-bottom: 4px;
}

.ctw-ticket-desc {
    font-size: 13px;
    color: var(--ctw-text-light);
    margin-bottom: 8px;
}

.ctw-ticket-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--ctw-primary);
}

.ctw-ticket-limited {
    font-size: 12px;
    color: var(--ctw-warning);
    font-weight: 600;
    margin-top: 4px;
}

/* Quantity Controls */
.ctw-ticket-quantity {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctw-qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: #f8f9fa;
    color: #495057;
    border: 1px solid #dee2e6;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.ctw-qty-btn:hover {
    background: #e9ecef;
    border-color: #ced4da;
    color: #212529;
}

.ctw-qty-btn:active {
    background: #dee2e6;
    transform: scale(0.95);
}

.ctw-qty-input {
    width: 60px;
    height: 36px;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #ffffff;
    color: #212529;
    padding: 0;
}

.ctw-qty-input:focus {
    outline: none;
    border-color: var(--ctw-primary);
    box-shadow: 0 0 0 3px rgba(29, 99, 133, 0.1);
}

/* Step Summary */
.ctw-step-summary {
    padding: 20px;
    background: #f8f9fa;
    border-radius: var(--ctw-radius);
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid #e9ecef;
}

.ctw-summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--ctw-text);
}

.ctw-summary-total {
    font-size: 18px;
    font-weight: 700;
    padding-top: 8px;
    border-top: 1px solid var(--ctw-border);
    color: var(--ctw-primary);
}

.ctw-summary-discount {
    color: var(--ctw-success);
}

/* Step Actions */
.ctw-step-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

/* Cart Items */
.ctw-cart-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ctw-cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--ctw-bg-secondary);
    border-radius: var(--ctw-radius);
}

.ctw-cart-item-info h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--ctw-text);
    margin-bottom: 4px;
}

.ctw-cart-item-info p {
    font-size: 13px;
    color: var(--ctw-text-light);
}

.ctw-cart-item-total {
    font-size: 16px;
    font-weight: 700;
    color: var(--ctw-primary);
}

/* Promocode Section */
.ctw-promocode-section {
    padding: 16px;
    background: var(--ctw-bg-secondary);
    border-radius: var(--ctw-radius);
}

.ctw-promocode-section h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--ctw-text);
    margin-bottom: 12px;
}

.ctw-promocode-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.ctw-input {
    flex: 1;
    padding: 12px 16px;
    font-size: 15px;
    line-height: 1.5;
    border: 1px solid #dee2e6;
    border-radius: var(--ctw-radius);
    background: #ffffff;
    color: #212529;
    transition: all 0.2s ease;
    font-family: inherit;
}

.ctw-input:focus {
    outline: none;
    border-color: var(--ctw-primary);
    box-shadow: 0 0 0 3px rgba(29, 99, 133, 0.1);
    background: #ffffff;
}

.ctw-input:disabled {
    background: #f8f9fa;
    opacity: 0.6;
    cursor: not-allowed;
    border-color: #e9ecef;
}

.ctw-input::placeholder {
    color: #adb5bd;
}

/* Messages */
.ctw-message {
    padding: 10px 12px;
    font-size: 13px;
    border-radius: 8px;
    margin-top: 8px;
}

.ctw-message-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--ctw-success);
    border: 1px solid var(--ctw-success);
}

.ctw-message-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--ctw-error);
    border: 1px solid var(--ctw-error);
}

.ctw-message-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--ctw-warning);
    border: 1px solid var(--ctw-warning);
}

/* Cart Summary */
.ctw-cart-summary {
    padding: 20px;
    background: #f8f9fa;
    border-radius: var(--ctw-radius);
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid #e9ecef;
}

/* Form Styles */
.ctw-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ctw-form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.ctw-form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ctw-form-group label {
    font-size: 14px;
    font-weight: 600;
    color: #212529;
    margin-bottom: 4px;
}

.ctw-form-group small {
    font-size: 12px;
    color: #6c757d;
    margin-top: -4px;
}

/* Checkbox */
.ctw-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--ctw-text);
}

.ctw-checkbox input[type="checkbox"] {
    margin-top: 2px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--ctw-primary);
}

.ctw-checkbox a {
    color: var(--ctw-primary);
    text-decoration: underline;
}

/* Payment Container */
.ctw-payment-container {
    padding: 24px;
    background: var(--ctw-bg-secondary);
    border-radius: var(--ctw-radius);
    text-align: center;
}

.ctw-payment-info {
    padding: 16px;
    background: var(--ctw-bg-secondary);
    border-radius: var(--ctw-radius);
    margin-bottom: 16px;
}

.ctw-payment-info p {
    font-size: 14px;
    color: var(--ctw-text-light);
    margin-bottom: 8px;
}

.ctw-payment-info p:last-child {
    margin-bottom: 0;
}

/* Success Screen */
.ctw-checkout-step.ctw-success {
    text-align: center;
    padding: 20px 0;
}

.ctw-success-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.ctw-success-icon svg {
    color: var(--ctw-success);
}

.ctw-success-message {
    margin: 20px 0;
}

.ctw-success-message p {
    font-size: 14px;
    color: var(--ctw-text-light);
    margin-bottom: 8px;
}

.ctw-success-message strong {
    color: var(--ctw-text);
}

/* Empty State */
.ctw-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--ctw-text-light);
}

/* Badge Info */
.ctw-badge-info {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

/* Responsive для checkout */
@media (max-width: 640px) {
    .ctw-form-row {
        grid-template-columns: 1fr;
    }

    .ctw-ticket-type {
        flex-direction: column;
        align-items: flex-start;
    }

    .ctw-ticket-quantity {
        width: 100%;
        justify-content: flex-end;
    }

    .ctw-step-actions {
        flex-direction: column;
    }

    .ctw-step-actions .ctw-btn {
        width: 100%;
    }

    .ctw-promocode-input-group {
        flex-direction: column;
    }

    .ctw-promocode-input-group .ctw-btn {
        width: 100%;
    }

    .ctw-event-meta-compact {
        flex-direction: column;
        gap: 8px;
    }
}

/* Print styles */
@media print {
    .ctw-modal {
        display: none !important;
    }
}
