/* Thème sombre : seules les couleurs changent, jamais la mise en page. */
html[data-theme='dark'] {
  color-scheme: dark;
  --app-background: #1c1512;
  --page: #201a17;
  --paper: #302622;
  --border: #50413b;
  --text: #f1ebe9;
  --muted: #bfb0aa;
  --red: #ef9696;
  --green: #a2d77d;
  --olive: #f0b27a;
  --blue: #d3a08a;
  --sidebar: #2d211c;
  /* Survols centralisés : même intensité partout. */
  --danger-bg: #3d2b2c;
  --hover-surface: #3e302a;
  --hover-control: #45362f;
  --pressed: #4f3f38;
  --hover-button: #5e4a42;
  --pressed-button: #6f5950;
}

html[data-theme='dark']
  :is(
    .nav-heading,
    .operations-toolbar .icon,
    .budget-cell b,
    .row-action,
    .account-table-order button,
    .account-table-favorite button
  ) {
  color: var(--text-secondary);
}
html[data-theme='dark']
  :is(
    .nav-item .icon,
    .kpi-tab.active,
    .op-name,
    .config-row > button,
    .forecast-actions > button:not(.forecast-apply),
    .allocation-editor button,
    .dialog-actions button:not(.save-button),
    #dropdown-menu button,
    .account-table-action button,
    .forecast-table button
  ) {
  color: var(--text);
}
html[data-theme='dark']
  :is(
    .kpi-title .icon,
    .kpi-caption,
    .kpi-tab,
    .mini-row,
    .envelope-top span,
    .envelope-rest,
    .envelope-rest .icon,
    .op-sub,
    .budget-cell,
    .budget-cell .budget-extra,
    .config-note,
    .config-row > .icon,
    .config-row > span:not(.icon),
    .forecast-account > summary span,
    .dialog-heading button,
    .edit-field,
    .allocation-editor p,
    #dropdown-menu .menu-date,
    .sort-menu-heading small,
    .sort-rank,
    .sort-add,
    .empty-state,
    .empty-row td,
    .associations-kpi #account-associations,
    .account-table-name .icon,
    .accounts-table th,
    .app-version,
    .release-entry time,
    .auth-card p,
    .auth-card label,
    #new-user-form label,
    .user-row span,
    #savings-menu .nav-label > small,
    #dropdown-menu .menu-section-title,
    #dropdown-menu .month-filter-empty,
    #release-close,
    #import-close
  ) {
  color: var(--muted);
}
html[data-theme='dark'] .envelope-rest strong {
  color: var(--text-secondary);
}
html[data-theme='dark'] :is(th, .accounts-table th) {
  color: var(--text-secondary);
}
html[data-theme='dark'] :is(input, select, textarea) {
  color: var(--text);
}
html[data-theme='dark'] :is(input, textarea)::placeholder {
  color: color-mix(in srgb, var(--muted) 80%, var(--paper));
}

/* Surfaces fixes et états interactifs. */
html[data-theme='dark']
  :is(
    .kpi-tabs,
    .account-group h3,
    .account-group-heading,
    .forecast-group-heading,
    .accounts-table th
  ) {
  background: var(--hover-surface);
}
html[data-theme='dark'] :is(.table-scroll, .operations-frame) {
  background: var(--page);
}
html[data-theme='dark']
  :is(
    .config-row,
    .forecast-account,
    .accounts-table,
    .action-list button,
    .config-row > button,
    .forecast-actions > button:not(.forecast-apply),
    .allocation-editor button,
    .dialog-actions button:not(.save-button),
    .forecast-table button
  ) {
  background: var(--paper);
}
html[data-theme='dark'] :is(th, .group-row td) {
  background: var(--hover-surface);
}
html[data-theme='dark'] :is(.nav-item.active, .operations-toolbar button.active) {
  background: var(--pressed);
}
html[data-theme='dark'] .column-sort.active {
  background: var(--pressed);
  color: var(--text);
}
html[data-theme='dark'] .progress {
  background: var(--border);
}
html[data-theme='dark'] #notice {
  background: var(--pressed);
  color: var(--text);
}
html[data-theme='dark']
  :is(
    .search,
    .operations-toolbar .search,
    .category-search,
    .icon-picker summary,
    .icon-picker-options,
    .icon-picker-options button,
    .icon-picker-search,
    #dropdown-menu.month-filter-menu .month-search,
    .account-table-order button,
    .account-table-favorite button,
    .account-table-action button
  ) {
  background: color-mix(in srgb, var(--paper) 55%, var(--field));
}
html[data-theme='dark']
  :is(
    .edit-field input,
    .edit-field select,
    .allocation-row input,
    .allocation-row select,
    .sort-rule select,
    .sort-add select,
    .account-filter select,
    #dropdown-menu .menu-date input,
    #dropdown-menu.month-filter-menu .month-search input,
    .auth-card input,
    #new-user-form input
  ) {
  background: color-mix(in srgb, var(--page) 35%, var(--paper));
  color: var(--text);
  border-color: var(--border);
}
html[data-theme='dark'] :is(.icon-picker summary, .category-search) {
  color: var(--text);
  border-color: var(--border);
}
html[data-theme='dark']
  :is(
    #editor-dialog,
    #action-dialog,
    #dropdown-menu,
    #release-dialog,
    #users-dialog,
    #import-dialog
  ) {
  background: var(--paper);
  color: var(--text);
  border-color: var(--border);
}
html[data-theme='dark'] #dropdown-menu button {
  color: var(--text);
}
html[data-theme='dark'] .icon-picker-options {
  border-color: var(--border);
}

@media (hover: hover) and (pointer: fine) {
html[data-theme='dark']
  :is(
    .nav-item:not(.active):hover,
    tbody tr:hover,
    .config-row:hover,
    .category-group .config-row:hover,
    .accounts-table tbody tr:hover,
    .forecast-account > summary:hover,
    .envelope-card:hover,
    .search:hover,
    .category-search:hover,
    .icon-picker summary:hover,
    .icon-picker-options button:hover,
    .action-list button:hover,
    .group-row button:hover,
    .account-heading:hover,
    #release-close:hover,
    #import-close:hover
  ) {
  background: var(--hover-surface);
}
}
html[data-theme='dark']
  :is(
    .nav-item:not(.active):active,
    .forecast-account > summary:active,
    .envelope-card:active,
    .icon-picker-options button:active,
    .action-list button:active,
    .group-row button:active,
    #release-close:active,
    #import-close:active
  ) {
  background: var(--pressed);
}
@media (hover: hover) and (pointer: fine) {
html[data-theme='dark']
  :is(
    .operations-toolbar button:not(.active):hover,
    .month-controls button:hover,
    #dropdown-menu button:hover,
    .row-action:hover,
    .panel-add:hover,
    .kpi-tab:not(.active):hover,
    .config-row > button:hover,
    .forecast-actions > button:not(.forecast-apply):hover,
    .forecast-table button:hover,
    .account-table-action button:hover,
    .config-toolbar button:hover,
    .account-table-order button:hover:not(:disabled),
    .account-table-favorite button:hover
  ) {
  background: var(--hover-control);
}
}
html[data-theme='dark']
  :is(
    .operations-toolbar button:not(.active):active,
    .month-controls button:active,
    #dropdown-menu button:active,
    .row-action:active,
    .panel-add:active,
    .kpi-tab:not(.active):active,
    .config-row > button:active,
    .forecast-actions > button:not(.forecast-apply):active,
    .forecast-table button:active,
    .account-table-action button:active,
    .config-toolbar button:active,
    .account-table-order button:active:not(:disabled),
    .account-table-favorite button:active
  ) {
  background: var(--pressed);
}
@media (hover: hover) and (pointer: fine) {
html[data-theme='dark'] .operations-toolbar button.active:hover {
  background: var(--hover-button);
}
}
html[data-theme='dark'] .operations-toolbar button.active:active {
  background: var(--pressed-button);
}
html[data-theme='dark'] :is(.search:focus-within, .category-search:focus-within) {
  background: color-mix(in srgb, var(--page) 35%, var(--paper));
}
html[data-theme='dark']
  :is(
    #dropdown-menu button[aria-checked='true'],
    .icon-picker-options button[aria-selected='true'],
    .action-list button[aria-current='true']
  ) {
  background: var(--hover-button);
}

/* Montants et types d'opérations : les couleurs gardent leur sens. */
html[data-theme='dark'] tr:has(.amount-cell.checked-expense) > td:has(> .type-badge) {
  background: #3d2b2c;
}
html[data-theme='dark'] tr:has(.amount-cell.checked-income) > td:has(> .type-badge) {
  background: #2a3a30;
}
html[data-theme='dark'] tr:has(.amount-cell.checked-deferred) > td:has(> .type-badge) {
  background: var(--deferred-bg);
}
html[data-theme='dark'] .amount-cell.checked-expense {
  background: #3d2b2c;
}
html[data-theme='dark'] .amount-cell.checked-income {
  background: #2a3a30;
}
html[data-theme='dark'] .amount-cell.checked-deferred {
  background: var(--deferred-bg);
}
html[data-theme='dark'] :is(.type-expense, .amount-cell.checked-expense) {
  color: var(--red);
}
html[data-theme='dark'] :is(.type-income, .type-transfer, .amount-cell.checked-income) {
  color: var(--green);
}
html[data-theme='dark'] :is(.type-deferred, .amount-cell.checked-deferred) {
  color: var(--olive);
}
html[data-theme='dark'] .amount-cell.deferred-text {
  color: var(--olive);
}
html[data-theme='dark'] #editor-delete {
  color: var(--red);
  border-color: #6e4a4d;
}
@media (hover: hover) and (pointer: fine) {
html[data-theme='dark'] #editor-delete:hover {
  background: #3d2b2c;
}
}
html[data-theme='dark'] #editor-delete:active {
  background: #4a3335;
}
html[data-theme='dark'] .account-table-favorite button[aria-pressed='true'] {
  color: var(--olive);
  background: var(--deferred-bg);
}
html[data-theme='dark'] .forecast-actions .forecast-apply:disabled {
  background: var(--pressed);
  color: var(--muted);
}
html[data-theme='dark'] #editor-error {
  color: var(--red);
}


html[data-theme='dark'] .type-transfer-debit {
  color: var(--red);
}
html[data-theme='dark'] .type-transfer-credit {
  color: var(--green);
}
html[data-theme='dark'] :is(.choice-trigger, .choice-search) {
  background: color-mix(in srgb, var(--page) 35%, var(--paper));
  color: var(--text);
}
@media (hover: hover) and (pointer: fine) {
html[data-theme='dark'] .choice-options button:hover {
  background: var(--hover-control);
}
}
html[data-theme='dark'] .choice-options button:active {
  background: var(--pressed);
}
html[data-theme='dark'] .choice-options button[aria-selected='true'] {
  background: var(--hover-button);
}
@media (hover: hover) and (pointer: fine) {
html[data-theme='dark'] .category-order button:hover:not(:disabled) {
  background: var(--hover-control);
}
}
html[data-theme='dark'] .category-order button:active:not(:disabled) {
  background: var(--pressed);
}

@media (hover: hover) and (pointer: fine) {
html[data-theme='dark'] tbody tr:hover .amount-cell:is(.checked-expense, .checked-income, .checked-deferred) {
  box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.05);
}
}
html[data-theme='dark'] .inline-edit {
  background: color-mix(in srgb, var(--page) 35%, var(--paper));
  color: var(--text);
  border-color: var(--blue);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--blue) 25%, transparent);
}
html[data-theme='dark'] .no-date,
html[data-theme='dark'] .edit-field.field-missing > span::after {
  color: #e2b45c;
}

html[data-theme='dark'] .available-kpi.kpi-positive {
  background: #2a3a30;
}
html[data-theme='dark'] .available-kpi.kpi-negative {
  background: #3d2b2c;
}
html[data-theme='dark'] .available-kpi.kpi-zero {
  background: var(--hover-surface);
}
html[data-theme='dark'] .deferred-kpi {
  background: var(--deferred-bg);
}

/* Couleur primaire (boutons) en thème sombre : brun assez clair pour se détacher, texte blanc lisible (≥ 6:1). */
html[data-theme='dark'] {
  --accent: #8a4a30;
  --accent-line: #9a573a;
  --accent-hover: #9a573a;
  --accent-pressed: #77432e;
}
