:root {
  --mirror-opacity: .5;
  --mirror-ink: rgba(117, 124, 143, .46);
  --mirror-accent: rgba(157, 97, 69, .52);
  --mirror-card: rgba(255, 255, 255, .54);
  --mirror-chrome: rgba(255, 255, 255, .67);
  --mirror-feed: rgba(241, 243, 249, .22);
  --mirror-stage: rgba(228, 229, 238, .72);
  --mirror-past: rgba(220, 240, 229, .77);
}
:root[data-theme="dark"] {
  --mirror-ink: rgba(153, 167, 189, .39);
  --mirror-accent: rgba(198, 147, 113, .45);
  --mirror-card: rgba(32, 37, 49, .54);
  --mirror-chrome: rgba(32, 37, 49, .67);
  --mirror-feed: rgba(25, 29, 40, .24);
  --mirror-stage: rgba(41, 47, 62, .76);
  --mirror-past: rgba(35, 59, 53, .78);
}
body { isolation: isolate; }
crm-wave-backdrop, crm-wave-surface {
  display: block;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  user-select: none;
  overflow: hidden;
}
crm-wave-backdrop { position: fixed; opacity: var(--mirror-opacity); }
crm-wave-surface { position: absolute; border-radius: inherit; opacity: calc(.42 * var(--mirror-opacity)); }
crm-wave-backdrop canvas, crm-wave-surface canvas { display: block; width: 100%; height: 100%; }
.modal, .table-header, .login-screen .card { isolation: isolate; position: relative; }
.sidebar, dialog { isolation: isolate; }
.sidebar > crm-wave-surface, .table-header > crm-wave-surface { opacity: calc(.53 * var(--mirror-opacity)); }
:root[data-mirror-off] :is(crm-wave-backdrop, crm-wave-surface) { display: none; }

.dashboard-appearance {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  max-width: 100%;
}
.mirror-brightness {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--theme-surface, #fff);
  color: var(--ink);
  font-size: 12px;
  white-space: nowrap;
}
.mirror-brightness input {
  width: clamp(55px, 8vw, 90px);
  height: 24px;
  margin: 0;
  accent-color: var(--purple);
  cursor: pointer;
}
.mirror-brightness input:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.mirror-brightness-value { width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 460px) {
  .dashboard-appearance { gap: 6px; }
  .dashboard-appearance .theme-toggle { gap: 5px; padding-inline: 7px; font-size: 11px; }
  .mirror-brightness { gap: 5px; padding-inline: 8px; font-size: 11px; }
}

:root[data-theme] :is(.metric, .panel, .deal-tile, .day, .proposal, .summary-item, .table-stat) {
  background: var(--mirror-card);
}
:root[data-theme] :is(.topbar, .estimate-list) { background: var(--mirror-chrome); }
:root[data-theme] .content.deal-content :is(.chat-composer, .deal-rob-compose, .deal-chat-options, .profile-save) {
  background: var(--mirror-card);
}
:root[data-theme] .deal-content .chat-feed { background: var(--mirror-feed); }
:root[data-theme] .deal-content .stage:not(.current, .past) { background: var(--mirror-stage); }
:root[data-theme] .deal-content .stage.past { background: var(--mirror-past); }
:root[data-theme] .source-grid { background: var(--mirror-card); }
:root[data-theme] .source-grid td.empty-cell { background: transparent; }

:root[data-theme="dark"] .table-app :is(.model-name, dialog) { color: var(--ink); }
:root[data-theme="dark"] .table-app :is(.model-meta, label, .table-stat span, .source-section p,
  .source-cell, .source-footer, .table-tabs button, .unavailable-price small) { color: var(--muted); }
:root[data-theme="dark"] .table-app :is(.table-tabs button.active, .cell-formula, a:not(.btn)) { color: var(--purple); }
:root[data-theme="dark"] .table-app :is(.source-info, .source-warning, .unavailable-price, .model-warning-count,
  .source-cell.error) { background: var(--theme-warn-bg); color: var(--theme-warn); border-color: var(--theme-warn); }
:root[data-theme="dark"] .table-app .source-info strong { color: inherit; }
:root[data-theme="dark"] .table-app :is(.source-provenance, .source-cell.formula) { background: var(--pale); color: var(--purple); }
:root[data-theme="dark"] .table-app :is(pre, input, .source-grid th, .source-grid td:first-child) {
  background: var(--theme-inset);
  color: var(--ink);
  border-color: var(--line);
}
:root[data-theme="dark"] .table-app :is(dialog, .source-grid, .table-stat, .source-provenance, .rules-list li, .table-tabs) {
  border-color: var(--line);
}
:root[data-theme="dark"] .table-app .source-grid td { border-color: var(--line) !important; }
:root[data-theme="dark"] .table-app dialog { background: var(--theme-surface); }

:root[data-theme="dark"]:has(.login-screen) { color-scheme: dark; }
:root[data-theme="dark"] .login-screen .card { background: #202531; color: #eef0f8; border-color: #3b4355; }
:root[data-theme="dark"] .login-screen .brand { color: inherit; }
:root[data-theme="dark"] .login-screen :is(p, #verification-status) { color: #b9c1d1; }
:root[data-theme="dark"] .login-screen :is(input, .browser-check, #show-password) { border-color: #566178; }
:root[data-theme="dark"] .login-screen input { background: #191d28; color: #eef0f8; }
:root[data-theme="dark"] .login-screen #show-password { background: #2c283e; color: #ded2ff; }
:root[data-theme="dark"] .login-screen #status { color: #ffafb4; }

@media print, (forced-colors: active) {
  crm-wave-backdrop, crm-wave-surface { display: none; }
}
