/* Theme colors preserve layout and the backend state semantics. */
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="dark"] .app-shell .button.danger {
  color: var(--red);
  background: rgba(239,118,136,.08);
  border-color: rgba(239,118,136,.55);
}
:root[data-theme="dark"] .app-shell .button.danger:hover {
  background: rgba(239,118,136,.14);
  border-color: var(--red);
}
:root[data-theme="light"] {
  color-scheme:light;
  --bg:#f3f5f9;
  --sidebar:#fff;
  --surface:#fff;
  --surface-2:#f1f4f9;
  --surface-3:#f7f9fc;
  --surface-subtle:#f7f9fc;
  --surface-hover:#e8eef8;
  --line:#a8b5c8;
  --line-strong:#8698b2;
  --separator:#d1d9e5;
  --text:#172033;
  --muted:#536178;
  --muted-strong:#3f5069;
  --brand:#4269d8;
  --brand-hover:#3159c7;
  --brand-soft:#e8eefc;
  --nav-bg:#fff;
  --control-line:#a8b5c8;
  --action-bg:#4269d8;
  --action-ink:#fff;
  --danger-bg:#fff0f3;
  --danger-ink:#c23851;
  --danger-line:#c45f76;
  --green:#198254;
  --red:#c23851;
  --amber:#9c6516
}
:root[data-theme="light"]:has(.signin-theme) {
  --background:#f3f5f9;
  --foreground:#172033;
  --card:#fff;
  --muted-foreground:#536178;
  --border:#a8b5c8;
  --primary:#4269d8;
  --primary-foreground:#fff;
  --secondary:#f1f4f9;
}
:root[data-theme="light"] body:has(.signin-theme) { background:var(--background); }
:root[data-theme="light"] .signin-brand { color:var(--foreground); }
:root[data-theme="light"] .signin-theme a.text-violet-400 { color:var(--primary); }
:root[data-theme="light"] .signin-error { color:#c23851; }
:root[data-theme="light"] .signin-notice { color:var(--muted-foreground); border-color:var(--border); }
:root[data-theme="light"] .app-shell .panel,
:root[data-theme="light"] .app-shell .filters {
  background: var(--surface);
}
:root[data-theme="light"] .app-shell .sidebar {
  background: var(--sidebar);
  border-color: var(--separator);
}
:root[data-theme="light"] .app-shell .sidebar nav a {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .sidebar nav a:hover,
:root[data-theme="light"] .app-shell .sidebar nav a[aria-current=page] {
  background: var(--brand-soft);
  color: var(--text);
  border-color: transparent;
}
:root[data-theme="light"] .app-shell .button,
:root[data-theme="light"] .app-shell .assets-columns summary,
:root[data-theme="light"] .app-shell .period-dropdown summary {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .button:hover {
  background: var(--surface-hover);
  border-color: var(--line-strong);
}
:root[data-theme="light"] .app-shell .button.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
:root[data-theme="light"] .app-shell input,
:root[data-theme="light"] .app-shell select {
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--text);
}
:root[data-theme="light"] .app-shell input::placeholder {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .panel-heading span,
:root[data-theme="light"] .app-shell .connection-item small,
:root[data-theme="light"] .app-shell .connection-item>div>span,
:root[data-theme="light"] .app-shell .assets-history-note {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .connection-item {
  background: var(--surface-3);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .connection-item:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}
:root[data-theme="light"] .app-shell .connection-source-identity strong {
  color: var(--text);
}
:root[data-theme="light"] .app-shell .badge.neutral,
:root[data-theme="light"] .app-shell .source-chip {
  color: var(--muted-strong);
  background: var(--surface-2);
}
:root[data-theme="light"] .app-shell table {
  color: var(--text);
}
:root[data-theme="light"] .app-shell th {
  color: var(--muted);
  background: var(--surface-3);
  border-color: var(--separator);
}
:root[data-theme="light"] .app-shell td {
  border-color: var(--separator);
}
:root[data-theme="light"] .app-shell .asset-identity strong {
  color: var(--text);
}
:root[data-theme="light"] .app-shell .asset-identity small {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .clickable-row:hover {
  background: var(--surface-2);
}
:root[data-theme="light"] .app-shell .asset-section-tabs {
  border-color: var(--separator);
}
:root[data-theme="light"] .app-shell .asset-section-tabs a {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .asset-section-tabs a[aria-current=page] {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .table-sort {
  color: var(--muted-strong);
}
:root[data-theme="light"] .app-shell .chart-empty {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .pnl-tabs {
  background: var(--surface-3);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .pnl-tabs button {
  color: var(--muted);
  background: transparent;
}
:root[data-theme="light"] .app-shell .pnl-tabs button[aria-selected=true] {
  color: var(--text);
  background: var(--surface-2);
}
:root[data-theme="light"] .app-shell .pnl-day {
  background: var(--surface-3);
  border-color: var(--separator);
  color: var(--text);
}
:root[data-theme="light"] .app-shell .pnl-day-value {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .pnl-summary {
  border-color: var(--separator);
}
:root[data-theme="light"] .app-shell .pnl-day-detail,
:root[data-theme="light"] .app-shell .pnl-footnote {
  color: var(--muted);
  border-color: var(--separator);
}
:root[data-theme="light"] .app-shell .pnl-month strong {
  color: var(--text);
}
:root[data-theme="light"] .app-shell .pnl-month button,
:root[data-theme="light"] .app-shell .pnl-month a {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .period-options a {
  color: var(--muted-strong);
}
:root[data-theme="light"] .app-shell .period-options a[aria-current=page] {
  background: var(--brand-soft);
  color: var(--brand);
}
:root[data-theme="light"] .app-shell .account-avatar {
  background: var(--brand-soft);
  color: var(--brand);
}
:root[data-theme="light"] .app-shell .source-drawer {
  background: var(--surface);
}
:root[data-theme="light"] .app-shell .source-drawer-footer {
  background: var(--surface-3);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .source-drawer-row {
  border-color: var(--separator);
}
:root[data-theme="light"] .app-shell .source-drawer-summary {
  background: var(--surface-3);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .source-search {
  background: var(--surface-3);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .source-drawer-close {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .na,
:root[data-theme="light"] .app-shell .overview-period-pnl .neutral {
  color: var(--muted-strong);
}
:root[data-theme="light"] .app-shell .overview-period-pnl-percent.neutral {
  background: var(--surface-2);
  color: var(--muted-strong);
}
:root[data-theme="light"] .app-shell .pnl-day {
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .pnl-day[aria-label*="День не завершён"] {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .mobile-tab-bar {
  background: var(--nav-bg);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .mobile-tab-bar a,
:root[data-theme="light"] .app-shell .mobile-tab-bar button {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .mobile-tab-bar a[aria-current],
:root[data-theme="light"] .app-shell .mobile-tab-bar button[aria-expanded=true] {
  color: var(--brand);
  background: var(--brand-soft);
}
:root[data-theme="light"] .app-shell .account-menu-trigger .account-avatar {
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .mobile-tab-bar {
  background: var(--surface);
}
:root[data-theme="light"] .app-shell .button {
  border-color: var(--control-line);
}
:root[data-theme="light"] .app-shell .button.primary {
  color: #fff;
}
:root[data-theme="light"] .app-shell .button.danger {
  color: var(--danger-ink);
  border-color: var(--danger-line);
  background: var(--danger-bg);
}
:root[data-theme="light"] .app-shell .button.danger:hover {
  border-color: var(--danger-ink);
}
:root[data-theme="light"] .app-shell .sync-button.sync-compact-button:hover:not(:disabled) {
  background: transparent;
  color: var(--text);
}
:root[data-theme="light"] .app-shell .sync-button.sync-compact-button[data-sync-state=success] {
  color: var(--green);
}
:root[data-theme="light"] .app-shell .sync-button.sync-compact-button[data-sync-state=partial] {
  color: var(--amber);
}
:root[data-theme="light"] .app-shell .sync-button.sync-compact-button[data-sync-state=error] {
  color: var(--red);
}
:root[data-theme="light"] .app-shell .sync-button.sync-compact-button[data-sync-state=history] {
  color: #ff9332;
}
:root[data-theme="light"] .app-shell .connection-dialog {
  background: var(--surface);
}
:root[data-theme="light"] .app-shell .connection-dialog input {
  background: var(--surface-3);
}
:root[data-theme="light"] .app-shell .profile-actions .primary {
  color: #fff;
}
:root[data-theme="light"] .app-shell .chart-periods {
  background: var(--surface-3);
}
:root[data-theme="light"] .app-shell .chart-periods a.is-active {
  color: var(--brand);
  background: var(--brand-soft);
}
:root[data-theme="light"] .app-shell .chart-grid {
  stroke: var(--separator);
}
:root[data-theme="light"] .app-shell .chart-axis {
  color: var(--muted);
}
:root[data-theme="light"] .app-shell .chart-tooltip,
:root[data-theme="light"] .app-shell .info-tooltip::after {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
}
:root[data-theme="light"] .app-shell .allocation-track {
  stroke: var(--separator);
}
:root[data-theme="light"] .app-shell .allocation-legend-button:hover,
:root[data-theme="light"] .app-shell .allocation-legend-button.is-active {
  background: var(--brand-soft);
}
:root[data-theme="light"] .app-shell .allocation-legend-button.is-active strong {
  color: var(--text);
}
:root[data-theme="light"] .app-shell .period-options a:hover,
:root[data-theme="light"] .app-shell .period-options a:focus-visible {
  background: var(--surface-2);
}
:root[data-theme="light"] .app-shell .source-network-count {
  background: var(--surface-2);
}
:root[data-theme="light"] .app-shell .pnl-day.positive .pnl-day-value {
  color: var(--green);
}
:root[data-theme="light"] .app-shell .pnl-day.negative .pnl-day-value {
  color: var(--red);
}
:root[data-theme="light"] .app-shell .pnl-day.positive {
  background: color-mix(in srgb, var(--green) 8%, var(--surface));
}
:root[data-theme="light"] .app-shell .pnl-day.negative {
  background: color-mix(in srgb, var(--red) 8%, var(--surface));
}
:root[data-theme="light"] .app-shell .button.primary,
:root[data-theme="light"] .app-shell .profile-actions .primary {
  background: var(--action-bg);
  border-color: var(--action-bg);
  color: var(--action-ink);
}
:root[data-theme="light"] .app-shell .button.primary:hover {
  background: var(--brand-hover);
}

.menu-theme-row  {
   display: flex;
   align-items: center;
   justify-content: space-between;
   gap: 14px;
   padding: 12px 10px 14px;
   margin-bottom: 4px;
   border-bottom: 1px solid var(--line);
}
.menu-theme-row strong  {
   display: block;
   font-size: 13px;
   font-weight: 500;
}
.menu-theme-row small  {
   display: block;
   margin-top: 4px;
   font-size: 12px;
}
.theme-switch  {
   position: relative;
   flex-shrink: 0;
   width: 64px;
   height: 44px;
   padding: 0;
   border: 0;
   background: transparent;
   cursor: pointer;
   border-radius: 8px;
}
.theme-switch::before  {
   content: "";
   position: absolute;
   inset: 6px 0;
   border-radius: 999px;
   background: var(--brand-soft);
   border: 1px solid var(--line-strong);
}
.theme-switch-thumb  {
   position: absolute;
   top: 10px;
   left: 4px;
   width: 24px;
   height: 24px;
   border-radius: 50%;
   background: #edf2f8;
   color: #263e7b;
   display: grid;
   place-items: center;
   transform: translateX(31px);
   transition: transform 150ms ease;
}
.theme-switch-thumb svg  {
   width: 16px;
   height: 16px;
   fill: none;
   stroke: currentColor;
   stroke-width: 1.8;
   stroke-linecap: round;
   stroke-linejoin: round;
}
.theme-sun  {
   display: none;
}
:root[data-theme=light] .theme-switch-thumb  {
   transform: translateX(0);
   background: #fff;
   color: #365ed0;
}
:root[data-theme=light] .theme-sun  {
   display: block;
}
:root[data-theme=light] .theme-moon  {
   display: none;
}

.theme-switch:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
:root[data-theme="light"] .app-shell .button.primary,
:root[data-theme="light"] .account-button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="light"] .app-shell .button.primary:hover,
:root[data-theme="light"] .account-button.primary:hover { background: var(--brand-hover); }
:root[data-theme="light"] .app-shell .button.danger { color: var(--red); background: #fff0f3; border-color: #c45f76; }
:root[data-theme="light"] .badge.success { background: #e6f5ed; }
:root[data-theme="light"] .badge.warning { background: #fff3df; }
:root[data-theme="light"] .badge.danger { background: #fff0f3; }
:root[data-theme="light"] .app-shell .source-drawer { border-left-color: var(--line); }
:root[data-theme="light"] .app-shell .account-menu-panel { background: var(--surface); border-color: var(--line); }
:root[data-theme="light"] .app-shell .account-menu-item:hover { background: var(--surface-hover); }
:root[data-theme="light"] .app-shell .source-drawer-tab.is-active { color: var(--text); }
:root[data-theme="light"] .app-shell .source-count { background: var(--brand-soft); color: var(--brand); }
:root[data-theme="light"] .app-shell .source-state.syncing { color: var(--brand); }
:root[data-theme="light"] .app-shell .chart-crosshair { stroke: var(--brand); }
:root[data-theme="light"] .app-shell .chart-cursor-marker { fill: var(--surface); stroke: var(--brand); }
:root[data-theme="light"] .app-shell label:has(input.is-invalid,select.is-invalid) { color: var(--red); }
:root[data-theme="light"] .app-shell .operation-date-field { background: var(--surface-3); border-color: var(--line); }
:root[data-theme="light"] .app-shell .operation-date-field input { background: transparent; }
:root[data-theme="light"] .app-shell .mobile-tab-bar { background: rgba(255,255,255,.9); }
:root[data-theme="light"] .app-shell .sync-button[data-sync-state=queued],
:root[data-theme="light"] .app-shell .sync-button[data-sync-state=running],
:root[data-theme="light"] .app-shell .sync-button[data-sync-state=history] { color: #b85b0b; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root[data-theme="light"] .app-shell .mobile-tab-bar { background: var(--surface); }
}
@media (prefers-reduced-transparency: reduce) {
  :root[data-theme="light"] .app-shell .mobile-tab-bar { background: var(--surface); }
}
@media (prefers-reduced-motion: reduce) { .theme-switch-thumb { transition: none; } }

.app-shell .sidebar nav .desktop-source-trigger  {
   display: flex;
   align-items: center;
   gap: 11px;
   min-height: 42px;
   padding: 0 12px;
   color: var(--muted);
   border: 1px solid transparent;
   border-radius: 9px;
   background: transparent;
   font-size: 12px;
   font-weight: 500;
   text-align: left;
   cursor: pointer;
}
.app-shell .sidebar nav .desktop-source-trigger:hover, .app-shell .desktop-source-trigger[aria-expanded=true]  {
   color: var(--text);
   background: var(--brand-soft);
}
.desktop-source-trigger:focus-visible  {
   outline: 2px solid var(--brand);
   outline-offset: 2px;
}
.source-load-status:not(:empty)  {
   position: fixed;
   z-index: 90;
   left: 50%;
   bottom: calc(100px + env(safe-area-inset-bottom));
   transform: translateX(-50%);
   width: max-content;
   max-width: calc(100vw - 32px);
   border: 1px solid var(--line);
   border-radius: 10px;
   padding: 12px 16px;
   color: var(--text);
   background: var(--surface);
   font-size: 13px;
}
