:root {
    --bg-primary: #090d16;
    --bg-secondary: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --bg-input: #0b1120;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: #3b82f6;
    
    --brand-primary: #2563eb;
    --brand-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 50%, #06b6d4 100%);
    --brand-glow: 0 0 25px rgba(37, 99, 235, 0.35);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(37, 99, 235, 0.12) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(6, 182, 212, 0.08) 0%, transparent 40%);
    background-attachment: fixed;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: #0f172a;
}
::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* Header & Navbar */
.app-header {
    background: rgba(11, 17, 32, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 14px 28px;
}

.header-container {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand-wrapper {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo-img {
    height: 38px;
    filter: drop-shadow(0 2px 8px rgba(37, 99, 235, 0.3));
    background: #ffffff;
    padding: 4px 10px;
    border-radius: 8px;
}

.brand-text-col {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge-tag {
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(37, 99, 235, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.brand-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    text-decoration: none;
    line-height: 1;
}

.btn-primary {
    background: var(--brand-gradient);
    color: #fff;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(37, 99, 235, 0.45);
    filter: brightness(1.08);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.btn-outline-danger {
    background: transparent;
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-outline-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

/* Layout */
.main-wrapper {
    max-width: 1600px;
    margin: 24px auto;
    padding: 0 24px;
}

.split-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    align-items: start;
}

@media (max-width: 1180px) {
    .split-layout {
        grid-template-columns: 1fr;
    }
}

/* Panel Containers */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 26px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-title i, .panel-title svg {
    color: #38bdf8;
}

/* Form Styles */
.form-section {
    margin-bottom: 24px;
    padding: 18px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-lg);
}

.section-label {
    font-size: 0.92rem;
    font-weight: 700;
    color: #38bdf8;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Checkbox Cards */
.job-types-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

@media (max-width: 640px) {
    .job-types-grid {
        grid-template-columns: 1fr;
    }
}

.job-card {
    position: relative;
    cursor: pointer;
    user-select: none;
}

.job-card input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.job-card-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1.5px solid #1e293b;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.job-card input:checked ~ .job-card-inner {
    border-color: var(--brand-primary);
    background: rgba(37, 99, 235, 0.15);
    box-shadow: 0 0 15px rgba(37, 99, 235, 0.25);
}

.job-check-box {
    width: 20px;
    height: 20px;
    border: 1.5px solid #475569;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: transparent;
    transition: var(--transition);
}

.job-card input:checked ~ .job-card-inner .job-check-box {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: #fff;
}

.job-card-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Input Fields */
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

@media (max-width: 768px) {
    .form-grid-2, .form-grid-4 {
        grid-template-columns: 1fr;
    }
}

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

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid #334155;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition);
    outline: none;
    font-family: inherit;
}

.form-control:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

textarea.form-control {
    resize: vertical;
    min-height: 90px;
    line-height: 1.5;
}

/* Quick Snippets Pills */
.snippets-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.snippet-pill {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

.snippet-pill:hover {
    background: rgba(37, 99, 235, 0.2);
    border-color: #3b82f6;
    color: #60a5fa;
}

/* Signature Section */
.signature-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 768px) {
    .signature-grid {
        grid-template-columns: 1fr;
    }
}

.signature-box {
    background: #060a12;
    border: 1.5px dashed #334155;
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
}

.signature-box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.signature-box-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #cbd5e1;
}

.canvas-wrapper {
    background: #ffffff;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    touch-action: none;
}

.signature-canvas {
    display: block;
    width: 100%;
    height: 120px;
    cursor: crosshair;
}

.canvas-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    color: #94a3b8;
    pointer-events: none;
    user-select: none;
    transition: opacity 0.2s;
}

.canvas-hint.hidden {
    opacity: 0;
}

.signature-tools {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* Action Bar */
.action-card {
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.95) 100%);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius-lg);
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.action-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.action-buttons-group {
    display: flex;
    gap: 12px;
}

/* Right Panel: Live Document Visualizer */
.preview-sticky {
    position: sticky;
    top: 88px;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.a4-paper-wrapper {
    background: #475569;
    padding: 16px;
    border-radius: var(--radius-lg);
    overflow: auto;
    max-height: calc(100vh - 160px);
    display: flex;
    justify-content: center;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.4);
}

.a4-paper {
    background: #ffffff;
    color: #000000;
    width: 100%;
    max-width: 520px;
    min-height: 735px;
    padding: 24px 28px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.5);
    font-family: 'Times New Roman', Times, serif;
    font-size: 9pt;
    line-height: 1.35;
    position: relative;
    border-radius: 2px;
    transform-origin: top center;
    transition: transform 0.2s ease;
}

/* A4 preview internal styles */
.pv-header-table {
    width: 100%;
    margin-bottom: 10px;
}
.pv-header-table td {
    vertical-align: top;
}
.pv-logo {
    max-width: 120px;
    height: auto;
}
.pv-company-info {
    text-align: right;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 6.8pt;
    line-height: 1.2;
}
.pv-company-name {
    font-weight: bold;
    font-size: 7.2pt;
}

.pv-title {
    text-align: center;
    font-size: 13pt;
    font-weight: bold;
    letter-spacing: 1.5px;
    margin: 8px 0 10px 0;
}

.pv-checkbox-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 10px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
}

.pv-chk-box {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 1px solid #000;
    text-align: center;
    line-height: 11px;
    font-size: 9pt;
    margin-right: 4px;
    vertical-align: middle;
}

.pv-body-text {
    text-align: justify;
    margin-bottom: 6px;
    font-size: 8.8pt;
}

.pv-dots {
    border-bottom: 1px dotted #333;
    display: inline-block;
    padding: 0 2px;
    font-weight: bold;
}

.pv-table {
    width: 100%;
    margin-bottom: 2px;
    border-collapse: collapse;
}

.pv-table td {
    padding: 1px 0;
    vertical-align: top;
    font-size: 8.8pt;
}

.pv-val {
    border-bottom: 1px dotted #333;
    font-weight: bold;
    padding-left: 2px;
}

.pv-statement {
    margin-top: 6px;
    margin-bottom: 4px;
    font-size: 8.8pt;
}

.pv-statement-lines {
    width: 100%;
    margin-bottom: 8px;
}

.pv-sline {
    border-bottom: 1px dotted #333;
    min-height: 16px;
    font-size: 8.5pt;
    padding: 1px 0;
    line-height: 14px;
}

.pv-signatures {
    width: 100%;
    margin-top: 6px;
}
.pv-signatures td {
    width: 50%;
    vertical-align: top;
    padding: 0 8px;
}

.pv-sig-title {
    font-weight: bold;
    font-size: 9pt;
    margin-bottom: 2px;
}

.pv-sig-box {
    height: 40px;
    position: relative;
    margin-bottom: 4px;
}

.pv-sig-img {
    max-height: 38px;
    max-width: 130px;
    display: block;
}

.pv-sig-meta-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4px;
}

.pv-sig-meta-table td {
    padding: 1.5px 0;
    vertical-align: top;
    font-size: 8.8pt;
}

.pv-sig-meta-label {
    width: 50px;
    font-weight: bold;
    white-space: nowrap;
}

.pv-sig-meta-val {
    border-bottom: 1px dotted #333;
    font-weight: bold;
    padding-left: 4px;
    word-break: break-word;
}

/* History Archive Section */
.history-section {
    margin-top: 40px;
}

.history-table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    text-align: left;
}

.history-table th {
    background: rgba(15, 23, 42, 0.9);
    color: var(--text-secondary);
    font-weight: 700;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

.history-table td {
    padding: 14px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(30, 41, 59, 0.4);
    color: var(--text-primary);
}

.history-table tr:hover td {
    background: rgba(37, 99, 235, 0.08);
}

.tag-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(37, 99, 235, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.25);
    margin-right: 4px;
}

/* Alerts */
.alert-banner {
    padding: 12px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #34d399;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 900px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: #0b1120;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}

.modal-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #334155;
}

.modal-iframe {
    width: 100%;
    height: 100%;
    border: none;
}
