/**
 * Modern Signature Modal - CSS
 * Inspired by DocuSign, HelloSign, Stripe Checkout, and Linear
 * 
 * Features:
 * - Glassmorphism backdrop
 * - Smooth animations
 * - Mobile-optimized (bottom sheet)
 * - Accessibility support
 * - Company Dashboard theme colors
 */

/* ==========================================
   Design Tokens
   ========================================== */

:root {
    --signature-overlay-bg: rgba(15, 23, 42, 0.8);
    --signature-modal-bg: #ffffff;
    --signature-primary: #0f172a;
    --signature-border: #e2e8f0;
    --signature-success: #10b981;
    --signature-error: #ef4444;
    --signature-warning: #f59e0b;
    --signature-focus: #3b82f6;
    --signature-text: #334155;
    --signature-text-muted: #64748b;
}

/* ==========================================
   Modal Overlay & Container
   ========================================== */

.signature-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--signature-overlay-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    
    /* Animation */
    opacity: 0;
    transition: opacity 0.3s ease;
}

.signature-modal-overlay.active {
    opacity: 1;
}

/* Modal Container */
.signature-modal {
    background: var(--signature-modal-bg);
    border: 1px solid var(--signature-border);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    
    /* Animation */
    transform: scale(0.95) translateY(10px);
    transition: transform 0.3s ease;
}

.signature-modal-overlay.active .signature-modal {
    transform: scale(1) translateY(0);
}

/* Custom scrollbar */
.signature-modal::-webkit-scrollbar {
    width: 8px;
}

.signature-modal::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.signature-modal::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.signature-modal::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ==========================================
   Modal Header
   ========================================== */

.signature-modal-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 2rem 2rem 1.5rem 2rem;
    border-bottom: 1px solid var(--signature-border);
}

.signature-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.signature-icon i {
    width: 24px;
    height: 24px;
    color: white;
}

.signature-modal-header h2 {
    flex: 1;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--signature-primary);
    margin: 0;
}

.btn-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--signature-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-close:hover {
    background: #f1f5f9;
    color: var(--signature-primary);
}

.btn-close:focus {
    outline: 2px solid var(--signature-focus);
    outline-offset: 2px;
}

.btn-close i {
    width: 20px;
    height: 20px;
}

/* ==========================================
   Document Info
   ========================================== */

.signature-document-info {
    padding: 1.5rem 2rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--signature-border);
}

.document-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--signature-primary);
    margin-bottom: 0.5rem;
}

.document-meta {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.document-meta span {
    font-size: 0.875rem;
    color: var(--signature-text-muted);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.document-meta span:not(:last-child)::after {
    content: '•';
    margin-left: 1rem;
    color: var(--signature-border);
}

/* ==========================================
   Security Badge
   ========================================== */

.signature-security-badge {
    padding: 1rem 2rem;
    background: #ecfdf5;
    border-left: 4px solid var(--signature-success);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 2rem;
    border-radius: 8px;
}

.signature-security-badge i {
    width: 20px;
    height: 20px;
    color: var(--signature-success);
    flex-shrink: 0;
}

.signature-security-badge span {
    font-size: 0.875rem;
    font-weight: 600;
    color: #065f46;
}

/* ==========================================
   Form
   ========================================== */

.signature-form {
    padding: 0 2rem;
}

.signature-form-group {
    margin-bottom: 1.5rem;
}

.signature-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--signature-primary);
    margin-bottom: 0.5rem;
}

.required {
    color: var(--signature-error);
    margin-left: 0.25rem;
}

.signature-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--signature-primary);
    background: white;
    border: 2px solid var(--signature-border);
    border-radius: 8px;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.signature-input::placeholder {
    color: #94a3b8;
}

.signature-input:hover {
    border-color: #cbd5e1;
}

.signature-input:focus {
    outline: none;
    border-color: var(--signature-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Input validation states */
.signature-input.valid {
    border-color: var(--signature-success);
    background: #f0fdf4;
}

.signature-input.error {
    border-color: var(--signature-error);
    background: #fef2f2;
}

.signature-helper-text {
    margin: 0.5rem 0 0 0;
    font-size: 0.75rem;
    color: var(--signature-text-muted);
    line-height: 1.4;
}

.signature-error {
    margin: 0.5rem 0 0 0;
    font-size: 0.75rem;
    color: var(--signature-error);
    font-weight: 500;
    display: block;
    min-height: 1rem;
}

/* ==========================================
   Consent Checkbox
   ========================================== */

.signature-consent-wrapper {
    margin-bottom: 1.5rem;
}

.signature-consent {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid var(--signature-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.signature-consent:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.signature-consent input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 2px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--signature-primary);
}

.signature-consent label {
    font-size: 0.875rem;
    color: var(--signature-text);
    line-height: 1.5;
    cursor: pointer;
}

/* ==========================================
   Footer Actions
   ========================================== */

.signature-modal-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--signature-border);
}

.btn-cancel,
.btn-sign {
    flex: 1;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.btn-cancel {
    background: white;
    color: var(--signature-text);
    border: 2px solid var(--signature-border);
}

.btn-cancel:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-cancel:focus {
    outline: 2px solid var(--signature-focus);
    outline-offset: 2px;
}

.btn-sign {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-sign:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.btn-sign:focus {
    outline: 2px solid var(--signature-focus);
    outline-offset: 2px;
}

.btn-sign:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-sign i {
    width: 18px;
    height: 18px;
}

/* Loading state */
.btn-sign.loading {
    pointer-events: none;
}

.btn-sign.loading i {
    animation: spin 1s linear infinite;
}

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

/* ==========================================
   Audit Trail Info
   ========================================== */

.signature-audit-info {
    padding: 1rem 2rem 2rem 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--signature-text-muted);
}

.signature-audit-info i {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ==========================================
   Success State
   ========================================== */

.signature-success {
    text-align: center;
    padding: 3rem 2rem;
}

.success-checkmark {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: scaleIn 0.5s ease;
}

.success-checkmark i {
    width: 48px;
    height: 48px;
    color: white;
    animation: checkmarkPop 0.5s ease 0.2s both;
}

@keyframes scaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes checkmarkPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.signature-success h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--signature-primary);
    margin: 0 0 0.5rem 0;
}

.signature-success p {
    font-size: 1rem;
    color: var(--signature-text-muted);
    margin: 0;
}

/* ==========================================
   Error Banner
   ========================================== */

.signature-error-banner {
    padding: 1rem 1.5rem;
    margin: 1.5rem 2rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid var(--signature-error);
    border-radius: 8px;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: slideDown 0.3s ease;
}

.signature-error-banner.fade-out {
    animation: fadeOut 0.3s ease;
    opacity: 0;
}

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

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.signature-error-banner i {
    width: 20px;
    height: 20px;
    color: var(--signature-error);
    flex-shrink: 0;
    margin-top: 2px;
}

.signature-error-banner p {
    flex: 1;
    font-size: 0.875rem;
    color: #991b1b;
    margin: 0;
    line-height: 1.5;
}

/* ==========================================
   Mobile Optimization
   ========================================== */

@media (max-width: 768px) {
    /* Bottom sheet style on mobile */
    .signature-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    
    .signature-modal {
        max-width: 100%;
        max-height: 85vh;
        border-radius: 24px 24px 0 0;
        margin: 0;
        transform: translateY(100%);
    }
    
    .signature-modal-overlay.active .signature-modal {
        transform: translateY(0);
    }
    
    /* Larger tap targets */
    .btn-close {
        width: 44px;
        height: 44px;
    }
    
    .signature-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .btn-cancel,
    .btn-sign {
        padding: 1rem 1.5rem;
        min-height: 48px;
    }
    
    /* Adjust padding */
    .signature-modal-header {
        padding: 1.5rem 1.5rem 1rem 1.5rem;
    }
    
    .signature-document-info {
        padding: 1rem 1.5rem;
    }
    
    .signature-security-badge {
        margin: 1rem 1.5rem;
        padding: 0.875rem 1rem;
    }
    
    .signature-form {
        padding: 0 1.5rem;
    }
    
    .signature-modal-footer {
        padding: 1.25rem 1.5rem;
    }
    
    .signature-audit-info {
        padding: 0.875rem 1.5rem 1.5rem 1.5rem;
    }
}

@media (max-width: 480px) {
    .signature-modal-header h2 {
        font-size: 1.25rem;
    }
    
    .document-title {
        font-size: 1rem;
    }
    
    /* Stack buttons on very small screens */
    .signature-modal-footer {
        flex-direction: column-reverse;
    }
    
    .btn-cancel,
    .btn-sign {
        width: 100%;
    }
}

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

/* Focus visible styles */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .signature-modal {
        border: 2px solid currentColor;
    }
    
    .signature-input:focus {
        outline: 3px solid currentColor;
        outline-offset: 2px;
    }
    
    .btn-sign {
        border: 2px solid currentColor;
    }
}

/* ==========================================
   Mobile (max-width 768px) - touch targets, safe-area
   ========================================== */

@media (max-width: 768px) {
    .signature-modal {
        max-height: 88vh;
        overflow-y: auto;
    }

    .signature-modal .btn-close {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }

    .signature-modal-footer,
    .signature-modal [class*="footer"] {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    .signature-modal .btn-sign,
    .signature-modal button[type="submit"],
    .signature-modal .btn-primary {
        min-height: 44px;
        padding: 12px 20px;
    }
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus trap for keyboard navigation */
.signature-modal:focus {
    outline: none;
}
