/* Variables for Siemens color theme */
:root {
    --siemens-corporate-blue: #003366;
    /* Deep blue for header, CTAs */
    --siemens-light-gray: #f4f4f4;
    /* Background gray */
    --siemens-white: #ffffff;
    /* Card backgrounds, text */
    --siemens-dark-gray: #0f0f0f;
    /* Main text color */
    --siemens-accent-teal: #009999;
    /* Accent color (teal) */

    --shadow-light: 0 4px 10px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 6px 15px rgba(0, 0, 0, 0.12);

    --border-radius-card: 12px;
    --border-radius-elements: 8px;

    --font-family-primary: 'Open Sans', 'Roboto', Arial, sans-serif;
}

/* General Body Styles */
body {
    font-family: var(--font-family-primary);
    margin: 0;
    padding: 0;
    background-color: var(--siemens-light-gray);
    color: var(--siemens-dark-gray);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Header */
header {
    background-color: var(--siemens-corporate-blue);
    color: var(--siemens-white);
    padding: 1.8rem 1rem;
    text-align: center;
    box-shadow: var(--shadow-medium);
}

header h1 {
    margin: 0;
    font-size: 2.8rem;
    font-weight: 700;
}

header .tagline {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-top: 0.5rem;
}

/* Main Container */
.container {
    max-width: 1000px;
    /* Wider for viewer */
    margin: 2.5rem auto;
    padding: 1.2rem;
    flex-grow: 1;
}

/* Card Styles */
.card {
    background-color: var(--siemens-white);
    padding: 2.5rem;
    margin-bottom: 2rem;
    border-radius: var(--border-radius-card);
    box-shadow: var(--shadow-light);
    transition: transform 0.3s ease-in-out;
}

.card:hover:not(#signer-section) {
    /* Don't transform signer section on hover */
    transform: translateY(-3px);
}

.section-title {
    color: var(--siemens-corporate-blue);
    margin-top: 0;
    margin-bottom: 2rem;
    font-size: 2.2rem;
    font-weight: 600;
    border-bottom: 3px solid var(--siemens-accent-teal);
    padding-bottom: 0.8rem;
}

/* Drag and Drop Area */
.drag-drop-area {
    border: 3px dashed var(--siemens-medium-gray);
    border-radius: var(--border-radius-card);
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: rgba(0, 153, 153, 0.03);
    /* Very light tint of teal */
}

.drag-drop-area:hover,
.drag-drop-area.drag-over {
    border-color: var(--siemens-accent-teal);
    background-color: rgba(0, 153, 153, 0.08);
}

.drag-drop-area p {
    margin-bottom: 1.5rem;
    color: var(--siemens-dark-gray);
    font-size: 1.2rem;
    font-weight: 500;
}

/* Buttons */
.btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: var(--border-radius-elements);
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background-color: var(--siemens-accent-teal);
    color: var(--siemens-white);
    box-shadow: 0 4px 8px rgba(0, 153, 153, 0.3);
}

.btn-primary:not(:disabled):hover {
    background-color: #007a7a;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 153, 153, 0.4);
}

.btn-cta {
    background-color: var(--siemens-corporate-blue);
    color: var(--siemens-white);
    box-shadow: 0 4px 8px rgba(0, 51, 102, 0.3);
}

.btn-cta:not(:disabled):hover {
    background-color: #002244;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 51, 102, 0.4);
}

.btn-secondary {
    background-color: var(--siemens-medium-gray);
    color: var(--siemens-dark-gray);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.btn-secondary:not(:disabled):hover {
    background-color: #b3b3b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.button-group {
    display: flex;
    gap: 1.5rem;
    margin-top: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* File Info */
.file-info {
    margin-top: 1rem;
    font-style: italic;
    color: var(--siemens-dark-gray);
    text-align: center;
}

/* Signature Toolbar */
.signature-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: var(--siemens-light-gray);
    border-radius: var(--border-radius-elements);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tool-btn {
    background-color: var(--siemens-white);
    border: 1px solid var(--siemens-medium-gray);
    border-radius: 5px;
    padding: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--siemens-dark-gray);
}

.tool-btn:hover {
    background-color: var(--siemens-accent-teal);
    color: var(--siemens-white);
    border-color: var(--siemens-accent-teal);
    transform: translateY(-1px);
}

.tool-btn.active {
    background-color: var(--siemens-corporate-blue);
    color: var(--siemens-white);
    border-color: var(--siemens-corporate-blue);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.tool-btn svg {
    width: 20px;
    height: 20px;
}

/* Signature Creation Area */
.signature-creation-area {
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px dashed var(--siemens-medium-gray);
    text-align: center;
    border-radius: var(--border-radius-elements);
    background-color: var(--siemens-light-gray);
}

#signature-pad-canvas {
    border: 1px solid var(--siemens-medium-gray);
    background-color: var(--siemens-white);
    max-width: 100%;
    height: 150px;
    /* Fixed height for drawing area */
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.signature-controls {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.signature-controls input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border: none;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 5px;
    cursor: pointer;
}

.signature-controls input[type="color"]::-webkit-color-swatch {
    border-radius: 5px;
    border: none;
}

.signature-controls input[type="color"]::-moz-color-swatch {
    border-radius: 5px;
    border: none;
}

.signature-controls input[type="text"] {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--siemens-medium-gray);
    border-radius: var(--border-radius-elements);
    font-size: 1rem;
    flex-grow: 1;
    /* Allow input to grow */
    max-width: 300px;
}

.signature-controls select {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--siemens-medium-gray);
    border-radius: var(--border-radius-elements);
    font-size: 1rem;
}

#typed-signature-preview {
    font-family: 'Dancing Script', cursive;
    /* Example Google Font */
    font-size: 3em;
    color: #000;
    margin-top: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#uploaded-signature-img-preview {
    max-width: 200px;
    max-height: 150px;
    height: auto;
    border: 1px solid var(--siemens-medium-gray);
    border-radius: var(--border-radius-elements);
    margin: 1rem auto;
    display: block;
    object-fit: contain;
}

/* PDF Viewer and Placement Area */
.page-navigation-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: var(--siemens-light-gray);
    border-radius: var(--border-radius-elements);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.page-info {
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    font-weight: 600;
    color: var(--siemens-corporate-blue);
}

.pdf-viewer-container {
    border: 1px solid var(--siemens-medium-gray);
    border-radius: var(--border-radius-elements);
    overflow: hidden;
    /* Only current page is visible */
    background-color: #e0e0e0;
    /* Light gray background for the viewer area */
    display: flex;
    justify-content: center;
    align-items: center;

    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
    position: relative;
    /* For positioning signature preview */
    min-height: 0;
    /* Ensure visibility even if PDF is not loaded */
}

#pdf-render-canvas {
    display: block;
    background-color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 1px solid #aaa;
    width: auto;
    /* Managed by JS for scaling */
    height: auto;
    /* Managed by JS for scaling */
}

.signature-placement-preview {
    position: absolute;
    cursor: grab;
    border: 2px dashed var(--siemens-accent-teal);
    /* Highlight draggable area */
    box-shadow: 0 0 5px rgba(0, 153, 153, 0.7);
    z-index: 100;
    touch-action: none;
    /* Disable default touch actions for draggable */
}

.signature-placement-preview.dragging {
    cursor: grabbing;
    opacity: 0.7;
}


/* Signature Position Controls */
.signature-position-controls {
    margin-top: 2rem;
    padding: 1.5rem;
    background-color: var(--siemens-light-gray);
    border-radius: var(--border-radius-elements);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.signature-position-controls h3 {
    text-align: center;
    color: var(--siemens-corporate-blue);
    margin-bottom: 1.5rem;
}

.signature-position-controls .input-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.signature-position-controls .input-group label {
    flex-basis: 80px;
    font-weight: 600;
}

.signature-position-controls .input-group input[type="range"] {
    flex-grow: 1;
    height: 10px;
    background: var(--siemens-medium-gray);
    border-radius: 5px;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

.signature-position-controls .input-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--siemens-accent-teal);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.signature-position-controls .input-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--siemens-accent-teal);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.signature-position-controls .input-group span {
    width: 50px;
    text-align: right;
    font-weight: bold;
    color: var(--siemens-corporate-blue);
}


/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    /* For Safari */
}

.spinner {
    border: 8px solid var(--siemens-light-gray);
    border-top: 8px solid var(--siemens-accent-teal);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin-bottom: 2rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    font-size: 1.5rem;
    color: var(--siemens-corporate-blue);
    font-weight: 600;
    margin-bottom: 1.5rem;
}

.progress-bar-container {
    width: 80%;
    max-width: 400px;
    background-color: var(--siemens-medium-gray);
    border-radius: 5px;
    height: 15px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-bar {
    height: 100%;
    background-color: var(--siemens-accent-teal);
    width: 0%;
    border-radius: 5px;
    transition: width 0.3s ease-out;
}

.progress-text {
    font-size: 1.1rem;
    color: var(--siemens-dark-gray);
}

/* Notifications */
#notification-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column-reverse;
    /* New notifications appear on top */
    gap: 12px;
}

.notification {
    padding: 1.2rem 1.8rem;
    border-radius: var(--border-radius-elements);
    color: var(--siemens-white);
    font-weight: bold;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInSlideUp 0.5s forwards, fadeOut 0.5s forwards 4.5s;
    /* Fade in, then fade out after 4.5s (total 5s display) */
}

.notification.success {
    background-color: #28a745;
    /* Green */
}

.notification.error {
    background-color: #dc3545;
    /* Red */
}

@keyframes fadeInSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* Utility Class */
.hidden {
    display: none !important;
}

/* Footer */
footer {
    text-align: center;
    padding: 1.8rem 1rem;
    background-color: var(--siemens-corporate-blue);
    color: var(--siemens-white);
    margin-top: 3rem;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    header h1 {
        font-size: 2.2rem;
    }

    header .tagline {
        font-size: 1rem;
    }

    .container {
        margin: 1.5rem auto;
        padding: 0.8rem;
    }

    .card {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .section-title {
        font-size: 1.8rem;
        margin-bottom: 1.5rem;
    }

    .drag-drop-area {
        padding: 3rem 1.5rem;
    }

    .drag-drop-area p {
        font-size: 1.1rem;
    }

    .btn {
        padding: 0.8rem 1.2rem;
        font-size: 1rem;
        width: 100%;
        /* Full width buttons on small screens */
    }

    .button-group {
        flex-direction: column;
        gap: 1rem;
    }

    .signature-toolbar {
        flex-direction: row;
        /* Keep row for toolbar, allow wrapping */
        justify-content: center;
        gap: 0.5rem;
        padding: 0.8rem;
    }

    .tool-btn {
        padding: 0.5rem;
    }

    .signature-creation-area {
        padding: 1rem;
    }

    .signature-controls {
        flex-direction: column;
        gap: 0.8rem;
    }

    #typed-signature-preview {
        font-size: 2.5em;
    }

    .page-navigation-toolbar {
        flex-direction: row;
        /* Keep row for toolbar */
        justify-content: center;
        gap: 0.5rem;
        padding: 0.8rem;
    }

    .page-info {
        font-size: 0.9rem;
    }

    .pdf-viewer-container {
        min-height: 300px;
        padding: 0.5rem;
    }

    .signature-position-controls .input-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .signature-position-controls .input-group label {
        flex-basis: auto;
    }

    .signature-position-controls .input-group span {
        width: 100%;
        text-align: left;
    }

    .file-info {
        font-size: 0.9rem;
    }

    .loading-overlay p {
        font-size: 1.2rem;
    }

    .spinner {
        width: 50px;
        height: 50px;
        border-width: 6px;
    }

    .progress-bar-container {
        width: 90%;
    }

    #notification-container {
        bottom: 10px;
        right: 10px;
        left: 10px;
        /* Make notifications full width on small screens */
    }

    .notification {
        padding: 1rem 1.2rem;
        font-size: 0.9rem;
    }
}