/**
 * Telegram Widget Styles
 * Designed to match Bitrix24 design system
 */

/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    background: #fff;
}

/* Widget container */
#telegram-widget {
    max-width: 400px;
    margin: 0 auto;
    padding: 16px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

/* Widget header */
.widget-header {
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
}

.widget-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: #2fc6f6;
    margin: 0;
}

/* Recipient info */
.recipient-info {
    margin-bottom: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #2fc6f6;
    display: flex;
    align-items: center;
    gap: 8px;
}

.recipient-info label {
    font-weight: 500;
    color: #666;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.recipient-value {
    font-weight: 600;
    color: #333;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.recipient-value::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
}

.recipient-value.loading::before {
    background: #f59e0b;
    animation: pulse 1.5s ease-in-out infinite;
}

.recipient-value.error::before {
    background: #ef4444;
}

/* Message form */
.message-form {
    margin-bottom: 16px;
}

.template-selector {
    margin-bottom: 8px;
}

.template-selector label,
.message-input label {
    display: block;
    font-weight: 500;
    color: #666;
    margin-bottom: 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-input {
    margin-bottom: 16px;
}

#template-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 32px;
    appearance: none;
}

#template-select:hover {
    border-color: #9ca3af;
    background-color: #f9fafb;
}

#template-select:focus {
    outline: none;
    border-color: #2fc6f6;
    box-shadow: 0 0 0 3px rgba(47, 198, 246, 0.1);
    background-color: #fff;
}

#template-select:disabled {
    background-color: #f3f4f6;
    color: #9ca3af;
    cursor: not-allowed;
}

/* Template select optgroups */
#template-select optgroup {
    font-weight: 600;
    color: #374151;
    font-size: 13px;
    padding: 4px 0;
}

#template-select option {
    padding: 8px 12px;
    font-weight: 400;
    color: #333;
    background: #fff;
}

#template-select option:hover {
    background: #f3f4f6;
}

/* Template selector enhancements */
.template-selector {
    position: relative;
}

.template-info {
    margin-top: 4px;
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
    min-height: 16px;
    transition: opacity 0.2s ease;
}

.template-info.hidden {
    opacity: 0;
}

/* Template preview tooltip */
.template-preview {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 12px;
    margin-top: 4px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 10;
    font-size: 13px;
    line-height: 1.4;
    color: #374151;
    max-height: 120px;
    overflow-y: auto;
    display: none;
}

.template-preview.show {
    display: block;
    animation: fadeIn 0.2s ease;
}

.template-preview::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #d1d5db;
}

.template-preview::after {
    content: '';
    position: absolute;
    top: -5px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #fff;
}

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

#message-text {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: all 0.2s ease;
    line-height: 1.5;
}

#message-text:hover {
    border-color: #9ca3af;
}

#message-text:focus {
    outline: none;
    border-color: #2fc6f6;
    box-shadow: 0 0 0 3px rgba(47, 198, 246, 0.1);
}

#message-text::placeholder {
    color: #9ca3af;
}

/* Form actions */
.form-actions {
    display: flex;
    justify-content: flex-end;
}

#send-button {
    padding: 10px 20px;
    background: #2fc6f6;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#send-button:hover {
    background: #1fb5e5;
}

#send-button:active {
    background: #1a9bc7;
}

#send-button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

#send-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 198, 246, 0.3);
}

#send-button.loading {
    position: relative;
    color: transparent;
}

#send-button.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Notifications */
.notifications {
    position: relative;
}

.notification {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 14px;
    animation: slideIn 0.3s ease;
}

.notification.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.notification.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.notification.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.notification.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.notification .close-btn {
    float: right;
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0;
    margin-left: 8px;
}

.notification .close-btn:hover {
    opacity: 1;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2fc6f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

.loading-text {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Responsive design */
@media (max-width: 480px) {
    #telegram-widget {
        margin: 0;
        border: none;
        border-radius: 0;
        padding: 12px;
        max-width: none;
    }
    
    .widget-header h3 {
        font-size: 14px;
    }
    
    .recipient-info {
        padding: 10px;
        margin-bottom: 12px;
    }
    
    .template-selector,
    .message-input {
        margin-bottom: 8px;
    }
    
    #message-text {
        min-height: 150px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .form-actions {
        justify-content: stretch;
    }
    
    #send-button {
        width: 100%;
        padding: 12px 20px;
        font-size: 16px;
    }
    
    .notification {
        padding: 10px;
        font-size: 13px;
    }
}

@media (max-width: 320px) {
    #telegram-widget {
        padding: 8px;
    }
    
    .recipient-info {
        padding: 8px;
    }
    
    #message-text {
        padding: 10px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    #telegram-widget {
        border-color: #000;
    }
    
    #template-select,
    #message-text {
        border-color: #000;
    }
    
    #send-button {
        border: 2px solid #000;
    }
}

/* Form validation states */
.invalid {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.valid {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

.recipient-value.invalid::before {
    background: #ef4444;
}

.recipient-value.valid::before {
    background: #10b981;
}

/* Enhanced notification styles */
.notification {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.4;
    animation: slideIn 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.notification::before {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 50%;
    margin-top: 6px;
    flex-shrink: 0;
}

.notification.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.notification.success::before {
    background: #10b981;
}

.notification.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.notification.error::before {
    background: #ef4444;
}

.notification.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.notification.warning::before {
    background: #f59e0b;
}

.notification.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.notification.info::before {
    background: #3b82f6;
}

.notification .close-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0;
    margin-left: auto;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.notification .close-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

.notification .close-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2);
}

/* Notification container positioning */
#notifications {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    max-width: 400px;
    width: 100%;
}

@media (max-width: 480px) {
    #notifications {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
/* ===
=========================================
   Auth Status Section Styles
   ============================================ */

.auth-status {
    margin-bottom: 16px;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #2fc6f6;
}

.auth-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.status-icon {
    font-size: 16px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-icon.status-success {
    color: #10b981;
}

.status-icon.status-error {
    color: #ef4444;
}

.status-text {
    font-size: 14px;
    font-weight: 500;
    color: #666;
}

/* Auth button */
.btn-auth {
    width: 100%;
    padding: 10px 16px;
    background: #2fc6f6;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-auth:hover {
    background: #1fb5e5;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(47, 198, 246, 0.3);
}

.btn-auth:active {
    background: #1a9bc7;
    transform: translateY(0);
}

.btn-auth:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 198, 246, 0.3);
}

/* Account info */
.account-info {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
}

.account-label {
    font-size: 12px;
    font-weight: 500;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    align-self: start;
    padding-top: 2px;
}

.account-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.account-name {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    line-height: 1.2;
}

.account-phone {
    font-size: 12px;
    color: #666;
    line-height: 1.2;
}

.btn-logout {
    padding: 6px 12px;
    background: #fff;
    color: #ef4444;
    border: 1px solid #ef4444;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-logout:hover {
    background: #ef4444;
    color: #fff;
}

.btn-logout:active {
    background: #dc2626;
}

.btn-logout:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

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

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

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

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #9ca3af;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: #f3f4f6;
    color: #333;
}

.modal-close:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.3);
}

.modal-body {
    padding: 20px;
}

/* Auth steps */
.auth-step {
    animation: fadeIn 0.3s ease;
}

.auth-step p {
    margin-bottom: 16px;
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

.auth-step input {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 16px;
    transition: all 0.2s ease;
}

.auth-step input:hover {
    border-color: #9ca3af;
}

.auth-step input:focus {
    outline: none;
    border-color: #2fc6f6;
    box-shadow: 0 0 0 3px rgba(47, 198, 246, 0.1);
}

.auth-step input::placeholder {
    color: #9ca3af;
}

/* Modal buttons */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 8px;
}

.btn-primary {
    background: #2fc6f6;
    color: #fff;
}

.btn-primary:hover {
    background: #1fb5e5;
}

.btn-primary:active {
    background: #1a9bc7;
}

.btn-primary:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 198, 246, 0.3);
}

.btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    background: #fff;
    color: #666;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-secondary:active {
    background: #f3f4f6;
}

.btn-secondary:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.2);
}

/* Error message in modal */
.error-message {
    padding: 12px;
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    font-size: 13px;
    margin-top: 12px;
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Loading indicator in modal */
.modal-body .loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    color: #666;
    font-size: 14px;
}

.modal-body .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2fc6f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ============================================
   Responsive Styles for Auth UI
   ============================================ */

@media (max-width: 480px) {
    .modal {
        padding: 0;
        align-items: flex-end;
    }
    
    .modal-content {
        max-width: none;
        border-radius: 16px 16px 0 0;
        max-height: 80vh;
    }
    
    .modal-header {
        padding: 16px;
    }
    
    .modal-header h3 {
        font-size: 16px;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .auth-status {
        padding: 10px;
        margin-bottom: 12px;
    }
    
    .account-info {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .btn-logout {
        width: 100%;
        padding: 8px 12px;
    }
    
    .auth-step input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

@media (max-width: 320px) {
    .modal-header {
        padding: 12px;
    }
    
    .modal-body {
        padding: 12px;
    }
    
    .auth-step p {
        font-size: 13px;
    }
}

/* ============================================
   Accessibility Enhancements
   ============================================ */

/* Focus visible for keyboard navigation */
.btn-auth:focus-visible,
.btn-logout:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.modal-close:focus-visible {
    outline: 2px solid #2fc6f6;
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .auth-status {
        border-color: #000;
    }
    
    .btn-auth,
    .btn-primary {
        border: 2px solid #000;
    }
    
    .btn-logout,
    .btn-secondary {
        border: 2px solid currentColor;
    }
    
    .modal-content {
        border: 2px solid #000;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .modal,
    .modal-content,
    .auth-step,
    .error-message {
        animation: none;
    }
    
    .btn-auth:hover {
        transform: none;
    }
}

/* Dark mode support (if needed in future) */
@media (prefers-color-scheme: dark) {
    .auth-status {
        background: #1f2937;
        border-left-color: #2fc6f6;
    }
    
    .status-text {
        color: #d1d5db;
    }
    
    .account-name {
        color: #f3f4f6;
    }
    
    .account-phone {
        color: #9ca3af;
    }
}
