/* ==========================================================================
   Beckdale Documentation Platform - Custom Styles
   Supplements Tailwind CSS (loaded via CDN).
   ========================================================================== */

/* ---------- Theme Custom Properties ---------- */
:root {
    --doc-primary: #6366f1;         /* indigo-600 */
    --doc-primary-hover: #4f46e5;   /* indigo-700 */
    --doc-bg: #f9fafb;              /* gray-50 */
    --doc-sidebar-bg: #1f2937;      /* gray-800 */
    --doc-text: #111827;            /* gray-900 */
}

/* ---------- Font Import ---------- */
@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&display=swap');

/* ---------- Base Font ---------- */
body {
    font-family: 'Libre Baskerville', 'Times New Roman', Times, serif;
}

/* ---------- Base / Reset ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------- Custom Scrollbar ---------- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #94a3b8 #f1f5f9;
}

/* ---------- Document Content Prose Styling ---------- */
.doc-content {
    font-family: 'Libre Baskerville', 'Times New Roman', Times, serif;
}

/* Headings use !important to override Tailwind CDN preflight reset
   (preflight sets all headings to font-size:inherit; font-weight:inherit) */
.doc-content h1 {
    font-size: 1.875rem !important;
    font-weight: 700 !important;
    line-height: 1.3;
    margin: 1.5rem 0 0.75rem;
    color: #111827;
}

.doc-content h2 {
    font-size: 1.5rem !important;
    font-weight: 600 !important;
    line-height: 1.35;
    margin: 1.25rem 0 0.625rem;
    color: #1f2937;
}

.doc-content h3 {
    font-size: 1.25rem !important;
    font-weight: 600 !important;
    line-height: 1.4;
    margin: 1rem 0 0.5rem;
    color: #374151;
}

.doc-content h4 {
    font-size: 1.125rem !important;
    font-weight: 600 !important;
    line-height: 1.4;
    margin: 0.875rem 0 0.4375rem;
    color: #374151;
}

.doc-content h5 {
    font-size: 1rem !important;
    font-weight: 600 !important;
    line-height: 1.4;
    margin: 0.75rem 0 0.375rem;
    color: #374151;
}

.doc-content h6 {
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    line-height: 1.4;
    margin: 0.75rem 0 0.375rem;
    color: #4b5563;
}

.doc-content p {
    margin: 0.5rem 0;
    line-height: 1.625;
}

.doc-content ul {
    list-style: disc;
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.doc-content ol {
    list-style: decimal;
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.doc-content li {
    margin: 0.25rem 0;
    line-height: 1.625;
}

.doc-content a {
    color: var(--doc-primary);
    text-decoration: underline;
}

.doc-content a:hover {
    color: var(--doc-primary-hover);
}

.doc-content strong,
.doc-content b {
    font-weight: 700 !important;
}

.doc-content em {
    font-style: italic;
}

.doc-content blockquote {
    border-left: 4px solid #d1d5db;
    padding: 0.5rem 0 0.5rem 1rem;
    margin: 1rem 0;
    color: #4b5563;
    font-style: italic;
}

.doc-content hr {
    border: 0;
    border-top: 1px solid #e5e7eb;
    margin: 1.5rem 0;
}

.doc-content img {
    max-width: 100%;
    height: auto;
    border-radius: 0.375rem;
    margin: 1rem 0;
}

.doc-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.875rem;
}

.doc-content th {
    background-color: #f9fafb;
    font-weight: 600;
    text-align: left;
    padding: 0.625rem 0.75rem;
    border: 1px solid #d1d5db;
}

.doc-content td {
    padding: 0.5rem 0.75rem;
    border: 1px solid #e5e7eb;
}

.doc-content thead {
    border-bottom: 2px solid #d1d5db;
}

.doc-content tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

.doc-content pre {
    background-color: #1f2937;
    color: #e5e7eb;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 1rem 0;
}

.doc-content code {
    background-color: #f3f4f6;
    color: #dc2626;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

.doc-content pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

/* ---------- Signature Pad Styling ---------- */
#signature-pad {
    cursor: crosshair;
    width: 100%;
    border-radius: 0.5rem;
}

.signature-pad-wrapper {
    position: relative;
    border: 2px solid #d1d5db;
    border-radius: 0.5rem;
    background-color: #ffffff;
    overflow: hidden;
}

.signature-pad-wrapper:focus-within {
    border-color: var(--doc-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Signature thumbnail in history */
.signature-thumbnail {
    max-height: 2rem;
    object-fit: contain;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.25rem;
    padding: 0.125rem 0.25rem;
}

/* ---------- Flash Message Styles ---------- */
.flash-message {
    animation: doc-flash-slide-in 0.3s ease-out;
}

@keyframes doc-flash-slide-in {
    from {
        opacity: 0;
        transform: translateY(-0.5rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.flash-fade-out {
    animation: doc-flash-slide-out 0.3s ease-in forwards;
}

@keyframes doc-flash-slide-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-0.5rem);
    }
}

/* ---------- Sidebar Transitions & Hover (Admin layout) ---------- */
#sidebar {
    transition: transform 0.3s ease-in-out;
}

.sidebar-link {
    transition: background-color 0.15s ease, color 0.15s ease, padding-left 0.15s ease;
    position: relative;
}

.sidebar-link:hover:not(.active) {
    padding-left: 1rem;
}

.sidebar-link.active {
    background-color: rgba(99, 102, 241, 0.3);
    color: #ffffff;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: var(--doc-primary);
    border-radius: 0 2px 2px 0;
}

/* ---------- Responsive Utilities ---------- */

/* Touch-friendly tap targets on mobile */
@media (max-width: 640px) {
    .touch-target {
        min-height: 44px;
        min-width: 44px;
    }

    /* Larger font for mobile readability */
    .doc-content {
        font-size: 1rem;
    }

    .doc-content h1 {
        font-size: 1.5rem !important;
    }

    .doc-content h2 {
        font-size: 1.25rem !important;
    }

    .doc-content h3 {
        font-size: 1.125rem !important;
    }

    .doc-content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ---------- Loading Spinner ---------- */
@keyframes doc-spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.doc-spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--doc-primary);
    border-radius: 50%;
    animation: doc-spin 0.6s linear infinite;
}

.doc-spinner--sm {
    width: 1rem;
    height: 1rem;
    border-width: 2px;
}

/* ---------- Smooth Page Transitions ---------- */
main {
    animation: doc-page-fade-in 0.2s ease-out;
}

@keyframes doc-page-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ---------- Focus Ring for Accessibility ---------- */
*:focus-visible {
    outline: 2px solid var(--doc-primary);
    outline-offset: 2px;
}

/* ---------- Disabled State ---------- */
[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- Print Styles ---------- */
@media print {
    /* Hide navigation, flash messages, and interactive elements */
    header,
    footer,
    .no-print,
    .flash-message,
    #sidebar,
    #sidebar-overlay,
    nav.fixed {
        display: none !important;
    }

    /* Remove layout constraints */
    main {
        margin: 0 !important;
        padding: 0 !important;
        max-width: none !important;
        animation: none !important;
    }

    body {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 12pt;
    }

    /* Clean document content for print */
    .doc-content {
        font-size: 11pt;
    }

    .doc-content a {
        color: #000000 !important;
        text-decoration: none !important;
    }

    .doc-content table {
        page-break-inside: avoid;
    }

    .doc-content th {
        background-color: #e2e8f0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .doc-content tbody tr:nth-child(even) {
        background-color: #f8fafc !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .doc-content img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }

    /* Avoid page breaks in awkward places */
    h1, h2, h3, h4 {
        page-break-after: avoid;
    }

    .bg-white {
        box-shadow: none !important;
        border: none !important;
    }

    /* Ensure signature images print with background */
    .signature-print img {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        max-height: 80px;
    }

    .signature-print {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        border: 1px solid #e5e7eb !important;
    }

    /* Remove links after URLs in print */
    a[href]::after {
        content: none !important;
    }
}

/* ---------- Quill-generated Class Support ---------- */
/* These rules ensure content created in the Quill rich-text editor renders
   correctly in portal views (document, sign, policies) where Quill's own
   CSS (quill.snow.css) is NOT loaded. */

.doc-content .ql-align-center { text-align: center; }
.doc-content .ql-align-right  { text-align: right; }
.doc-content .ql-align-justify { text-align: justify; }

.doc-content .ql-indent-1 { padding-left: 3em; }
.doc-content .ql-indent-2 { padding-left: 6em; }
.doc-content .ql-indent-3 { padding-left: 9em; }
.doc-content .ql-indent-4 { padding-left: 12em; }
.doc-content .ql-indent-5 { padding-left: 15em; }
.doc-content .ql-indent-6 { padding-left: 18em; }
.doc-content .ql-indent-7 { padding-left: 21em; }
.doc-content .ql-indent-8 { padding-left: 24em; }

.doc-content .ql-size-small  { font-size: 0.75em; }
.doc-content .ql-size-large  { font-size: 1.5em; }
.doc-content .ql-size-huge   { font-size: 2.5em; }

.doc-content .ql-font-serif    { font-family: 'Libre Baskerville', 'Times New Roman', Times, serif; }
.doc-content .ql-font-monospace { font-family: monospace; }

.doc-content .ql-syntax,
.doc-content pre.ql-syntax {
    background-color: #1f2937;
    color: #e5e7eb;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 1rem 0;
}

.doc-content .ql-direction-rtl { direction: rtl; text-align: inherit; }
.doc-content .ql-video { width: 100%; max-width: 560px; height: 315px; margin: 1rem 0; }

.doc-content u { text-decoration: underline; }
.doc-content s { text-decoration: line-through; }
.doc-content sub { vertical-align: sub; font-size: smaller; }
.doc-content sup { vertical-align: super; font-size: smaller; }

/* ---------- Barcode Field Highlight ---------- */
.barcode-field-active {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4);
    border-color: var(--doc-primary) !important;
}

/* ---------- Dynamic Theme: Tailwind Class Overrides ---------- */
.bg-indigo-600 { background-color: var(--doc-primary) !important; }
.hover\:bg-indigo-700:hover { background-color: var(--doc-primary-hover) !important; }
.focus\:ring-indigo-500:focus { --tw-ring-color: var(--doc-primary) !important; }
.focus\:border-indigo-500:focus { border-color: var(--doc-primary) !important; }
.text-indigo-600 { color: var(--doc-primary) !important; }
.hover\:text-indigo-800:hover { color: var(--doc-primary-hover) !important; }
.border-indigo-500 { border-color: var(--doc-primary) !important; }
