/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* Header */
.signature-header {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.signature-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #333;
}

/* Main Layout */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.app-layout {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 2rem;
    min-height: 600px;
}

/* History Sidebar (Left) */
.history-sidebar {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
}

.history-sidebar h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #333;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 0.5rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    transition: all 0.2s ease;
}

.history-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

.history-item img {
    width: 100%;
    height: 60px;
    object-fit: contain;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    margin-bottom: 0.5rem;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.item-actions button {
    flex: 1;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
}

/* Signature Area (Center) */
.signature-area {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.signature-area h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: #333;
}

.signature-pad {
    border: 2px solid #333;
    border-radius: 8px;
    background: white;
    cursor: crosshair;
    margin-bottom: 1.5rem;
}

.signature-pad:focus {
    outline: 3px solid #007acc;
    outline-offset: 2px;
}

.canvas-controls {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* Settings Sidebar (Right) */
.settings-sidebar {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.pen-settings,
.text-settings {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.pen-settings h3,
.text-settings h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #333;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0.5rem;
}

.setting-group {
    margin-bottom: 1rem;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #555;
    font-size: 0.9rem;
}

.color-swatches {
    display: flex;
    gap: 0.5rem;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #ddd;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.color-swatch.active {
    border-color: #007acc;
    box-shadow: 0 0 0 3px rgba(0,122,204,0.2);
}

.color-swatch:focus {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

select,
input[type="text"] {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

select:focus,
input[type="text"]:focus {
    outline: none;
    border-color: #007acc;
    box-shadow: 0 0 0 3px rgba(0,122,204,0.1);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.checkbox-group label {
    margin: 0;
    font-weight: normal;
}

/* Buttons */
.primary-btn,
.secondary-btn,
.control-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.primary-btn {
    background: #007acc;
    color: white;
}

.primary-btn:hover:not(:disabled) {
    background: #005a9e;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,122,204,0.3);
}

.secondary-btn {
    background: #6c757d;
    color: white;
}

.secondary-btn:hover:not(:disabled) {
    background: #545b62;
    transform: translateY(-1px);
}

.control-btn {
    background: #f8f9fa;
    color: #495057;
    border: 1px solid #dee2e6;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
}

.control-btn:hover:not(:disabled) {
    background: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-1px);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tertiary-btn {
    background: #dc3545;
    color: white;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tertiary-btn:hover {
    background: #c82333;
    transform: translateY(-1px);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}

.modal-header {
    padding: 1.5rem 2rem 1rem;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0.25rem;
    line-height: 1;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 2rem;
}

.signatures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

.signature-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    transition: all 0.2s ease;
}

.signature-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.signature-item img {
    width: 100%;
    height: 80px;
    object-fit: contain;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    margin-bottom: 0.75rem;
}

.signature-preview {
    text-align: center;
    margin-bottom: 2rem;
}

.signature-preview img {
    max-width: 100%;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
}

.preview-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .app-layout {
        grid-template-columns: 250px 1fr 250px;
        gap: 1.5rem;
    }
}

@media (max-width: 1024px) {
    .app-layout {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .history-sidebar,
    .settings-sidebar {
        order: 2;
    }
    
    .signature-area {
        order: 1;
    }
}

@media (max-width: 768px) {
    .main-container {
        padding: 1rem;
    }
    
    .signature-header {
        padding: 1rem;
    }
    
    .signature-header h1 {
        font-size: 1.2rem;
    }
    
    .modal-content {
        margin: 1rem;
        max-width: calc(100vw - 2rem);
    }
    
    .signatures-grid {
        grid-template-columns: 1fr;
    }
    
    .canvas-controls {
        gap: 0.5rem;
    }
    
    .control-btn,
    .primary-btn {
        padding: 0.6rem 1rem;
        font-size: 0.8rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Management */
button:focus,
select:focus,
input:focus {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .modal,
    .signature-header,
    .canvas-controls,
    .history-sidebar,
    .settings-sidebar {
        display: none !important;
    }
}