/*
 * Condensed contract-editor styling (helder-maritiem).
 *
 * Overrides Filament 5's default RichEditor table styling on the *editing*
 * surface (.fi-fo-rich-editor .tiptap). Filament sets `border border-gray-300`
 * and `!p-2` (0.5rem !important) on every cell; here we lighten the borders so
 * the grid recedes and tighten padding so the table reads compactly — matching
 * the condensed PDF output (resources/views/pdf/contract.blade.php).
 *
 * Registered via FilamentAsset::register([Css::make('contract-editor', …)]) in
 * AdminPanelProvider. This is a static asset (NOT Tailwind-compiled), so it
 * uses plain CSS — no @apply. Re-run `php artisan filament:assets` and commit
 * the published public/css artifact after editing (stale-artifact rule).
 */

/* Keep the formatting toolbar reachable on long contracts: stick it just
   below the panel topbar (.fi-topbar-ctn, sticky top-0 h-16 z-30) while the
   page scrolls. Filament's default is position: relative with a transparent
   background, so an opaque background is required to hide the content
   scrolling underneath. z-index sits below the topbar (30) but above the
   floating toolbar / editor content (20). Top corners match the input
   wrapper's rounded-lg. */
.fi-fo-rich-editor .fi-fo-rich-editor-toolbar {
    position: sticky;
    top: 4rem;
    z-index: 25;
    background-color: #fff;
    border-radius: 0.5rem 0.5rem 0 0;
}

.dark .fi-fo-rich-editor .fi-fo-rich-editor-toolbar {
    background-color: #111827; /* gray-900: composite of dark input bg over the page */
}

/* Whole-table whitespace — margin on the table (not rows) so only the outer
   edges gain space. Mirrors the PDF rule in pdf/contract.blade.php. */
.fi-fo-rich-editor .tiptap table {
    margin: 1em 0;
}

.fi-fo-rich-editor .tiptap table td,
.fi-fo-rich-editor .tiptap table th {
    /* Beat Filament's `!p-2` (0.5rem !important) to condense rows. */
    padding: 2px 6px !important;
    /* Fainter than the default gray-300 so the grid lines stay subtle. */
    border-color: #eceef1;
    line-height: 1.3;
}

.fi-fo-rich-editor .tiptap table th {
    /* Softer header fill than the default gray-100. */
    background-color: #f7f8f9;
}

.dark .fi-fo-rich-editor .tiptap table td,
.dark .fi-fo-rich-editor .tiptap table th {
    border-color: rgba(255, 255, 255, 0.08);
}

.dark .fi-fo-rich-editor .tiptap table th {
    background-color: rgba(255, 255, 255, 0.04);
}

/* Nudge the editor body font down for parity with the smaller (~10pt) PDF. */
.fi-fo-rich-editor .tiptap {
    font-size: 0.9rem;
}

/* First column lines up with body text — beat Filament's `!p-2` left padding.
   Mirrors the PDF rule in resources/views/pdf/contract.blade.php so the editor
   preview matches the rendered contract. */
.fi-fo-rich-editor .tiptap table tr > :first-child {
    padding-left: 0 !important;
}

/* 2-column tables (max 2 cols) get the same fixed 35% title column as the PDF.
   Only for tables never resized by hand — once a column border is dragged the
   cells carry data-colwidth and TipTap's own colgroup widths take over (the
   PDF mirrors this via TableColumnWidths). */
.fi-fo-rich-editor .tiptap table:has(td:nth-child(2)):not(:has(td:nth-child(3))):not(:has([data-colwidth])),
.fi-fo-rich-editor .tiptap table:has(th:nth-child(2)):not(:has(th:nth-child(3))):not(:has([data-colwidth])) {
    table-layout: fixed;
}
.fi-fo-rich-editor .tiptap table:has(td:nth-child(2)):not(:has(td:nth-child(3))):not(:has([data-colwidth])) tr > :first-child,
.fi-fo-rich-editor .tiptap table:has(th:nth-child(2)):not(:has(th:nth-child(3))):not(:has([data-colwidth])) tr > :first-child {
    width: 35%;
}

/* Pin the merge-tag placeholder panel to the bottom of the viewport so it
   stays reachable while scrolling long contracts. Complements the toolbar
   sticky-top rule above. The class is attached to the ViewField wrapper via
   ->extraAttributes() in ContractTemplateResource. */
.contract-placeholder-panel-sticky {
    position: sticky;
    bottom: 0;
    z-index: 25;
    background-color: #fff;
    border-top: 1px solid #e5e7eb;
    padding-top: 0.5rem;
}

.dark .contract-placeholder-panel-sticky {
    background-color: #111827;
    border-top-color: #374151;
}
