@import url("formFields.css?v=1");

/* Theme tokens are separate from the older page palettes. Light mode keeps
   each page's existing colors; dark overrides cover shared and legacy UI. */
:root {
  --theme-bg: #f3f4f6;
  --theme-surface: #fff;
  --theme-raised: #f1f5f9;
  --theme-input: #fff;
  --theme-text: #172033;
  --theme-muted: #52627a;
  --theme-border: #cbd5e1;
  --theme-link: #1d4ed8;
  --theme-selected: #dbeafe;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 6px 10px;
  min-height: 32px;
  border: 1px solid var(--theme-border);
  border-radius: 6px;
  background: var(--theme-surface);
  color: var(--theme-text);
  font: 500 12px/1.2 system-ui, sans-serif;
  cursor: pointer;
  white-space: nowrap;
}
.theme-toggle svg { flex: none; }
.theme-toggle:hover:not(:disabled) { background: var(--theme-raised); }
.theme-toggle:disabled { cursor: not-allowed; opacity: .6; }
.theme-toggle[aria-pressed="true"] { background: var(--theme-selected); color: var(--theme-link); border-color: var(--theme-link); }
.theme-toggle:focus-visible { outline: 3px solid #60a5fa; outline-offset: 3px; }
.topbar-right .theme-toggle { background: #ffffff12; border-color: #ffffff80; color: #fff; }
.topbar-right .theme-toggle:hover:not(:disabled), .topbar-right .theme-toggle[aria-pressed="true"] { background: #ffffff24; border-color: #fff; }
.theme-tools { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.theme-tools-floating { position: fixed; top: 12px; right: 12px; z-index: 1001; }
body[data-theme-header] { padding-top: var(--portal-header-height, 64px) !important; }
.topbar:has(.topbar-inner) .topbar-inner { flex-wrap: wrap; row-gap: 8px; }
.topbar:has(.topbar-inner) .topnav-tabs { flex: 1 1 480px; }
.topbar:has(.topbar-inner) .topbar-right { flex-wrap: wrap; }
@media (max-width: 700px) {
  .page-title-block, .page-header-left { min-width: 0; max-width: 100%; }
  .page-title-block h1, .page-header-left h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .page-header :is(.badge-count, .badge-pill) { flex: 0 0 auto; white-space: nowrap; }
  .topbar:has(.topbar-inner) .brand { flex-basis: 100%; font-size: 20px; }
  .topbar:has(.topbar-inner) .topbar-right { order: 2; width: 100%; justify-content: space-between; gap: 8px; }
  .topbar:has(.topbar-inner) .topnav-tabs { order: 3; flex-basis: 100%; gap: 2px; }
  .topbar:has(.topbar-inner) .topnav-tab { font-size: 12px; padding: 6px 8px; }
  .topbar-right .user-label { min-width: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
}

@media screen {
  html[data-theme="dark"], html[data-theme="dark"] body {
    color-scheme: dark;
    --theme-bg: #101722;
    --theme-surface: #192332;
    --theme-raised: #233146;
    --theme-input: #111c2b;
    --theme-text: #e5ecf5;
    --theme-muted: #acbad0;
    --theme-border: #43536b;
    --theme-link: #9bc5ff;
    --theme-selected: #253f64;
    --theme-highlight-bg: #443a1e;
    --theme-highlight-hover: #504321;
    --theme-success-bg: #133c30;
    --theme-success-text: #9aefbf;
    --theme-warning-bg: #47371c;
    --theme-warning-text: #ffdc8a;
    --theme-error-bg: #48272e;
    --theme-error-text: #ffb3b3;
    --bg: var(--theme-bg);
    --card-bg: var(--theme-surface);
    --panel: var(--theme-surface);
    --text-main: var(--theme-text);
    --text: var(--theme-text);
    --text-muted: var(--theme-muted);
    --muted: var(--theme-muted);
    --border: var(--theme-border);
    --line: var(--theme-border);
    --code: var(--theme-input);
    --primary: var(--theme-link);
    --primary-dark: var(--theme-link);
    --danger: var(--theme-error-text);
    --ok: var(--theme-success-text);
  }
  html[data-theme="dark"], html[data-theme="dark"] body {
    background: var(--theme-bg) !important;
    color: var(--theme-text) !important;
  }
  html[data-theme="dark"] :is(.card, .stat-card, .login-card, .panel, .content, aside, fieldset,
    .table-wrapper, .detail-panel, .contract-detail, .detail-section, .form-section, .form-card, .customer-property-row, .customer-app-account, .contact-chip, .reminder-edit-card, .bulk-delivery-dates-dialog,
    .accordion-item, .accordion-content, .contact-card, .stat, .kpi-card, .api-card, details,
    .b2c-tracking-panel, .b2c-tracking-notice, .b2c-api-step, .b2c-api-dialog .step, .intro-split-item,
    .admin-card, .admin-card-body, .docs-link-card, .delivery-point-detail-value, .billing-scroll,
    .searchable-select-dropdown, .system-select-panel, .modal-content, .modal-dialog, dialog:not(.page-loading-mask), [popover]) {
    background: var(--theme-surface) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
  }
  html[data-theme="dark"] :is(.card-header, .accordion-header, .summary-box, .detail-header, .form-panel-dashed, #newSupplyForm, #newOutgoingForm,
    .account-tabs, .tabs, .admin-subnav-link, .delivery-point-dialog-header, .delivery-point-dialog-footer, .contact-card-header,
    .modal-header, .modal-footer, .tab-content, .tab-panel, .app-version-badge, .system-select-footer, .api-toolbar,
    .b2c-tracking-header, .b2c-api-dialog .step-group, .b2c-api-header, pre, code) {
    background: var(--theme-raised) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
  }
  html[data-theme="dark"] :is(h1, h2, h3, h4, h5, h6, legend, .logo-text-main, .stat-card-value, .detail-title, .section-subtitle, .kpi-value,
    .contact-person-name, .timeline-reason strong, .note-item) { color: var(--theme-text) !important; }
  html[data-theme="dark"] :is(.small-muted, .hint, .form-label, .field-label, .detail-label, .summary-label,
    .stat-card-title, .summary-info, .login-subtitle, .login-version-inline, .logo-text-sub, .page-title-block p, .page-header-left p, .header-right, .page-header-right,
    .admin-subnav-hint, .docs-link-card p, .billing-note, .table-empty-cell, .table-loading-cell, .portal-pagination .page-info, .button-separator,
    .portal-pagination .pagination-size, .table-query-help, .footnote, .duplicate-table-address, .duplicate-table-contact,
    .intro-split-item > label, .admin-filter-field, .inline-radio-control, .admin-help-text, .customer-property-count,
    .split-summary-label, .timeline-loading, .customer-app-account p, .app-account-dialog p) { color: var(--theme-muted) !important; }
  html[data-theme="dark"] .admin-help-text strong { color: var(--theme-text); }
  html[data-theme="dark"] :is(a:not(.topnav-tab):not(.btn-primary):not(.btn-login), button.link-cell) { color: var(--theme-link); }
  html[data-theme="dark"] .docs-link-eyebrow { color: var(--theme-link); }
  html[data-theme="dark"] .api-toolbar strong { color: var(--theme-text) !important; }
  html[data-theme="dark"] .empty-icon { color: var(--theme-link); }
  html[data-theme="dark"] .tree-row:hover { background: var(--theme-selected); }
  html[data-theme="dark"] :is(.topbar:not(.topbar--test):has(.topbar-inner)) { background: linear-gradient(90deg, #173456, #1d3864) !important; }
  html[data-theme="dark"] .topnav-tab { color: #fff !important; }
  html[data-theme="dark"] :is(.topnav-tab.active, .admin-subnav-link.active, .billing-subnav a[aria-current="page"], .tab.active, .account-tab.active, .address-tab.active, .tabs button.active) {
    background: var(--theme-selected) !important; color: var(--theme-link) !important; border-color: var(--theme-link) !important;
  }
  html[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]), select, textarea) {
    background: var(--theme-input) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
  }
  html[data-theme="dark"] :is(input, select, textarea)::placeholder { color: var(--theme-muted); opacity: 1; }
  html[data-theme="dark"] :is(input[type="checkbox"], input[type="radio"]) { accent-color: #60a5fa; }
  html[data-theme="dark"] :is(.b2c-flag-input, .customer-b2c-flag-input):not(:checked) + :is(.b2c-flag-box, .customer-b2c-flag-box) {
    background: var(--theme-input); border-color: #8b9db7;
  }
  html[data-theme="dark"] :is(.b2c-flag-input, .customer-b2c-flag-input):focus-visible + :is(.b2c-flag-box, .customer-b2c-flag-box) {
    outline: 2px solid #60a5fa; outline-offset: 3px;
  }
  html[data-theme="dark"] :is(input, select, textarea):focus-visible { outline: 2px solid #60a5fa; outline-offset: 1px; border-color: #60a5fa !important; }
  html[data-theme="dark"] :is(input, select, textarea)[aria-invalid="true"] { background: var(--theme-warning-bg) !important; border-color: var(--theme-warning-text) !important; }
  html[data-theme="dark"] :is(.btn-secondary, .btn-secondary2, .btn-secondary3, .btn-small, .btn-small-secondary, .link-edit, .link-small, .tree-toggle,
    .category-pill, .tab, .tabs button, .small-button, .contact-action-edit, .b2c-api-close, .account-tab, .address-tab:where(:not(.active)), button.secondary, .toc-toggle, button.exact-word-search, .billing-subnav a, .b2c-row-action,
    .system-select-footer button, .table-date-range-toggle, .table-filter-apply, .page-btn, .pagination-btn) {
    background: var(--theme-raised) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
  }
  html[data-theme="dark"] :is(.btn-secondary, .btn-secondary2, .btn-secondary3, .btn-small, .tabs button, .small-button, .contact-action-edit, .b2c-api-close, .category-pill, .account-tab, .page-btn, button.secondary, .tree-toggle):hover:not(:disabled) {
    background: var(--theme-selected) !important; color: var(--theme-link) !important;
  }
  html[data-theme="dark"] :is(.btn-primary, .btn-login, .btn-small-primary, .duplicate-open-link, label.upload, .api-btn:not(.secondary), .category-pill.active,
    button.exact-word-search[aria-pressed="true"], .page-btn[aria-current="page"], .pagination-btn.active) {
    background: #2563eb !important; color: #fff !important; border-color: #6096ef !important;
  }
  html[data-theme="dark"] :is(.btn-danger, .btn-small-danger, .btn-remove, .contact-action-delete, .admin-button-danger, button.danger) {
    background: var(--theme-error-bg) !important; color: var(--theme-error-text) !important; border-color: #bb6d79 !important;
  }
  /* Informational statuses share the contract/customer ID badge palette. */
  html[data-theme="dark"] :is(a.link-cell, button.link-cell, a.delivery-contract-badge, .tag-blue, .badge-count, .badge-mode, .badge-id, .avatar, .archive-help-badge, .app-account-state,
    .tag:not(.tag-green):not(.tag-red):not(.tag-orange), .contact-pill-neutral,
    .stat-chip, .badge-index, .badge-pill, .admin-badge, .pill, .category-pill .count, .b2c-status-pill.is-empty,
    .admin-status, .billing-status, .billing-tag, .b2c-api-status, :where(.status:not(.error):not(.ok))) {
    background: var(--theme-selected) !important; color: var(--theme-link) !important; border-color: #6687bb !important;
  }
  html[data-theme="dark"] table { background: var(--theme-surface) !important; color: var(--theme-text) !important; }
  html[data-theme="dark"] :is(th, td, table, .field, .event, .detail-row td, .form-grid-3, .accordion-item) { border-color: var(--theme-border) !important; }
  html[data-theme="dark"] :is(thead, th, .subtable th) { background: var(--theme-raised) !important; color: var(--theme-muted) !important; }
  html[data-theme="dark"] tbody td { background: var(--theme-surface) !important; color: var(--theme-text) !important; }
  html[data-theme="dark"] tbody tr:nth-child(even) td { background: #1d2a3c !important; }
  html[data-theme="dark"] tbody tr:hover td { background: #294161 !important; }
  html[data-theme="dark"] #supplyTable tbody tr.row-alt td { background: #1d2a3c !important; }
  html[data-theme="dark"] #supplyTable tbody tr:hover td { background: #294161 !important; }
  html[data-theme="dark"] .detail-row td { background: var(--theme-input) !important; }
  /* Match the page-specific table selectors, whose light highlights use !important. */
  html[data-theme="dark"] :is(#kundenTable, #b2bTable, #contractsTable) tbody tr:is(.row-new-highlight, .row-edit-highlight, .row-return-highlight, .row-cancel-highlight, .is-last-clicked) > td {
    background: var(--theme-highlight-bg) !important; color: var(--theme-text) !important;
  }
  html[data-theme="dark"] :is(#kundenTable, #b2bTable, #contractsTable) tbody tr:is(.row-new-highlight, .row-edit-highlight, .row-return-highlight, .row-cancel-highlight, .is-last-clicked):hover > td {
    background: var(--theme-highlight-hover) !important;
  }
  html[data-theme="dark"] :is(.searchable-select-option:hover, .searchable-select-option.selected, .system-select-option:hover,
    .system-select-option.is-active, .system-select-option[aria-selected="true"], .customer-property-row:hover, .customer-property-row.is-selected,
    .meter-manager-toggle-btn[aria-expanded="true"], .file.active, .event.active) {
    background: var(--theme-selected) !important; color: var(--theme-text) !important;
  }
  html[data-theme="dark"] :is(.system-select-checkbox, .event, .file, .portal-loading-status) { background: var(--theme-surface) !important; color: var(--theme-text) !important; }
  html[data-theme="dark"] .system-select-multiple-option[aria-selected="true"] .system-select-checkbox { background: #2563eb !important; }
  html[data-theme="dark"] .portal-pagination .page-btn:disabled { color: #8b9db7 !important; }
  html[data-theme="dark"] .page-loading-mask { background: #101722b8 !important; }
  html[data-theme="dark"] .portal-loading-spinner { border-color: #43536b; border-top-color: #9bc5ff; }
  html[data-theme="dark"] :is(dialog, [popover])::backdrop { background: #050a137f; }
  html[data-theme="dark"] .page-loading-mask::backdrop { background: transparent; }

  /* The old inline renderers use fixed light colors. Limit replacements to
     those palette values so semantic status colors can retain their meaning. */
  html[data-theme="dark"] :is([style*="background:#fff" i], [style*="background: #fff" i],
    [style*="background-color:#fff" i], [style*="background-color: #fff" i], [style*="background:white" i],
    [style*="background: white" i], [style*="background:#f9fafb" i], [style*="background: #f9fafb" i],
    [style*="background:#f8fafc" i], [style*="background: #f8fafc" i], [style*="background:#f1f5f9" i], [style*="background: #f1f5f9" i]) {
    background: var(--theme-surface) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
  }
  html[data-theme="dark"] :is([style*="color:#111" i], [style*="color: #111" i], [style*="color:#000" i], [style*="color: #000" i],
    [style*="color:#0f172a" i], [style*="color: #0f172a" i], [style*="color:#333" i], [style*="color: #333" i], [style*="color:black" i], [style*="color: black" i]) { color: var(--theme-text) !important; }
  html[data-theme="dark"] :is([style*="color:#6b7280" i], [style*="color: #6b7280" i], [style*="color:#64748b" i], [style*="color: #64748b" i],
    [style*="color:#666" i], [style*="color: #666" i], [style*="color:#999" i], [style*="color: #999" i]) { color: var(--theme-muted) !important; }
  html[data-theme="dark"] :is(.chip-status, .status-gebucht, .tag-green, .duplicate-result, .contact-pill-main, .status-switch-text.is-complete, .app-account-state[data-state="linked"], .customer-meter-field-save-btn, .b2c-status-pill.is-active, .api-pill.post, .status.ok, .admin-status.is-success,
    .billing-tag.active, .billing-tag.approved, .b2c-api-status.is-success, .b2c-api-step-icon.is-success, .b2c-api-dialog .step-status-success,
    [style*="#ecfdf3" i], [style*="#ecfdf5" i], [style*="#dcfce7" i]) {
    background: var(--theme-success-bg) !important; color: var(--theme-success-text) !important; border-color: #3c7c61 !important;
  }
  html[data-theme="dark"] :is(.chip-status-red, .tag-red, #errorMessage, .customer-meter-field-cancel-btn, .customer-meter-list-close-btn, .b2c-status-pill.is-cancelled, .api-pill.delete, .status.error, .error-box, .admin-status.is-error, .billing-status[data-error="true"],
    .b2c-tracking-notice.is-error, .b2c-api-status.is-error, .b2c-api-step-icon.is-error, .b2c-api-dialog .step-status-error, .b2c-cancellation-card.is-cancelled,
    [style*="#fef2f2" i], [style*="#fee2e2" i]) {
    background: var(--theme-error-bg) !important; color: var(--theme-error-text) !important; border-color: #a85d6a !important;
  }
  html[data-theme="dark"] :is(.status-offen, .tag-orange, .status-switch-text.is-open, .btn-korektur, #message[role="alert"], .b2c-status-pill.is-expiring, .api-pill.put, .meter-cleanup-dialog [data-duplicates], .incoming-mismatch td,
    .billing-tag.draft, .b2c-api-status.is-pending, .b2c-api-step-icon.is-pending, .b2c-api-dialog .step-status-pending,
    [style*="#fffbeb" i], [style*="#fef3c7" i], [style*="#fff7ed" i]) {
    background: var(--theme-warning-bg) !important; color: var(--theme-warning-text) !important; border-color: #a78a50 !important;
  }
  html[data-theme="dark"] :is(.summary-diff-neg, .table-error-cell, .table-state-cell--error, .table-id-error,
    .delivery-point-save-error, .bulk-delivery-dates-error, .meter-cleanup-error, .timeline-error, .b2c-cancellation-note, .required-field-marker, [data-supplier-error], #supplierStatus[data-error="true"]) { color: var(--theme-error-text) !important; }
  html[data-theme="dark"] :is(.summary-diff-pos, .summary-highlight, .reminder-edit-label) { color: var(--theme-success-text) !important; }
  html[data-theme="dark"] :is(.meter-duplicate-indicator, .table-filter-feedback, .found-count) { color: var(--theme-warning-text) !important; }
}
@media print {
  .theme-toggle, .theme-tools { display: none !important; }
  html { color-scheme: light !important; }
  body[data-theme-header] { padding-top: 0 !important; }
}
