<?php
/**
 * Unified Document Styles for Public Views (Proposal, Contract, Invoice)
 * 
 * Include this file in proposal.php, contract.php, and invoice.php
 * Required variable: $primary_color (set before including)
 * Optional variables: $primary_color_mode, $primary_color_2, $gradient_direction
 *
 * @package Freelance_Studio
 */

if (!defined('ABSPATH')) {
    exit;
}

// Compute primary background value
$color_mode = isset($primary_color_mode) ? $primary_color_mode : 'solid';
$color_2 = isset($primary_color_2) ? $primary_color_2 : $primary_color;
$grad_dir = isset($gradient_direction) ? intval($gradient_direction) : 135;

if ($color_mode === 'gradient' && !empty($color_2)) {
    $primary_bg = 'linear-gradient(' . $grad_dir . 'deg, ' . esc_attr($primary_color) . ' 0%, ' . esc_attr($color_2) . ' 100%)';
} else {
    $primary_bg = esc_attr($primary_color);
}
?>
<style>
    :root {
        --primary-color: <?php echo esc_attr($primary_color); ?>;
        --primary-bg: <?php echo  esc_html( $primary_bg ); ?>;
        --gray-50: #f9fafb;
        --gray-100: #f3f4f6;
        --gray-200: #e5e7eb;
        --gray-300: #d1d5db;
        --gray-400: #9ca3af;
        --gray-500: #6b7280;
        --gray-600: #4b5563;
        --gray-700: #374151;
        --gray-800: #1f2937;
        --gray-900: #111827;
        --success: #059669;
        --success-light: #d1fae5;
        --warning: #d97706;
        --warning-light: #fef3c7;
        --danger: #dc2626;
        --danger-light: #fef2f2;
        --secondary: #81A5DF;
        --teal: #3ECFB2;
    }
    
    * { box-sizing: border-box; margin: 0; padding: 0; }
    
    body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
        background: var(--gray-100);
        color: var(--gray-800);
        line-height: 1.6;
        min-height: 100vh;
    }
    
    /* Container */
    .fs-doc-container {
        max-width: 900px;
        margin: 0 auto;
        padding: 40px 20px;
    }
    
    /* Back link */
    .fs-doc-back-link {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        color: var(--gray-500);
        text-decoration: none;
        font-size: 14px;
        margin-bottom: 16px;
        transition: color 0.2s;
    }
    
    .fs-doc-back-link:hover {
        color: var(--primary-color);
    }
    
    /* Main document card */
    .fs-doc-card {
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
        overflow: hidden;
    }
    
    /* Colored header */
    .fs-doc-header {
        background: var(--primary-bg);
        padding: 32px;
        color: #fff;
    }
    
    .fs-doc-logo {
        max-height: 50px;
        margin-bottom: 16px;
    }
    
    .fs-doc-business-name {
        font-size: 14px;
        opacity: 0.9;
        margin-bottom: 20px;
    }
    
    .fs-doc-title {
        font-size: 28px;
        font-weight: 700;
        margin-bottom: 8px;
        line-height: 1.2;
    }
    
    .fs-doc-number {
        font-size: 14px;
        opacity: 0.8;
        margin-bottom: 12px;
    }
    
    /* Status badges */
    .fs-status-badge {
        display: inline-block;
        padding: 6px 16px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }
    
    /* Header badges (on colored background) */
    .fs-doc-header .fs-status-badge {
        background: rgba(255,255,255,0.2);
        color: #fff;
    }
    
    .fs-doc-header .fs-status-badge.status-approved,
    .fs-doc-header .fs-status-badge.status-paid,
    .fs-doc-header .fs-status-badge.status-completed {
        background: var(--success-light);
        color: #065f46;
    }
    
    .fs-doc-header .fs-status-badge.status-overdue,
    .fs-doc-header .fs-status-badge.status-expired,
    .fs-doc-header .fs-status-badge.status-rejected {
        background: var(--danger-light);
        color: #dc2626;
    }
    
    /* Content area badges */
    .fs-status-badge.status-draft { background: var(--gray-200); color: var(--gray-600); }
    .fs-status-badge.status-sent { background: #dbeafe; color: #1e40af; }
    .fs-status-badge.status-viewed { background: #e0e7ff; color: #3730a3; }
    .fs-status-badge.status-pending { background: var(--warning-light); color: #92400e; }
    .fs-status-badge.status-partial { background: var(--warning-light); color: #92400e; }
    .fs-status-badge.status-revision { background: var(--warning-light); color: #92400e; }
    .fs-status-badge.status-approved { background: var(--success-light); color: #065f46; }
    .fs-status-badge.status-paid { background: var(--success-light); color: #065f46; }
    .fs-status-badge.status-completed { background: var(--success-light); color: #065f46; }
    .fs-status-badge.status-overdue { background: var(--danger-light); color: #dc2626; }
    .fs-status-badge.status-expired { background: var(--danger-light); color: #dc2626; }
    .fs-status-badge.status-rejected { background: var(--danger-light); color: #dc2626; }
    
    /* Document body content */
    .fs-doc-body {
        padding: 40px;
    }
    
    /* Section titles */
    .fs-doc-section-title {
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: var(--gray-500);
        margin-bottom: 16px;
        font-weight: 600;
    }
    
    /* Parties section */
    .fs-doc-parties {
        margin-bottom: 32px;
    }
    
    .fs-doc-parties-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
    }
    
    .fs-doc-party-card {
        background: var(--gray-50);
        border-radius: 8px;
        padding: 20px;
    }
    
    .fs-doc-party-label {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-bottom: 8px;
        font-weight: 600;
    }
    
    .fs-doc-party-label.contractor {
        color: var(--secondary);
    }
    
    .fs-doc-party-label.client {
        color: var(--teal);
    }
    
    .fs-doc-party-name {
        font-size: 16px;
        font-weight: 600;
        color: var(--gray-900);
        margin-bottom: 4px;
    }
    
    .fs-doc-party-card p {
        margin: 2px 0;
        color: var(--gray-600);
        font-size: 14px;
    }
    
    /* Dates section */
    .fs-doc-dates {
        display: flex;
        gap: 40px;
        margin-bottom: 32px;
        padding-bottom: 24px;
        border-bottom: 1px solid var(--gray-200);
    }
    
    .fs-doc-date-item label {
        display: block;
        font-size: 12px;
        color: var(--gray-500);
        margin-bottom: 4px;
    }
    
    .fs-doc-date-item span {
        font-weight: 600;
        color: var(--gray-900);
    }
    
    .fs-doc-date-item.overdue span {
        color: var(--danger);
    }
    
    /* Services/Items table */
    .fs-doc-section {
        margin-bottom: 32px;
    }
    
    .fs-doc-table {
        width: 100%;
        border-collapse: collapse;
    }
    
    .fs-doc-table th {
        text-align: left;
        padding: 12px 0;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: var(--gray-500);
        font-weight: 600;
        border-bottom: 2px solid var(--primary-color);
    }
    
    .fs-doc-table th:last-child {
        text-align: right;
    }
    
    .fs-doc-table td {
        padding: 16px 0;
        border-bottom: 1px solid var(--gray-100);
        vertical-align: top;
    }
    
    .fs-doc-table td:last-child {
        text-align: right;
        font-weight: 500;
    }
    
    .fs-doc-item-name {
        font-weight: 500;
        color: var(--gray-900);
    }
    
    .fs-doc-item-description {
        font-size: 13px;
        color: var(--gray-500);
        margin-top: 4px;
    }
    
    .fs-doc-item-meta {
        font-size: 12px;
        color: var(--gray-400);
        margin-top: 2px;
    }
    
    /* Totals */
    .fs-doc-totals {
        margin-top: 24px;
        padding-top: 24px;
        border-top: 2px solid var(--gray-200);
    }
    
    .fs-doc-totals-row {
        display: flex;
        justify-content: flex-end;
        gap: 40px;
        padding: 8px 0;
    }
    
    .fs-doc-totals-row.grand-total {
        font-size: 20px;
        font-weight: 700;
        background: var(--gray-50);
        border-radius: 8px;
        margin-top: 8px;
        padding: 16px;
    }
    
    .fs-doc-totals-label {
        color: var(--gray-600);
        min-width: 120px;
        text-align: right;
    }
    
    .fs-doc-totals-value {
        min-width: 120px;
        text-align: right;
        font-weight: 500;
    }
    
    /* Notes section */
    .fs-doc-notes {
        background: var(--gray-50);
        padding: 20px;
        border-radius: 8px;
        margin-top: 32px;
    }
    
    .fs-doc-notes h3 {
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: var(--gray-500);
        margin-bottom: 8px;
        font-weight: 600;
    }
    
    .fs-doc-notes p {
        color: var(--gray-700);
        white-space: pre-wrap;
    }
    
    /* Custom sections (for proposals) */
    .fs-doc-custom-section {
        background: var(--gray-50);
        padding: 24px;
        border-radius: 8px;
        margin-bottom: 24px;
    }
    
    .fs-doc-custom-section h3 {
        font-size: 16px;
        font-weight: 600;
        color: var(--gray-900);
        margin-bottom: 12px;
    }
    
    .fs-doc-custom-section-content {
        color: var(--gray-700);
    }
    
    /* Contract terms sections */
    .fs-doc-terms {
        margin-top: 40px;
    }
    
    .fs-doc-term-section {
        margin-bottom: 32px;
        padding-bottom: 24px;
        border-bottom: 1px solid var(--gray-200);
    }
    
    .fs-doc-term-section:last-child {
        border-bottom: none;
    }
    
    .fs-doc-term-title {
        font-size: 16px;
        font-weight: 600;
        color: var(--gray-900);
        margin-bottom: 12px;
    }
    
    .fs-doc-term-content {
        color: var(--gray-700);
        font-size: 14px;
        line-height: 1.7;
    }
    
    .fs-doc-term-content p {
        margin-bottom: 12px;
    }
    
    .fs-doc-term-content p:last-child {
        margin-bottom: 0;
    }
    
    /* Signatures section */
    .fs-doc-signatures {
        margin-top: 40px;
        padding-top: 32px;
        border-top: 2px solid var(--gray-200);
    }
    
    .fs-doc-signatures-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 40px;
    }
    
    .fs-doc-signature-block {
        text-align: center;
    }
    
    .fs-doc-signature-label {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: var(--gray-400);
        margin-bottom: 16px;
        font-weight: 600;
    }
    
    .fs-doc-signature-image {
        min-height: 60px;
        margin-bottom: 8px;
    }
    
    .fs-doc-signature-image img {
        max-height: 60px;
        max-width: 200px;
    }
    
    .fs-doc-signature-line {
        border-bottom: 2px solid var(--gray-300);
        margin-bottom: 8px;
    }
    
    .fs-doc-signature-name {
        font-weight: 600;
        color: var(--gray-900);
    }
    
    .fs-doc-signature-title {
        font-size: 13px;
        color: var(--gray-500);
    }
    
    .fs-doc-signature-date {
        font-size: 13px;
        color: var(--gray-400);
        margin-top: 4px;
    }
    
    .fs-doc-signature-pending {
        min-height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px dashed var(--gray-300);
        border-radius: 8px;
        color: var(--gray-400);
        font-style: italic;
        margin-bottom: 8px;
    }
    
    /* Sign Form */
    .fs-doc-sign-section {
        background: #eff6ff;
        border: 2px solid #3b82f6;
        border-radius: 12px;
        padding: 24px;
        margin-top: 32px;
    }
    
    .fs-doc-sign-title {
        font-size: 18px;
        font-weight: 600;
        margin-bottom: 16px;
        color: #1e40af;
    }
    
    .fs-doc-signature-pad-container {
        background: #fff;
        border: 2px solid var(--gray-300);
        border-radius: 8px;
        margin-bottom: 16px;
        position: relative;
    }
    
    .fs-doc-signature-pad {
        width: 100%;
        height: 150px;
        cursor: crosshair;
    }
    
    .fs-doc-signature-hint {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: var(--gray-400);
        font-size: 14px;
        pointer-events: none;
    }
    
    .fs-doc-signature-pad-container.has-signature .fs-doc-signature-hint {
        display: none;
    }
    
    .fs-doc-clear-signature {
        position: absolute;
        top: 8px;
        right: 8px;
        background: var(--gray-200);
        border: none;
        padding: 4px 12px;
        border-radius: 4px;
        font-size: 12px;
        cursor: pointer;
    }
    
    .fs-doc-clear-signature:hover {
        background: var(--gray-300);
    }
    
    .fs-doc-form-group {
        margin-bottom: 16px;
    }
    
    .fs-doc-form-group label {
        display: block;
        font-size: 14px;
        font-weight: 500;
        margin-bottom: 6px;
    }
    
    .fs-doc-form-group input,
    .fs-doc-form-group textarea {
        width: 100%;
        padding: 10px 14px;
        border: 1px solid var(--gray-300);
        border-radius: 6px;
        font-size: 15px;
        font-family: inherit;
    }
    
    .fs-doc-form-group input:focus,
    .fs-doc-form-group textarea:focus {
        outline: none;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
    
    .fs-doc-sign-btn {
        width: 100%;
        padding: 14px 24px;
        background: var(--success);
        color: #fff;
        border: none;
        border-radius: 8px;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: background 0.2s;
    }
    
    .fs-doc-sign-btn:hover {
        background: #047857;
    }
    
    .fs-doc-sign-btn:disabled {
        background: var(--gray-300);
        cursor: not-allowed;
    }
    
    .fs-doc-revision-link {
        display: block;
        text-align: center;
        margin-top: 16px;
        color: var(--gray-500);
        font-size: 14px;
        cursor: pointer;
        text-decoration: none;
    }
    
    .fs-doc-revision-link:hover {
        color: var(--gray-700);
    }
    
    .fs-doc-revision-form {
        margin-top: 24px;
        padding-top: 24px;
        border-top: 1px solid #bfdbfe;
        display: none;
    }
    
    .fs-doc-revision-form.active {
        display: block;
    }
    
    .fs-doc-revision-btn {
        width: 100%;
        padding: 12px;
        background: var(--warning);
        color: #fff;
        border: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
    }
    
    .fs-doc-cancel-revision {
        width: 100%;
        padding: 10px;
        background: transparent;
        border: none;
        color: var(--gray-500);
        cursor: pointer;
        margin-top: 8px;
    }
    
    /* Footer */
    .fs-doc-footer {
        text-align: center;
        padding: 32px;
        color: var(--gray-500);
        font-size: 14px;
    }
    
    /* Payment actions (for invoices) */
    .fs-doc-actions {
        display: flex;
        gap: 12px;
        margin-top: 32px;
        padding-top: 24px;
        border-top: 1px solid var(--gray-200);
    }
    
    .fs-doc-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 12px 20px;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 500;
        text-decoration: none;
        cursor: pointer;
        border: none;
        transition: all 0.2s;
    }
    
    .fs-doc-btn-primary {
        background: var(--primary-bg);
        color: #fff;
    }
    
    .fs-doc-btn-primary:hover {
        filter: brightness(1.1);
        color: #fff;
    }
    
    .fs-doc-btn-secondary {
        background: var(--gray-200);
        color: var(--gray-700);
    }
    
    .fs-doc-btn-secondary:hover {
        background: var(--gray-300);
        color: var(--gray-700);
    }
    
    /* Print styles */
    @media print {
        body { background: #fff; }
        .fs-doc-container { padding: 0; max-width: none; }
        .fs-doc-card { box-shadow: none; }
        .fs-doc-sign-section, .fs-doc-footer, .fs-doc-back-link, .fs-doc-actions { display: none; }
    }
    
    /* Mobile */
    @media (max-width: 600px) {
        .fs-doc-header { padding: 24px; }
        .fs-doc-body { padding: 24px; }
        .fs-doc-parties-grid { grid-template-columns: 1fr; }
        .fs-doc-dates { flex-direction: column; gap: 16px; }
        .fs-doc-signatures-grid { grid-template-columns: 1fr; gap: 24px; }
        .fs-doc-table th, .fs-doc-table td { padding: 12px 8px; font-size: 14px; }
        .fs-doc-actions { flex-direction: column; }
        .fs-doc-btn { width: 100%; }
    }
</style>
