/* public/style.css */

/* --- Google Font & CSS Variables --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #4b5563;
    --secondary-hover: #374151;
    --bg-color: #f3f4f6;
    --card-bg-color: #ffffff;
    --text-color: #111827;
    --muted-text-color: #6b7280;
    --border-color: #e5e7eb;
    --success-color: #16a34a;
    --danger-color: #dc2626;
    --info-color: #2563eb;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --border-radius: 0.5rem;
}

/* --- Global Resets & Body --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem;
    min-height: 100vh;
}

.centered-page-body {
    justify-content: center;
}


/* --- Layout Containers --- */
.container {
    width: 100%;
    max-width: 600px;
    margin-bottom: 2rem;
}

.card {
    background-color: var(--card-bg-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.credits-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f9fafb;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.credits-display {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.credits-label {
    font-size: 1rem;
    color: var(--muted-text-color);
    font-weight: 500;
}

.credits-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* --- Typography --- */
h1, h2, h3, h4 {
    margin-bottom: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

h1 { font-size: 2.25rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; color: var(--muted-text-color); margin-top: 1.5rem; }
p { margin-bottom: 1rem; color: var(--muted-text-color); }
a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}
hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

/* --- Forms & Buttons --- */
form { display: flex; flex-direction: column; }

label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="file"] {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="file"] {
    padding: 0.5rem;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(79 70 229 / 0.2);
}

.form-row {
    display: flex;
    gap: 1rem;
    width: 100%;
}
.form-row > div {
    flex: 1;
}

button {
    background-color: var(--primary-color);
    color: white;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

button:hover {
    background-color: var(--primary-hover);
}

button.secondary {
    background-color: var(--secondary-color);
}
button.secondary:hover {
    background-color: var(--secondary-hover);
}

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.875rem;
    table-layout: fixed;
}

thead {
    background-color: #f9fafb;
}

th, td {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    overflow-wrap: break-word;
}

th:first-child,
td:first-child {
    width: 40%;
}

th {
    font-weight: 500;
    color: var(--muted-text-color);
}

tbody tr:hover {
    background-color: #f9fafb;
}

td .action-link {
    font-weight: 500;
}
td .action-link-primary {
    color: var(--primary-color);
}

.td-status {
    text-align: center;
}


/* --- Utility Classes --- */
.text-center { text-align: center; }

.status {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: capitalize;
    display: inline-block;
    min-width: 110px;
    text-align: center;
}
.status-pending-setup { color: #94a3b8; background-color: #f1f5f9; }
.status-pending-signatures { color: #d97706; background-color: #fef3c7; }
.status-completed { color: #15803d; background-color: #dcfce7; }

.alert {
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 0.375rem;
    font-weight: 500;
}
.alert-success { color: var(--success-color); background-color: #dcfce7; }
.alert-danger { color: var(--danger-color); background-color: #fee2e2; }
.alert-info { color: var(--info-color); background-color: #dbeafe; }

/* --- Progress Bar --- */
.progress-bar {
    display: inline-block;
    width: 120px;
    height: 20px;
    background-color: var(--border-color);
    border-radius: 10px;
    position: relative;
    font-size: 0.75rem;
    line-height: 20px;
    text-align: center;
    color: var(--text-color);
    overflow: hidden;
    cursor: pointer;
}

.progress-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--progress, 0%);
    background-color: #818cf8;
    border-radius: 10px;
    transition: width 0.3s ease-in-out;
    z-index: 0;
}
.progress-bar {
    z-index: 1;
    position: relative;
}

/* --- Placement View Styles --- */
.placement-view {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-color);
    flex-direction: column;
}

.placement-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 1rem;
}

.placement-view-header .header-info h2,
.placement-view-header .header-info p {
    margin: 0;
    line-height: 1.3;
}
.placement-view-header .header-info p {
    font-size: 0.875rem;
    color: var(--muted-text-color);
}

.placement-body {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
}

.signer-management-panel {
    width: 320px;
    flex-shrink: 0;
    background-color: #f9fafb;
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
}

#signersList {
    list-style: none;
    margin-top: 1rem;
}
#signersList li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}
#no-signers-yet {
    border: none;
    background: none;
    color: var(--muted-text-color);
    padding: 0.5rem 0;
}
.remove-signer-btn {
    background: none;
    border: none;
    color: var(--danger-color);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.5rem;
}

.pdf-nav { display: flex; align-items: center; gap: 1rem; }
.pdf-nav button { padding: 0.5rem 1rem; }
#page-indicator { font-weight: 500; min-width: 100px; text-align: center; }

#pdf-viewer-container {
    flex-grow: 1;
    overflow: auto;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

#canvas-wrapper {
    position: relative;
    line-height: 0;
}

#pdf-canvas {
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow);
    cursor: crosshair;
}

#signature-placeholders-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.signature-box-placed {
    position: absolute;
    z-index: 5;
    border: 2px solid var(--primary-color);
    background-color: rgba(79, 70, 229, 0.25);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    color: var(--primary-hover);
    line-height: 1.2;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    user-select: none;
    pointer-events: all;
    word-break: break-all;
    overflow: hidden;
}

.signature-box-placed.dragging {
    cursor: grabbing;
    z-index: 10;
    border-style: dashed;
    opacity: 0.8;
}

.signature-box-placed.resizing {
    cursor: nwse-resize;
    z-index: 10;
    opacity: 0.8;
}

.resize-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    right: 0;
    bottom: 0;
    background-color: var(--primary-color);
    cursor: se-resize;
    border-top: 2px solid white;
    border-left: 2px solid white;
    pointer-events: all;
}

/* --- Signing View Styles --- */
.signing-view {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-color);
}

.signing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 2rem;
}

.signing-header .header-info { flex-grow: 1; }
.signing-header .header-info h1, 
.signing-header .header-info p { margin: 0; line-height: 1.3; }
.signing-header .header-info h1 { font-size: 1.5rem; }
.signing-header .header-info p { font-size: 0.875rem; }
.signing-header form { margin: 0; }

.signing-view #pdf-viewer-container {
    flex-grow: 1;
    overflow: auto;
    padding: 2rem;
}

.signing-view #pdf-canvas {
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow);
    display: block;
    margin: 0 auto;
}

.signing-view .signature-box-placed {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    line-height: 1.2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    word-break: break-all;
    user-select: none;
    cursor: default;
    pointer-events: none;
}

/* Default style for the current user's pending signature */
.signing-view .signature-box-placed.current-user {
    border: 2px solid var(--primary-color);
    background-color: rgba(79, 70, 229, 0.2);
    color: var(--primary-hover);
}

/* Style for other users' pending signatures */
.signing-view .signature-box-placed.other-user {
    border: 2px dashed var(--muted-text-color);
    background-color: rgba(107, 114, 128, 0.1);
    color: var(--muted-text-color);
}

/* Style for any signature that has already been completed */
.signing-view .signature-box-placed.signed {
    border: 2px solid var(--success-color);
    background-color: rgba(22, 163, 74, 0.1);
    color: var(--success-color);
}

button:disabled {
    background-color: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.7;
}

.button-like-label {
    display: inline-block;
    background-color: var(--primary-color);
    color: white;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    text-align: center;
}

.button-like-label:hover {
    background-color: var(--primary-hover);
}

.button-like-link {
    display: inline-block;
    background-color: var(--primary-color);
    color: white;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    text-align: center;
    text-decoration: none;
    margin-top: 1.5rem;
}

.button-like-link:hover {
    background-color: var(--primary-hover);
    color: white;
    text-decoration: none;
}

.button-like-link.secondary-action-button {
    background-color: var(--secondary-color);
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    margin-top: 0;
}

.button-like-link.secondary-action-button:hover {
    background-color: var(--secondary-hover);
}

a.button-as-link-disabled {
    cursor: not-allowed;
    opacity: 0.7;
    pointer-events: none;
}


/* --- Progress Tooltip --- */
.progress-tooltip {
    position: absolute;
    visibility: hidden;
    opacity: 0;
    z-index: 2000;
    background-color: var(--card-bg-color);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    border-radius: var(--border-radius);
    padding: 1rem;
    width: 100%;
    max-width: 350px;
    pointer-events: none;
    transform: scale(0.95);
    transition: opacity 0.1s ease-out, transform 0.1s ease-out;
}

.progress-tooltip.visible {
    visibility: visible;
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.progress-tooltip h4 {
    margin-top: 0;
    margin-bottom: 0.75rem;
    font-size: 1rem;
    color: var(--text-color);
}

.progress-tooltip ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.progress-tooltip li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
}

.progress-tooltip li:last-child {
    border-bottom: none;
}

.signer-info span {
    display: block;
    line-height: 1.4;
}
.signer-info .signer-email {
    font-weight: 500;
}
.signer-info .signer-status {
    font-size: 0.75rem;
    color: var(--muted-text-color);
}

.signer-info .signer-status.pending {
    color: var(--danger-color);
}
.signer-info .signer-status.signed {
    color: var(--success-color);
}

.copy-link-btn {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    background-color: #e5e7eb;
    color: var(--secondary-color);
    border: 1px solid #d1d5db;
    font-weight: 500;
}
.copy-link-btn:hover {
    background-color: #d1d5db;
}

/* --- Profile Modal Styles --- */
.modal-overlay {
    display: none;
    position: fixed;
    z-index: 1500;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal-content {
    background-color: var(--card-bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 500px;
    position: relative;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 2rem;
    font-weight: bold;
    line-height: 1;
    color: var(--muted-text-color);
    cursor: pointer;
    padding: 0;
}
.close-modal-btn:hover {
    color: var(--text-color);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-body input[type="text"],
.modal-body input[type="password"] {
    width: 100%;
}

.profile-info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem 1.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

@media (min-width: 520px) {
    .profile-info-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.profile-info-grid span {
    color: var(--muted-text-color);
}
.profile-info-grid strong {
    color: var(--text-color);
}
.grid-span-all {
    grid-column: 1 / -1;
}

/* --- Media Queries for Mobile Responsiveness --- */
@media (max-width: 768px) {
    body {
        padding: 1rem 0;
    }

    .container {
        padding: 0 1rem;
    }

    .card {
        padding: 1.5rem;
    }
    
    .credits-section {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem;
    }

    .credits-display {
        justify-content: center;
    }

    .button-like-link.secondary-action-button {
        text-align: center;
    }

    /* --- Dashboard Specific Styles --- */
    #dashboard-content .container {
        padding: 0 1rem;
    }

    #dashboard-content header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    #dashboard-content header h1 {
        margin-bottom: 0;
    }

    /* Responsive Table: Transform into a list of cards */
    .card table thead {
        display: none;
    }

    .card table,
    .card table tbody,
    .card table tr,
    .card table td {
        display: block;
        width: 100%;
    }

    .card table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius);
    }
    
    .card table td {
        padding: 0.75rem 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid var(--border-color);
        min-height: 44px;
        gap: 1rem;
    }

    .card table tr td:last-child {
        border-bottom: none;
    }

    .card table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-color);
        text-align: left;
        flex-shrink: 0;
    }

    /* The div wrapper added in JS */
    .card table td > div {
        text-align: right;
        word-break: break-word;
        flex-grow: 1;
    }

    /* Override for document name to be left aligned */
    .card table td[data-label="Document Name"] > div {
        text-align: left;
    }
    
    .card table .td-status > div {
        display: flex;
        justify-content: flex-end;
    }

    /* Handle the loading/empty states */
    #documentsList tr td[colspan="5"] {
        border: none;
        padding: 1rem 0;
        text-align: center;
        display: block;
        justify-content: center;
    }
    #documentsList tr:has(td[colspan="5"]) {
        border: none;
        padding: 0;
        margin-bottom: 0;
        background: none;
    }

    /* --- Placement View Specific Styles --- */
    .placement-view-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem;
    }
    
    .placement-view-header .header-info {
        text-align: center;
    }
    
    .placement-view-header .pdf-nav {
        order: 1;
        justify-content: space-between;
    }

    .placement-view-header .header-actions {
        order: 2;
        width: 100%;
        display: flex;
        gap: 1rem;
    }

    .placement-view-header .header-actions button {
        flex-grow: 1;
    }

    .placement-body {
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .signer-management-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
        overflow-y: visible;
        max-height: none;
    }

    #pdf-viewer-container {
        padding: 1rem;
        overflow: visible;
        display: flex;
        justify-content: center;
    }

    #pdf-canvas {
        max-width: 100%;
        height: auto;
        box-shadow: none;
    }

    /* --- Signing View Specific Styles --- */
    .signing-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem;
    }

    .signing-header .header-info {
        text-align: center;
    }
    
    .signing-header .header-info h1 {
        font-size: 1.25rem;
    }
    
    .signing-header .header-info p {
        font-size: 0.8rem;
    }

    .signing-header .pdf-nav {
        width: 100%;
        justify-content: space-between;
    }
    
    .signing-header .pdf-nav button {
        padding: 0.5rem;
    }

    .signing-header form {
        width: 100%;
    }
    .signing-header form button {
        width: 100%;
    }
    
    .signing-view #pdf-viewer-container {
        padding: 1rem;
    }
    
    /* --- Profile Modal Specific Styles --- */
    .modal-content {
        width: 95%;
        max-width: 95vw;
    }
    .form-row {
        flex-direction: column;
        gap: 0;
    }
}
