/* Sistema visual central do FHAgroLink. Carregado por config.php em todas as páginas HTML. */
html[data-theme] {
    --theme-primary: #2d5a27;
    --theme-primary-strong: #173c27;
    --theme-primary-soft: #e9f2e5;
    --theme-primary-rgb: 45, 90, 39;
    --theme-canvas-start: #10251a;
    --theme-canvas-middle: #193426;
    --theme-canvas-end: #2d5a27;
    --theme-surface: #ffffff;
    --theme-surface-raised: #f8fbf5;
    --theme-surface-soft: #f1f6ed;
    --theme-input: #ffffff;
    --theme-text: #243126;
    --theme-muted: #667065;
    --theme-border: #d6dfd1;
    --theme-on-primary: #ffffff;
    --theme-sidebar: rgba(10, 28, 18, 0.76);
    --theme-shadow: 0 24px 60px rgba(7, 24, 11, 0.28);
    --theme-focus: rgba(45, 90, 39, 0.18);
    color-scheme: light;
}

html[data-theme="blue"] {
    --primary-green: #235ea8;
    --secondary-green: #397dcc;
    --text-dark: #1d2d42;
    --text-light: #637188;
    --border-color: #cfdaea;
    --surface: rgba(255, 255, 255, 0.96);
    --surface-strong: #f5f8fd;
    --theme-primary: #235ea8;
    --theme-primary-strong: #123d73;
    --theme-primary-soft: #e7f0fb;
    --theme-primary-rgb: 35, 94, 168;
    --theme-canvas-start: #0c2038;
    --theme-canvas-middle: #123d66;
    --theme-canvas-end: #235ea8;
    --theme-surface-raised: #f5f8fd;
    --theme-surface-soft: #edf3fb;
    --theme-text: #1d2d42;
    --theme-muted: #637188;
    --theme-border: #cfdaea;
    --theme-sidebar: rgba(8, 28, 53, 0.80);
    --theme-shadow: 0 24px 60px rgba(7, 28, 54, 0.28);
    --theme-focus: rgba(35, 94, 168, 0.18);
}

html[data-theme="dark"] {
    --primary-green: #d9b66f;
    --secondary-green: #ad7f31;
    --white: #f7f7f8;
    --text-dark: #f4f4f5;
    --text-light: #a5a6ad;
    --border-color: #33343a;
    --surface: rgba(17, 18, 21, 0.98);
    --surface-strong: #18191d;
    --shadow: 0 28px 70px rgba(0, 0, 0, 0.62);
    --theme-primary: #d9b66f;
    --theme-primary-strong: #f2d79f;
    --theme-primary-soft: #2b2418;
    --theme-primary-rgb: 217, 182, 111;
    --theme-canvas-start: #000000;
    --theme-canvas-middle: #070708;
    --theme-canvas-end: #101114;
    --theme-surface: #111215;
    --theme-surface-raised: #18191d;
    --theme-surface-soft: #212228;
    --theme-input: #0b0c0e;
    --theme-text: #f4f4f5;
    --theme-muted: #a5a6ad;
    --theme-border: #33343a;
    --theme-on-primary: #171109;
    --theme-sidebar: rgba(0, 0, 0, 0.94);
    --theme-shadow: 0 28px 70px rgba(0, 0, 0, 0.62);
    --theme-focus: rgba(217, 182, 111, 0.28);
    color-scheme: dark;
}

html[data-theme] body {
    background:
        radial-gradient(circle at top left, rgba(217, 182, 111, 0.20), transparent 32%),
        radial-gradient(circle at bottom right, rgba(var(--theme-primary-rgb), 0.36), transparent 28%),
        linear-gradient(135deg, var(--theme-canvas-start) 0%, var(--theme-canvas-middle) 45%, var(--theme-canvas-end) 100%);
    color: var(--theme-text);
    transition: background-color .24s ease, color .24s ease;
}

html[data-theme] :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    border-color: var(--theme-border);
    background: var(--theme-input);
    color: var(--theme-text);
}

html[data-theme] :where(input, select, textarea):focus {
    border-color: var(--theme-primary);
    box-shadow: 0 0 0 3px var(--theme-focus);
}

html[data-theme] :where(input, textarea)::placeholder {
    color: var(--theme-muted);
    opacity: .78;
}

html[data-theme] :where(input[type="checkbox"], input[type="radio"]) {
    accent-color: var(--theme-primary);
}

html[data-theme] :where(.app-sidebar, .sidebar) {
    background: var(--theme-sidebar);
}

html[data-theme] :where(.btn-submit, .btn-logout, .btn-primary, .settings-summary-action, .recovery-code-copy, .implement-yield-add) {
    background: linear-gradient(135deg, var(--theme-primary), var(--secondary-green));
    color: var(--theme-on-primary);
    box-shadow: 0 14px 28px rgba(var(--theme-primary-rgb), .22);
}

html[data-theme] :where(.panel-title, .section-title, .settings-form-heading h2, .settings-user-head h3, .settings-user-meta strong, .settings-user-section > summary, .settings-permission-box strong, .auth-recovery-link) {
    color: var(--theme-primary);
}

html[data-theme] :where(.content-card, .manager-card, .manager-panel, .list-card) {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: var(--theme-shadow);
}

html[data-theme] :where(.section-description, .list-head span, .field-hint, .empty-state, .empty-row) {
    color: var(--theme-muted);
}

html[data-theme="blue"] :where(.content-subnav-secondary .subnav-link, .checkbox-field) {
    border-color: rgba(35, 94, 168, .24);
    background: var(--theme-primary-soft);
    color: var(--theme-primary-strong);
}

html[data-theme="blue"] :where(.sidebar-link:hover, .sidebar-link.active) {
    border-color: rgba(151, 200, 255, .42);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.16), 0 12px 28px rgba(1, 16, 36, .24);
}

html[data-theme="blue"] :where(.settings-admin-overview article, .settings-user-card, .settings-create-card > summary, .settings-archive-card > summary) {
    border-color: rgba(35, 94, 168, .18);
    background: linear-gradient(145deg, #ffffff, #edf4fc);
}

html[data-theme="blue"] :where(.settings-user-avatar, .settings-archive-card > summary > span) {
    background: linear-gradient(135deg, #235ea8, #397dcc);
}

html[data-theme="blue"] :where(.dashboard-hero, .dashboard-kpi.accent) {
    background: linear-gradient(125deg, #0d2d50 0%, #174f83 58%, #3278bd 100%);
}

html[data-theme="blue"] :where(.dashboard-table th, .data-table th) {
    background: #123d73;
}

/* O modo escuro também neutraliza cores claras antigas e estilos locais das páginas. */
html[data-theme="dark"] :where(
    .login-card, .content-card, .manager-card, .manager-panel, .list-card,
    .form-card, .table-card, .dashboard-filter-card, .dashboard-panel, .dashboard-kpi,
    .settings-admin-overview article, .settings-create-card, .settings-archive-card,
    .settings-user-card, .settings-user-section, .settings-permission-box,
    .settings-create-options .toggle-row, .settings-recovery-grant,
    .application-modal-card, .supervisor-modal-card, .audit-undo-dialog,
    dialog, .offline-card, .implement-operation-yields, .implement-yield-row
) {
    border-color: var(--theme-border) !important;
    background: var(--theme-surface) !important;
    color: var(--theme-text) !important;
    box-shadow: var(--theme-shadow);
}

html[data-theme="dark"] :where(
    .settings-create-card > summary, .settings-archive-card > summary,
    .settings-create-form, .settings-user-meta > span, .content-subnav-secondary .subnav-link,
    .checkbox-field, .chip, .filter-card, .toolbar, .table-wrap,
    .dashboard-legend-item, .dashboard-empty, .application-pill,
    .supervisor-modal-operation, .implement-yield-empty
) {
    border-color: var(--theme-border) !important;
    background: var(--theme-surface-raised) !important;
    color: var(--theme-text) !important;
}

html[data-theme="dark"] body {
    background:
        radial-gradient(circle at 14% 8%, rgba(217, 182, 111, .10), transparent 26%),
        radial-gradient(circle at 88% 92%, rgba(255, 255, 255, .035), transparent 30%),
        linear-gradient(145deg, #000 0%, #070708 52%, #101114 100%);
}

html[data-theme="dark"] :where(.app-sidebar, .sidebar) {
    border-color: #24252a;
    background: linear-gradient(180deg, rgba(0,0,0,.97), rgba(8,8,10,.97));
    box-shadow: 18px 0 55px rgba(0,0,0,.24);
}

html[data-theme="dark"] :where(.content-header, .settings-hero-header, .dashboard-hero) {
    border-color: #343238 !important;
    background:
        radial-gradient(circle at 88% 12%, rgba(217,182,111,.14), transparent 30%),
        linear-gradient(135deg, #08080a, #17171a) !important;
    color: #f7f7f8 !important;
}

html[data-theme="dark"] :where(.sidebar-link:hover, .sidebar-link.active) {
    border-color: rgba(217,182,111,.44);
    background: linear-gradient(135deg, rgba(217,182,111,.15), rgba(255,255,255,.055));
    box-shadow: inset 3px 0 0 #d9b66f, 0 14px 30px rgba(0,0,0,.30);
}

html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class$="-card"],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="-card "],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class$="-panel"],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="-panel "],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class$="-tile"],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="-tile "],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="summary"],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="stat-"],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="metric"],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="toolbar"],
html[data-theme="dark"] :where(section, article, div, form, dialog, aside, a)[class*="filter"] {
    border-color: var(--theme-border) !important;
    background: var(--theme-surface) !important;
    color: var(--theme-text);
    box-shadow: var(--theme-shadow);
}

html[data-theme="dark"] :where(
    .ai-workspace, .ai-context-panel, .ai-conversation, .ai-messages,
    .ai-message-assistant, .ai-result-card, .ai-composer,
    .ai-suggestions button, .ai-tool-button, .ai-safety-note,
    .audit-content, .audit-module-tab, .audit-summary article,
    .audit-group, .audit-details, .audit-events, .audit-event,
    .audit-change-table, .audit-empty, .audit-pagination a, .audit-pagination span,
    .offline-hero, .offline-hero-actions, .offline-status-card,
    .offline-flow, .offline-step, .offline-manager-section,
    .offline-fast-toggle, .offline-package, .offline-install-help,
    .map-panel, .results-panel
) {
    border-color: var(--theme-border) !important;
    background: var(--theme-surface) !important;
    color: var(--theme-text);
    box-shadow: var(--theme-shadow);
}

html[data-theme="dark"] :where(.ai-hero, .offline-hero) {
    background:
        radial-gradient(circle at 92% 12%, rgba(217,182,111,.18), transparent 30%),
        linear-gradient(135deg, #070708, #19191d) !important;
}

html[data-theme="dark"] :where(
    .audit-change-row > *, .audit-change-header,
    .audit-undone-note, .audit-details[open] > summary,
    .audit-module-pill, .audit-action, .audit-avatar
) {
    border-color: var(--theme-border) !important;
    background: var(--theme-surface-raised) !important;
}

html[data-theme="dark"] .audit-content :where(
    h1, h2, h3, h4, h5, h6, div, p, span, label, strong, small,
    li, td, th, time, summary, a
) {
    color: var(--theme-text) !important;
}

html[data-theme="dark"] .audit-content :where(
    p, small, time, .audit-group-who span, .audit-group-summary,
    .audit-event-description, .audit-technical, .audit-group-footer small
) {
    color: var(--theme-muted) !important;
}

html[data-theme="dark"] :where(
    .ai-message-user, .offline-global-progress,
    .audit-hero-status, .offline-package-icon, .offline-step-number
) {
    border-color: #4b402a !important;
    background: linear-gradient(135deg, #252017, #121214) !important;
    color: #f7f7f8 !important;
}

html[data-theme="dark"] :where(
    h1, h2, h3, h4, h5, h6, p, span, label, strong, small,
    li, td, th, time, summary, a
) {
    color: var(--theme-text);
}

html[data-theme="dark"] :where(
    p, small, .section-description, .list-head span, .field-hint
) {
    color: var(--theme-muted);
}

html[data-theme="dark"] :where(
    .panel-title, .section-title, .list-head strong,
    .settings-admin-overview strong, .settings-form-grid label,
    .settings-user-head h3, .settings-user-meta strong,
    .settings-user-section > summary, .settings-recovery-grant h2,
    .dashboard-filter-head h3, .dashboard-panel-head h3,
    .dashboard-kpi strong, .dashboard-table td strong,
    .offline-card h1
) {
    color: var(--theme-text);
}

html[data-theme="dark"] :where(
    .section-description, .list-head span, .field-hint,
    .settings-admin-overview span, .settings-admin-overview small,
    .settings-form-heading p, .settings-permission-box span,
    .settings-user-head p, .settings-user-meta small,
    .settings-archive-list small, .dashboard-filter-head p,
    .dashboard-panel-head p, .dashboard-kpi span, .dashboard-kpi small,
    .dashboard-table td, .offline-card p
) {
    color: var(--theme-muted);
}

html[data-theme="dark"] :where(table, .data-table, .dashboard-table) {
    color: var(--theme-text);
    background: var(--theme-surface);
}

html[data-theme="dark"] :where(td, th) {
    border-color: var(--theme-border) !important;
}

html[data-theme="dark"] :where(tbody tr:nth-child(even), tbody tr:hover) {
    background: rgba(217, 182, 111, .055);
}

html[data-theme="dark"] :where(.data-table th, .dashboard-table th) {
    background: #070708 !important;
    color: #f4f4f5 !important;
}

html[data-theme="dark"] :where(.table-action, .btn-inline, button.secondary, .secondary-inline) {
    border-color: var(--theme-border) !important;
    background: var(--theme-surface-soft) !important;
    color: var(--theme-text) !important;
}

html[data-theme="dark"] :where(.settings-status-pill.active, .status-pill.success) {
    background: #183622 !important;
    color: #b9e7c5 !important;
}

html[data-theme="dark"] .settings-user-avatar {
    border: 1px solid #e5c47f;
    background: linear-gradient(135deg, #e5c47f, #b78635);
    color: #171109 !important;
}

html[data-theme="dark"] :where(.settings-status-pill.inactive, .status-pill.warning) {
    background: #463529 !important;
    color: #f0c79e !important;
}

html[data-theme="dark"] :where(.form-message.success, .dashboard-order-message) {
    border-color: #356b43 !important;
    background: #142d1c !important;
    color: #c5edcf !important;
}

html[data-theme="dark"] :where(.form-message.error, .dashboard-order-message.error, .table-action.danger) {
    border-color: #79453d !important;
    background: #3a211d !important;
    color: #ffc4b8 !important;
}

html[data-theme="dark"] :where(.settings-ceo-protected, .dashboard-note) {
    border-color: #735e37 !important;
    background: #3a301e !important;
    color: #f2d39a !important;
}

html[data-theme="dark"] :where(.leaflet-control, .leaflet-bar a, .leaflet-popup-content-wrapper, .leaflet-popup-tip) {
    border-color: var(--theme-border) !important;
    background: var(--theme-surface-raised) !important;
    color: var(--theme-text) !important;
}

html[data-theme="dark"] :where(.btn-submit, .btn-logout, .btn-primary, .settings-summary-action, .recovery-code-copy, .implement-yield-add) {
    background: linear-gradient(135deg, #e1c078, #ad7f31);
    color: #171109;
    box-shadow: 0 16px 34px rgba(217,182,111,.20);
}

html[data-theme="dark"] :where(a, button, summary) {
    text-underline-offset: 3px;
}

html[data-theme="dark"] :where(.eyebrow, .section-kicker, .ai-kicker, .dashboard-eyebrow) {
    color: #e6bd67 !important;
}

html[data-theme="dark"] :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    border-color: #383940 !important;
    background: #0b0c0e !important;
    color: #f4f4f5 !important;
}

html[data-theme="dark"] :where(input, textarea)::placeholder {
    color: #81838c !important;
    opacity: 1;
}

html[data-theme="dark"] [data-fh-contrast="dark"] {
    color: #17181c !important;
}

html[data-theme="dark"] [data-fh-contrast="light"] {
    color: #f7f7f8 !important;
}

html[data-theme="dark"] .theme-option:not(.is-selected) .theme-option-check {
    color: transparent !important;
}

html[data-theme="dark"] {
    scrollbar-color: #55565e #09090a;
}

/* Seletor de aparência em Configurações. */
.theme-settings-card {
    overflow: hidden;
    padding: clamp(20px, 3vw, 28px);
    border: 1px solid rgba(var(--theme-primary-rgb), .22);
    border-radius: 26px;
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: 0 18px 42px rgba(8, 37, 19, .14);
}

.theme-settings-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
}

.theme-settings-heading h2 {
    margin: 4px 0 0;
    color: var(--theme-primary);
    font-size: clamp(1.25rem, 2vw, 1.6rem);
}

.theme-settings-heading p {
    max-width: 590px;
    margin: 0;
    color: var(--theme-muted);
    line-height: 1.55;
}

.theme-option-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.theme-option {
    position: relative;
    display: grid;
    grid-template-columns: 74px minmax(0, 1fr) 28px;
    align-items: center;
    gap: 14px;
    min-height: 104px;
    padding: 15px;
    border: 2px solid var(--theme-border);
    border-radius: 20px;
    background: var(--theme-surface-raised);
    color: var(--theme-text);
    text-align: left;
    font: inherit;
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.theme-option:hover {
    transform: translateY(-2px);
    border-color: rgba(var(--theme-primary-rgb), .52);
}

.theme-option:focus-visible {
    outline: 4px solid var(--theme-focus);
    outline-offset: 2px;
}

.theme-option.is-selected {
    border-color: var(--theme-primary);
    box-shadow: 0 12px 30px rgba(var(--theme-primary-rgb), .18);
}

.theme-preview {
    display: grid;
    grid-template-columns: 20px 1fr;
    grid-template-rows: 20px 1fr;
    width: 74px;
    height: 68px;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,.12);
    border-radius: 14px;
    background: var(--preview-canvas);
    box-shadow: 0 8px 18px rgba(0,0,0,.12);
}

.theme-preview::before {
    content: "";
    grid-row: 1 / -1;
    background: var(--preview-sidebar);
}

.theme-preview::after {
    content: "";
    grid-column: 2;
    grid-row: 2;
    margin: 7px;
    border-radius: 6px;
    background: var(--preview-surface);
    box-shadow: inset 0 4px 0 var(--preview-accent);
}

.theme-preview-green { --preview-canvas: #eaf2e5; --preview-sidebar: #173c27; --preview-surface: #fff; --preview-accent: #2d5a27; }
.theme-preview-dark { --preview-canvas: #070708; --preview-sidebar: #000; --preview-surface: #18191d; --preview-accent: #d9b66f; }
.theme-preview-blue { --preview-canvas: #e7f0fb; --preview-sidebar: #123d73; --preview-surface: #fff; --preview-accent: #235ea8; }

.theme-option-copy {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.theme-option-copy strong { color: var(--theme-text); font-size: .98rem; }
.theme-option-copy small { color: var(--theme-muted); font-size: .73rem; line-height: 1.4; }

.theme-option-check {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border: 2px solid var(--theme-border);
    border-radius: 50%;
    color: transparent;
    font-weight: 900;
}

.theme-option.is-selected .theme-option-check {
    border-color: var(--theme-primary);
    background: var(--theme-primary);
    color: var(--theme-on-primary);
}

.theme-settings-footnote {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 16px 2px 0;
    color: var(--theme-muted);
    font-size: .78rem;
}

.theme-settings-footnote strong { color: var(--theme-primary); }

@media (max-width: 900px) {
    .theme-option-grid { grid-template-columns: 1fr; }
    .theme-settings-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
}

@media (max-width: 560px) {
    .theme-option { grid-template-columns: 62px minmax(0, 1fr) 26px; padding: 12px; }
    .theme-preview { width: 62px; height: 60px; }
    .theme-settings-footnote { align-items: flex-start; flex-direction: column; }
}

@media print {
    html[data-theme] { color-scheme: light; }
    html[data-theme] body { background: #fff !important; color: #111 !important; }
    html[data-theme] body * { color: #111 !important; text-shadow: none !important; }
    html[data-theme] :where(.content-card, .manager-card, .manager-panel, .list-card, table, td) {
        background: #fff !important;
        color: #111 !important;
        border-color: #bbb !important;
        box-shadow: none !important;
    }
    .theme-settings-card { display: none !important; }
}
