/* Paletas do painel: claro por padrão, escuro pela classe do Filament. */
:root {
    --dash-page: radial-gradient(ellipse at 65% 0%, #ffffff 0%, #f2f9ff 55%, #eaf6ff 100%);
    --dash-topbar: linear-gradient(110deg, #edf8ff, #ffffff);
    --dash-sidebar: linear-gradient(160deg, #ffffff, #f7fcff 65%, #eaf6ff);
    --dash-shell-border: #d8eaff;
    --dash-shell-text: #234888;
    --dash-heading: #080e3d;
    --dash-active-bg: linear-gradient(100deg, #0084ff, #006aff);
    --dash-accent: #0075ff;
    --dash-active-text: #ffffff;
    --dash-active-shadow: 0 2px 12px #0075ff26;
    --dash-surface: linear-gradient(120deg, #ffffff, #fbfdff 75%);
    --dash-surface-shadow: 0 3px 16px #0075ff08;
    --dash-icon-bg: #eaf2ff;
    --dash-success-bg: #dcfcf3;
    --dash-warning-bg: #fff8e5;
    --dash-info-bg: #e5f5ff;
    --dash-subtle-bg: #f1f8ff;
    --dash-button-text: #ffffff;
    --dash-button-bg: linear-gradient(#0085ff, #006aff);
    --dash-button-border: #0075ff;
    --dash-calendar-active: #0075ff;
    --dash-grid: #dcecff;
    --dash-chart-text: #5275ac;
    --dash-chart-fill: rgba(0, 117, 255, .14);
}
html.dark {
    --dash-page: radial-gradient(ellipse at 65% 0%, #071b33 0%, #030e19 48%, #040c14 100%);
    --dash-topbar: linear-gradient(110deg, #0a1c30, #04101e);
    --dash-sidebar: linear-gradient(160deg, #0b1927, #06121f 65%, #07192c);
    --dash-shell-border: #16334d;
    --dash-shell-text: #bdd0e6;
    --dash-heading: #f4f7ff;
    --dash-active-bg: linear-gradient(100deg, #44330b, #292510);
    --dash-accent: #ffc400;
    --dash-active-text: #ffc400;
    --dash-active-shadow: 0 0 14px #ffbf0026;
    --dash-surface: linear-gradient(120deg, #0c1b2b, #07131f 75%);
    --dash-surface-shadow: inset 0 1px 0 #228bff0d, 0 4px 16px #00000012;
    --dash-icon-bg: #173353;
    --dash-success-bg: #00372f;
    --dash-warning-bg: #302b10;
    --dash-info-bg: #072b4d;
    --dash-subtle-bg: #102034;
    --dash-button-text: #171c24;
    --dash-button-bg: linear-gradient(#ffd02a, #ffb700);
    --dash-button-border: #ffd740;
    --dash-calendar-active: #493709;
    --dash-grid: #21384d;
    --dash-chart-text: #aec5e0;
    --dash-chart-fill: rgba(255, 196, 0, .14);
}

/* Tokens partilhados por componentes nativos e páginas personalizadas. */
:root {
    --app-text: #080e3d;
    --app-secondary: #304f8c;
    --app-muted: #6484b7;
    --app-faint: #6f8db9;
    --app-surface: #ffffff;
    --app-subtle: #f2f8ff;
    --app-border: #d7eaff;
    --app-divider: #e0edfc;
    --app-hover: #eaf4ff;
    --app-accent: #0075ff;
    --app-on-accent: #ffffff;
    --app-accent-soft: #e5f1ff;
}
html.dark {
    --app-text: #f1f5ff;
    --app-secondary: #bdd0e6;
    --app-muted: #9bb8d8;
    --app-faint: #7f9abb;
    --app-surface: #091623;
    --app-subtle: #102033;
    --app-border: #173d60;
    --app-divider: #1a2e42;
    --app-hover: #142b42;
    --app-accent: #ffc400;
    --app-on-accent: #171c24;
    --app-accent-soft: #302b10;
}
html:root {
    --primary-50: #eff7ff;
    --primary-100: #dceeff;
    --primary-200: #bddfff;
    --primary-300: #8fcaff;
    --primary-400: #4ca5ff;
    --primary-500: #0075ff;
    --primary-600: #0065e0;
    --primary-700: #0051b8;
    --primary-800: #06458f;
    --primary-900: #103b73;
    --primary-950: #08234c;
    --gray-50: #f2f8ff;
    --gray-100: #eaf4ff;
    --gray-200: #d7eaff;
    --gray-300: #bdd0e6;
    --gray-400: #9bb8d8;
    --gray-500: #6484b7;
    --gray-600: #304f8c;
    --gray-700: #234568;
    --gray-800: #17334d;
    --gray-900: #091623;
    --gray-950: #030e19;
}
html.dark {
    --primary-50: #fffbdf;
    --primary-100: #fff3ad;
    --primary-200: #ffe778;
    --primary-300: #ffda3d;
    --primary-400: #ffd02a;
    --primary-500: #ffc400;
    --primary-600: #dca500;
    --primary-700: #ae7e00;
    --primary-800: #8b6109;
    --primary-900: #725011;
    --primary-950: #422b06;
    --gray-50: #f2f8ff;
    --gray-100: #eaf4ff;
    --gray-200: #d7eaff;
    --gray-300: #bdd0e6;
    --gray-400: #9bb8d8;
    --gray-500: #6484b7;
    --gray-600: #304f8c;
    --gray-700: #234568;
    --gray-800: #17334d;
    --gray-900: #091623;
    --gray-950: #030e19;
}
body.fi-body {
    background: var(--dash-page);
}

body.fi-body .fi-topbar {
    background: var(--dash-topbar);
    border-bottom: 1px solid var(--dash-shell-border);
    color: var(--dash-shell-text);
}
body.fi-body .fi-sidebar {
    background: var(--dash-sidebar);
    border-right: 1px solid var(--dash-shell-border);
    color: var(--dash-shell-text);
}
body.fi-body :is(.fi-sidebar-item-label, .fi-sidebar-group-label, .fi-sidebar-item-icon, .fi-logo, .fi-topbar .fi-icon-btn) { color: var(--dash-shell-text); }
body.fi-body .fi-sidebar-item-active > .fi-sidebar-item-btn {
    background: var(--dash-active-bg);
    border: 1px solid var(--dash-accent);
    box-shadow: var(--dash-active-shadow);
}
body.fi-body .fi-sidebar-item-active :is(.fi-sidebar-item-label, .fi-sidebar-item-icon) { color: var(--dash-active-text); }

/* Superfícies nativas, incluindo login, diálogos e menus suspensos. */
body.fi-body { color: var(--app-text); }
.fi-body :is(.fi-section, .fi-ta-ctn, .fi-wi-stats-overview-stat, .fi-simple-main) {
    background: var(--dash-surface);
    border-color: var(--app-border);
    --tw-ring-color: var(--app-border);
    box-shadow: 0 0 0 1px var(--app-border), var(--dash-surface-shadow);
}
.fi-body :is(.fi-modal-window, .fi-modal-header, .fi-modal-footer, .fi-dropdown-panel, .fi-global-search-results-ctn, .fi-select-panel, .fi-fo-date-time-picker-panel, .fi-no-notification) {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
    --tw-ring-color: var(--app-border);
}
.fi-body :is(.fi-header-heading, .fi-section-header-heading, .fi-modal-heading, .fi-simple-header-heading) { color: var(--app-text); }
.fi-body :is(.fi-input-wrp, .fi-fo-rich-editor, .fi-fo-markdown-editor) {
    background-color: var(--app-surface);
    --tw-ring-color: var(--app-border);
    border-color: var(--app-border);
}
.fi-body .fi-input-wrp:focus-within { --tw-ring-color: var(--app-accent); }
.fi-body .fi-input-wrp.fi-invalid { --tw-ring-color: var(--danger-500); }
.fi-body :is(.fi-input, .fi-select-input, .fi-fo-textarea) { color: var(--app-text); }
.fi-body :is(.fi-ta-header, .fi-ta-header-toolbar, .fi-ta-table thead, .fi-ta-filters, .fi-ta-selection-indicator, .fi-tabs) {
    background-color: var(--app-subtle);
    border-color: var(--app-border);
}
.fi-body :is(.fi-ta-row, .fi-ta-cell, .fi-section-header, .fi-ta-content, .fi-ta-pagination) { border-color: var(--app-divider); }
.fi-body .fi-ta-row:hover { background-color: var(--app-hover); }
.fi-body .fi-btn.fi-color-primary:not(.fi-outlined) {
    background: var(--dash-button-bg);
    color: var(--app-on-accent);
    --text: var(--app-on-accent);
    --dark-text: var(--app-on-accent);
    --hover-text: var(--app-on-accent);
    --dark-hover-text: var(--app-on-accent);
}
.fi-body .fi-btn.fi-color-primary:not(.fi-outlined) > .fi-icon { color: var(--app-on-accent); }
.fi-body .fi-btn.fi-color-primary:not(.fi-outlined):hover:not(:disabled) { filter: brightness(1.06); }
.fi-body :is(a, button, input, select, textarea):focus-visible { outline-color: var(--app-accent); }
.fi-body .fi-wi-chart-bg-color { color: var(--app-accent-soft); }
.fi-body .fi-wi-chart-border-color { color: var(--app-accent); }
.fi-body .fi-wi-chart-grid-color { color: var(--app-divider); }
.fi-body .fi-wi-chart-text-color { color: var(--app-muted); }

/* Agenda e controles de mapas usam as mesmas superfícies do painel. */
html .fi-body .fc {
    --fc-border-color: var(--app-divider);
    --fc-page-bg-color: var(--app-surface);
    --fc-neutral-bg-color: var(--app-subtle);
    --fc-today-bg-color: var(--app-accent-soft);
    --fc-list-event-hover-bg-color: var(--app-hover);
    color: var(--app-text);
}
html .fi-body .fc .fc-button {
    background: var(--app-subtle);
    border-color: var(--app-border);
    color: var(--app-text);
}
html .fi-body .fc .fc-button:hover { background: var(--app-hover); }
html .fi-body .fc .fc-button-primary:not(:disabled).fc-button-active {
    background: var(--dash-button-bg);
    border-color: var(--app-accent);
    color: var(--app-on-accent);
}
.fi-body :is(.leaflet-popup-content-wrapper, .leaflet-popup-tip, .leaflet-bar a, .leaflet-control-layers) {
    background: var(--app-surface);
    color: var(--app-text);
    border-color: var(--app-border);
}
@media print {
    body.fi-body { background: #fff; color: #111; }
}

/* Marca compacta: logo e nome permanecem na mesma linha inclusive no login. */
.fi-body .fi-logo:has(.dynaton-brand) { width: max-content; max-width: 100%; }
/* Container integrado ao fundo: recorte, halo azul e dissolução da base. */
.dynaton-sidebar-brand {
    position: relative;
    min-height: 190px;
    margin-top: auto;
    padding-top: 16px;
    flex-shrink: 0;
    isolation: isolate;
}
.dynaton-sidebar-brand::before {
    content: "";
    position: absolute;
    inset: 24px -12px 12px;
    z-index: -1;
    background: radial-gradient(ellipse at 65% 48%, #38a6ff30, #70c8ff12 45%, transparent 72%);
    filter: blur(12px);
    pointer-events: none;
}
.dynaton-sidebar-brand__container {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;
    object-fit: contain;
    /* Remove visualmente o cenário da imagem, preservando a silhueta do container. */
    clip-path: polygon(3% 11%, 43% 8%, 97% 19%, 97% 73%, 71% 94%, 3% 57%);
    -webkit-mask-image: linear-gradient(165deg, #000 15%, #000d 42%, #0006 68%, transparent 94%);
    mask-image: linear-gradient(165deg, #000 15%, #000d 42%, #0006 68%, transparent 94%);
    filter: brightness(1.55) saturate(.85);
    opacity: .72;
    pointer-events: none;
}
.dynaton-sidebar-brand__copy {
    position: relative;
    margin-top: -42px;
    padding: 12px 4px 4px;
    color: var(--app-secondary);
    font-size: 11px;
    line-height: 1.35;
}
.dynaton-sidebar-brand__name {
    color: var(--app-text);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 3px;
}
.dark .dynaton-sidebar-brand::before {
    background: radial-gradient(ellipse at 65% 48%, #0075ff24, transparent 70%);
}
.dark .dynaton-sidebar-brand__container {
    filter: brightness(.9) saturate(1.1);
    opacity: .55;
}

/* Document surfaces are independent of the panel theme; explicit inline colors win. */
.fi-body .contrato-documento,
.fi-body .contrato-editor .fi-fo-rich-editor-content {
    background: #fff;
    color: #000000;
    --tw-prose-body: #000000;
    --tw-prose-headings: #000000;
    --tw-prose-bold: #000000;
    --tw-prose-invert-body: #000000;
    --tw-prose-invert-headings: #000000;
    --tw-prose-invert-bold: #000000;
}
.fi-body .contrato-documento { padding: 1.25rem; }
.fi-body .contrato-documento :is(.fi-prose, p, h1, h2, h3, h4, h5, h6, strong, em, li, td, th),
.fi-body .contrato-editor .fi-fo-rich-editor-content :is(p, h1, h2, h3, h4, h5, h6, strong, em, li, td, th) {
    color: inherit;
}

/* Only the contract canvas uses a light document surface, even in dark mode. */
.fi-body .contrato-editor .fi-fo-rich-editor-content {
    padding: clamp(1rem, 3vw, 2rem);
    min-width: 0;
    caret-color: #000;
    color-scheme: light;
}
.fi-body .contrato-editor .fi-fo-rich-editor-content .tiptap {
    color: #000;
    --prose-color: #000;
    --prose-heading-color: inherit;
    --prose-strong-color: inherit;
    --prose-link-color: inherit;
    --prose-code-color: inherit;
    --prose-marker-color: #6b7280;
    --prose-link-underline-color: #1565c0;
    --prose-th-borders: #9ca3af;
    --prose-td-borders: #9ca3af;
    --prose-hr-color: #9ca3af;
    --prose-blockquote-border-color: #9ca3af;
    --prose-pre-bg: #f3f4f6;
}
.fi-body .contrato-editor .fi-fo-rich-editor-content .tiptap p.is-editor-empty:first-child::before {
    color: #6b7280;
}
.fi-body .contrato-editor .fi-fo-rich-editor-content ::selection {
    background: #bfdbfe;
    color: #000;
}
.fi-body .contrato-editor .fi-fo-rich-editor-content table {
    color: inherit;
}
.fi-body .contrato-editor .fi-fo-rich-editor-content :is(td, th) {
    border-color: #9ca3af;
}
.fi-body .contrato-editor .fi-fo-rich-editor-content th {
    background-color: #f3f4f6;
}
.fi-body .contrato-editor .fi-fo-rich-editor-content .selectedCell::after {
    background: rgb(59 130 246 / 20%);
}
