/* ── Valosign — Global Styles ── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:        #2563eb;
    --blue-dark:   #1d4ed8;
    --blue-light:  #eff6ff;
    --green:       #16a34a;
    --green-light: #f0fdf4;
    --red:         #dc2626;
    --red-light:   #fef2f2;
    --gray-50:     #f9fafb;
    --gray-100:    #f3f4f6;
    --gray-200:    #e5e7eb;
    --gray-300:    #d1d5db;
    --gray-500:    #6b7280;
    --gray-700:    #374151;
    --gray-900:    #111827;
    --radius:      8px;
    --shadow:      0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg:   0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--gray-900);
    background: var(--gray-50);
}

/* ── Layout ── */

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.container--narrow { max-width: 700px; }
.container--wide   { max-width: 1200px; }

/* ── Admin Navbar ── */

.navbar {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 24px;
    height: 56px;
    box-shadow: var(--shadow);
}

.navbar__brand {
    color: var(--blue);
    text-decoration: none;
    display: flex;
    align-items: center;
    height: 42px;
}

.navbar__brand img {
    display: block;
    height: 36px;
    width: auto;
}

.navbar__links { display: flex; gap: 4px; margin-left: auto; }
.navbar__links a {
    color: var(--gray-700);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background .15s;
}
.navbar__links a:hover { background: var(--gray-100); }

/* ── Page header ── */

.page-header {
    padding: 32px 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
}

/* ── Cards ── */

.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card__header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card__header h2 { font-size: 16px; font-weight: 600; }
.card__body { padding: 20px; }

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: background .15s, box-shadow .15s;
    line-height: 1.4;
}

.btn--primary   { background: var(--blue);  color: #fff; }
.btn--primary:hover { background: var(--blue-dark); }

.btn--success   { background: var(--green); color: #fff; }
.btn--success:hover { background: #15803d; }

.btn--outline   { background: #fff; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn--outline:hover { background: var(--gray-50); }

.btn--ghost     { background: transparent; color: var(--gray-500); }
.btn--ghost:hover { background: var(--gray-100); }

.btn--danger    { background: var(--red); color: #fff; }
.btn--danger:hover { background: #b91c1c; }

.btn:disabled, .btn[disabled] { opacity: .6; cursor: not-allowed; }

.btn--lg { padding: 12px 24px; font-size: 16px; }
.btn--sm { padding: 6px 12px;  font-size: 13px; }

/* ── Badges ── */

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.badge--pending  { background: #fef3c7; color: #92400e; }
.badge--signed   { background: var(--green-light); color: #166534; }
.badge--expired  { background: var(--gray-100); color: var(--gray-500); }

/* ── Table ── */

.table-wrapper { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    text-align: left;
    padding: 10px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-700);
    white-space: nowrap;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

/* ── Forms ── */

.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 15px;
    color: var(--gray-900);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.form-control[type="file"] { padding: 8px 12px; cursor: pointer; }

.form-hint { margin-top: 5px; font-size: 13px; color: var(--gray-500); }

.form-errors { margin-top: 6px; }
.form-errors li {
    color: var(--red);
    font-size: 13px;
    list-style: none;
}

.form-errors li::before { content: '✕ '; }

/* ── Alerts / Flash messages ── */

.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
    border-left: 4px solid transparent;
}

.alert--success { background: var(--green-light); border-color: var(--green); color: #166534; }
.alert--error   { background: var(--red-light);   border-color: var(--red);   color: #991b1b; }
.alert--info    { background: var(--blue-light);   border-color: var(--blue);  color: #1e40af; }
.alert--warning { background: #fffbeb; border-color: #d97706; color: #92400e; }

/* ── Detail rows ── */

.detail-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 0;
}

.detail-row {
    display: contents;
}

.detail-row dt, .detail-row dd {
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-100);
}

.detail-row dt {
    font-weight: 600;
    color: var(--gray-500);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding-right: 16px;
}

.detail-row dd { color: var(--gray-900); word-break: break-all; }

.client-admin-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: 20px;
}

@media (max-width: 900px) {
    .client-admin-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Copy token ── */

.token-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 10px 14px;
    font-family: monospace;
    font-size: 13px;
    word-break: break-all;
}

.copy-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: 5px;
    color: var(--gray-700);
    font-weight: 600;
}

.copy-btn:hover { background: var(--gray-200); }

/* ── Sign page specific ── */

.sign-layout {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: var(--gray-50);
}

.sign-header {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.sign-header__logo {
    flex-shrink: 0;
}

.sign-header__logo img {
    display: block;
    height: 42px;
    width: auto;
    max-width: 180px;
    object-fit: contain;
}

.sign-header__doc {
    font-size: 15px;
    color: var(--gray-700);
    font-weight: 500;
}

.sign-header__doc span { color: var(--gray-500); font-weight: 400; }

.sign-main {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 0;
    height: calc(100vh - 110px);
}

.sign-main--fillable {
    grid-template-columns: minmax(0, 1fr) 380px;
}

@media (max-width: 900px) {
    .sign-main { grid-template-columns: 1fr; height: auto; }
}

.sign-pdf-panel {
    border-right: 1px solid var(--gray-200);
    background: #525659;
    display: flex;
    align-items: stretch;
}

.sign-pdf-panel iframe {
    width: 100%;
    height: 100%;
    min-height: 500px;
    border: none;
    display: block;
}

.sign-side {
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow-y: auto;
}

.sign-side__section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-100);
}

.sign-side__section h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 12px;
}

/* ── Fillable document page ── */

.fillable-document-panel {
    overflow-y: auto;
    padding: 24px;
    background: #eef2f7;
}

.fillable-document {
    max-width: 920px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.doc-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    padding-bottom: 16px;
    border-bottom: 3px solid #1a5276;
    margin-bottom: 22px;
}

.doc-brand {
    color: #1a5276;
    font-size: 22px;
    font-weight: 800;
}

.doc-title {
    text-align: right;
}

.doc-title h1 {
    color: #1a5276;
    font-size: 22px;
    line-height: 1.15;
    text-transform: uppercase;
}

.doc-title p {
    color: #2878ad;
    font-size: 14px;
    font-weight: 600;
}

.doc-section {
    margin-bottom: 24px;
}

.doc-section h2 {
    color: #1a5276;
    font-size: 16px;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--gray-200);
}

.doc-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.doc-grid label,
.task-editor__row {
    min-width: 0;
}

.doc-grid label span {
    display: block;
    color: #1a5276;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 5px;
}

.doc-grid__full {
    grid-column: 1 / -1;
}

.doc-note {
    background: #eaf4fb;
    border: 1px solid #5dade2;
    border-radius: var(--radius);
    color: var(--gray-700);
    padding: 14px 16px;
}

.task-editor {
    display: grid;
    gap: 12px;
}

.task-editor__row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 150px;
    gap: 10px;
    align-items: start;
}

.task-editor__number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #5dade2;
    background: #eaf4fb;
    color: #1a5276;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    margin-top: 6px;
}

.fillable-document textarea.form-control {
    min-height: 96px;
    resize: vertical;
}

@media (max-width: 720px) {
    .fillable-document-panel { padding: 12px; }
    .fillable-document { padding: 18px; }
    .doc-header { flex-direction: column; }
    .doc-title { text-align: left; }
    .doc-grid,
    .task-editor__row {
        grid-template-columns: 1fr;
    }
}

/* ── Signature canvas ── */

.signature-canvas-wrapper {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    background: #fff;
    position: relative;
    overflow: hidden;
    touch-action: none;
}

.signature-canvas-wrapper canvas {
    display: block;
    width: 100%;
    cursor: crosshair;
}

.signature-canvas-wrapper .canvas-hint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-300);
    font-size: 14px;
    pointer-events: none;
    user-select: none;
    transition: opacity .2s;
}

/* ── Confirmation checkbox ── */

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-700);
    line-height: 1.5;
}

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

/* ── Success screen ── */

.success-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px 24px;
    gap: 16px;
}

.success-screen__icon {
    width: 64px;
    height: 64px;
    background: var(--green-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.success-screen h2 { font-size: 22px; font-weight: 700; }
.success-screen p  { color: var(--gray-500); font-size: 14px; max-width: 280px; }

/* ── Error / already-signed page ── */

.centered-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.centered-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 48px 40px;
    max-width: 460px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.centered-card .icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.centered-logo {
    display: block;
    height: 42px;
    width: auto;
    max-width: 190px;
    object-fit: contain;
    margin: 18px auto 0;
}

.centered-card h1 { font-size: 22px; margin-bottom: 12px; }
.centered-card p  { color: var(--gray-500); font-size: 15px; margin-bottom: 24px; }

/* ── Utilities ── */

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.flex { display: flex; }
.flex-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.text-sm   { font-size: 13px; }
.text-muted { color: var(--gray-500); }
.text-center { text-align: center; }
.font-mono { font-family: monospace; }

.w-full { width: 100%; }

/* ── Auth ── */

.auth-body {
    background: #f3f6fa;
}

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-panel {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 30px;
}

.auth-logo {
    display: block;
    width: 190px;
    height: auto;
    margin-bottom: 24px;
}

.auth-panel h1 {
    font-size: 22px;
    line-height: 1.25;
    margin-bottom: 8px;
}

.auth-panel p {
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 22px;
}

.auth-submit {
    justify-content: center;
    margin-top: 8px;
}

/* ── Spinner ── */

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
}

.sign-footer {
    background: #fff;
    border-top: 1px solid var(--gray-200);
    padding: 10px 24px;
    text-align: center;
    font-size: 12px;
    color: var(--gray-500);
}

/* ── Client portal ── */

.client-portal-body {
    background: #eef2f6;
}

.portal-shell {
    min-height: 100vh;
}

.portal-header {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 22px clamp(18px, 4vw, 46px);
}

.portal-brand {
    width: 190px;
    flex-shrink: 0;
}

.portal-brand img {
    display: block;
    max-width: 100%;
    max-height: 58px;
    object-fit: contain;
}

.portal-header h1 {
    font-size: 24px;
    color: var(--gray-900);
}

.portal-header p {
    color: var(--gray-500);
    font-size: 14px;
}

.portal-main {
    max-width: 980px;
    margin: 0 auto;
    padding: 26px 18px 48px;
}

.portal-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 18px;
}

.portal-section {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.portal-section__header {
    padding: 15px 18px;
    border-bottom: 1px solid var(--gray-200);
}

.portal-section__header h2 {
    font-size: 17px;
}

.portal-empty {
    color: var(--gray-500);
    padding: 20px 18px;
}

.portal-document-list {
    display: grid;
}

.portal-document {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--gray-100);
}

.portal-document:last-child {
    border-bottom: none;
}

.portal-document strong,
.portal-document span {
    display: block;
}

.portal-document span {
    color: var(--gray-500);
    font-size: 13px;
    margin-top: 2px;
}

.portal-message-form {
    padding: 18px;
}

.message-list {
    display: grid;
    gap: 10px;
}

.message-item {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 12px 14px;
    background: #fff;
}

.message-item--client {
    border-left: 4px solid var(--blue);
}

.message-item--admin {
    border-left: 4px solid var(--green);
    background: var(--green-light);
}

.message-item__meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: var(--gray-500);
    font-size: 13px;
    margin-bottom: 6px;
}

.message-item__meta strong {
    color: var(--gray-700);
}

@media (max-width: 620px) {
    .portal-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .portal-actions,
    .portal-document {
        align-items: stretch;
        flex-direction: column;
    }
}
