/* ==========================================================================
   FinApp v2 — Shared Components
   ========================================================================== */

@layer components {
  /* ------------------------------------------------------------------------
     Cards & Surfaces (No nested cards; use .surface-inset or hairline dividers)
     ------------------------------------------------------------------------ */
  .card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    overflow: clip;
    min-width: 0;
    max-width: 100%;
  }

  .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
  }

  .card-header.is-linen {
    background-color: var(--bg-subtle);
  }

  .card-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }

  .card-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
  }

  .card-title svg {
    width: 17px;
    height: 17px;
    color: var(--brand-primary);
    flex-shrink: 0;
  }

  .card-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
  }

  .card-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
  }

  .card-body {
    padding: var(--space-5);
  }

  .card-body.is-flush {
    padding: 0;
  }

  .surface-inset {
    background-color: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-4);
  }

  /* ------------------------------------------------------------------------
     KPI Strip & Stat Cells
     ------------------------------------------------------------------------ */
  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .kpi-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--dur-fast) var(--ease-out);
  }

  .kpi-card:hover {
    border-color: var(--border-strong);
  }

  .kpi-card.is-featured {
    background-color: var(--bg-subtle);
    border-color: var(--border-strong);
  }

  .kpi-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
  }

  .kpi-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.01em;
  }

  .kpi-icon {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background-color: var(--bg-linen);
    color: var(--brand-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .kpi-icon svg {
    width: 15px;
    height: 15px;
  }

  .kpi-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.15;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
  }

  .kpi-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    font-size: var(--text-xs);
    color: var(--text-muted);
  }

  /* ------------------------------------------------------------------------
     Shared Net Worth Card (Portföy & Bütçe)
     ------------------------------------------------------------------------ */
  .nw-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-xs);
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(240px, 1fr);
    gap: var(--space-5);
    align-items: center;
  }

  .nw-primary {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .nw-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
  }

  .nw-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
  }

  .nw-title svg {
    width: 16px;
    height: 16px;
    color: var(--brand-primary);
  }

  .nw-value-row {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    flex-wrap: wrap;
  }

  .nw-value {
    font-family: var(--font-display);
    font-size: var(--text-3xl);
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
  }

  .nw-breakdown {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
  }

  .nw-part {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .nw-part-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
  }

  .nw-part-value {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
  }

  .nw-chart-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    background-color: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    min-width: 0;
  }

  .nw-chart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-muted);
    flex-wrap: wrap;
  }

  .nw-sparkline-box {
    position: relative;
    width: 100%;
    height: 112px;
  }

  .nw-sparkline {
    width: 100%;
    height: 100%;
    overflow: visible;
    display: block;
  }

  .nw-chart-tooltip {
    position: absolute;
    top: 4px;
    left: 8px;
    pointer-events: none;
    background-color: var(--bg-dark);
    color: var(--text-on-dark);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity var(--dur-fast) var(--ease-out);
    z-index: 3;
  }

  .nw-chart-tooltip.is-visible {
    opacity: 1;
  }

  /* ------------------------------------------------------------------------
     Buttons
     ------------------------------------------------------------------------ */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 38px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: background-color var(--dur-fast) var(--ease-out),
      border-color var(--dur-fast) var(--ease-out),
      color var(--dur-fast) var(--ease-out),
      transform var(--dur-fast) var(--ease-out);
  }

  .btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .btn:active:not(:disabled) {
    transform: translateY(1px);
  }

  .btn:disabled {
    opacity: 0.48;
    cursor: not-allowed;
  }

  .btn-primary {
    background-color: var(--brand-primary);
    color: var(--text-on-brand);
    border-color: var(--brand-primary);
  }

  .btn-primary:hover:not(:disabled) {
    background-color: var(--brand-primary-hover);
    border-color: var(--brand-primary-hover);
  }

  .btn-secondary {
    background-color: var(--bg-linen);
    color: var(--text-primary);
    border-color: var(--border-default);
  }

  .btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-linen-hover);
    border-color: var(--border-strong);
  }

  .btn-outline {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-default);
  }

  .btn-outline:hover:not(:disabled) {
    background-color: var(--bg-subtle);
    border-color: var(--border-strong);
  }

  .btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
  }

  .btn-ghost:hover:not(:disabled) {
    background-color: var(--bg-linen);
    color: var(--text-primary);
  }

  .btn-danger {
    background-color: var(--negative-solid);
    color: var(--text-on-danger);
    border-color: var(--negative-solid);
  }

  .btn-danger:hover:not(:disabled) {
    background-color: var(--negative-solid-hover);
    border-color: var(--negative-solid-hover);
  }

  .btn-danger-outline {
    background-color: var(--negative-bg);
    color: var(--negative-text);
    border-color: var(--negative-border);
  }

  .btn-danger-outline:hover:not(:disabled) {
    background-color: rgba(217, 104, 104, 0.24);
  }

  .btn-sm {
    height: 32px;
    padding: 0 var(--space-3);
    font-size: var(--text-xs);
  }

  .btn-lg {
    height: 44px;
    padding: 0 var(--space-5);
    font-size: var(--text-base);
  }

  .btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    border: 1px solid transparent;
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  }

  .btn-icon:hover:not(:disabled) {
    background-color: var(--bg-linen);
    color: var(--text-primary);
  }

  .btn-icon svg {
    width: 18px;
    height: 18px;
  }

  .btn-icon.has-border {
    border-color: var(--border-default);
    background-color: var(--bg-surface);
  }

  .btn-icon.is-active {
    background-color: var(--brand-primary);
    color: var(--text-on-brand);
  }

  /* ------------------------------------------------------------------------
     Badges, Pills & Stale Price Indicators
     ------------------------------------------------------------------------ */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .badge svg {
    width: 13px;
    height: 13px;
  }

  .badge-linen {
    background-color: var(--bg-linen);
    color: var(--text-primary);
  }

  .badge-positive {
    background-color: var(--positive-bg);
    color: var(--positive-text);
  }

  .badge-negative {
    background-color: var(--negative-bg);
    color: var(--negative-text);
  }

  .badge-warning {
    background-color: var(--warning-bg);
    color: var(--warning-text);
  }

  .badge-info {
    background-color: var(--info-bg);
    color: var(--info-text);
  }

  .badge-olive {
    background-color: var(--brand-primary);
    color: var(--text-on-brand);
  }

  .stale-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: var(--radius-xs);
    background-color: var(--warning-bg);
    border: 1px solid var(--warning-border);
    color: var(--warning-text);
    font-size: 0.6875rem;
    font-weight: 600;
  }

  .stale-badge svg {
    width: 12px;
    height: 12px;
  }

  /* ------------------------------------------------------------------------
     Forms, Inputs, Selects, Toggles & Inline Validation
     ------------------------------------------------------------------------ */
  .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .form-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
  }

  .form-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: 400;
  }

  .form-control,
  .form-select,
  .form-textarea {
    width: 100%;
    height: 40px;
    padding: 0 var(--space-3);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    color: var(--text-primary);
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
  }

  .form-textarea {
    height: auto;
    min-height: 84px;
    padding: var(--space-2) var(--space-3);
    resize: vertical;
  }

  .form-control::placeholder,
  .form-textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.85;
  }

  .form-control:hover:not(:disabled),
  .form-select:hover:not(:disabled),
  .form-textarea:hover:not(:disabled) {
    border-color: var(--border-strong);
  }

  .form-control:focus,
  .form-select:focus,
  .form-textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-ring);
  }

  .form-control[readonly],
  .form-control:disabled {
    background-color: var(--bg-subtle);
    color: var(--text-muted);
    cursor: not-allowed;
  }

  .form-control.is-invalid,
  .form-select.is-invalid {
    border-color: var(--negative-solid);
    box-shadow: 0 0 0 3px rgba(217, 104, 104, 0.2);
  }

  .input-with-addon {
    position: relative;
    display: flex;
    align-items: center;
  }

  .input-with-addon .form-control {
    padding-right: 40px;
  }

  .input-addon-right {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border-radius: var(--radius-xs);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
  }

  .input-addon-right:hover {
    color: var(--text-primary);
    background-color: var(--bg-subtle);
  }

  .input-addon-right svg {
    width: 16px;
    height: 16px;
  }

  .form-error {
    display: none;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--negative-text);
    background-color: var(--negative-bg);
    border: 1px solid var(--negative-border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    line-height: 1.4;
  }

  .form-error.is-visible {
    display: flex;
  }

  .form-error svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }

  /* Password Strength Meter */
  .password-strength {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 2px;
  }

  .password-strength-track {
    height: 5px;
    background-color: var(--bg-linen);
    border-radius: var(--radius-pill);
    overflow: hidden;
  }

  .password-strength-bar {
    height: 100%;
    width: 0%;
    border-radius: var(--radius-pill);
    transition: width var(--dur-normal) var(--ease-out), background-color var(--dur-normal) var(--ease-out);
  }

  .password-strength-bar.level-1 { width: 25%; background-color: var(--negative-fill); }
  .password-strength-bar.level-2 { width: 50%; background-color: var(--warning-fill); }
  .password-strength-bar.level-3 { width: 75%; background-color: var(--color-sage); }
  .password-strength-bar.level-4 { width: 100%; background-color: var(--brand-primary); }

  .password-strength-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
  }

  /* Toggle Switch */
  .switch-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-primary);
  }

  .switch-input {
    appearance: none;
    -webkit-appearance: none;
    width: 40px;
    height: 22px;
    border-radius: var(--radius-pill);
    background-color: var(--bg-linen);
    border: 1px solid var(--border-strong);
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  }

  .switch-input::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--bg-surface);
    box-shadow: var(--shadow-xs);
    transition: transform var(--dur-fast) var(--ease-out);
  }

  .switch-input:checked {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
  }

  .switch-input:checked::after {
    transform: translateX(18px);
  }

  /* ------------------------------------------------------------------------
     Segmented Tabs & Filter Chips
     ------------------------------------------------------------------------ */
  .segmented {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background-color: var(--bg-linen);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    max-width: 100%;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .segmented-btn {
    height: 30px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-xs);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
    white-space: nowrap;
  }

  .segmented-btn:hover {
    color: var(--text-primary);
  }

  .segmented-btn.is-active {
    background-color: var(--brand-primary);
    color: var(--text-on-brand);
  }

  .tabs-bar {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border-default);
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
    transition: color var(--dur-fast) var(--ease-out);
  }

  .tab-btn svg {
    width: 15px;
    height: 15px;
  }

  .tab-btn:hover {
    color: var(--text-primary);
  }

  .tab-btn.is-active {
    color: var(--brand-primary);
    font-weight: 600;
  }

  .tab-btn.is-active::after {
    content: "";
    position: absolute;
    left: var(--space-3);
    right: var(--space-3);
    bottom: -1px;
    height: 2px;
    background-color: var(--brand-primary);
    border-radius: 2px 2px 0 0;
  }

  .chip-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    max-width: 100%;
  }

  .chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-pill);
    background-color: var(--bg-subtle);
    border: 1px solid var(--border-default);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    transition: background-color var(--dur-fast) var(--ease-out),
      border-color var(--dur-fast) var(--ease-out),
      color var(--dur-fast) var(--ease-out);
  }

  .chip:hover {
    background-color: var(--bg-linen);
    color: var(--text-primary);
  }

  .chip.is-active {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
    color: var(--text-on-brand);
  }

  /* ------------------------------------------------------------------------
     Data Tables & Mobile Card List
     ------------------------------------------------------------------------ */
  .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
  }

  .data-table thead th {
    background-color: var(--bg-subtle);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 600;
    text-align: left;
    padding: 0.75rem var(--space-3);
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
  }

  .data-table thead th:first-child,
  .data-table tbody td:first-child {
    padding-left: var(--space-4);
  }

  .data-table thead th:last-child,
  .data-table tbody td:last-child {
    padding-right: var(--space-4);
  }

  .data-table thead th.num,
  .data-table tbody td.num {
    text-align: right;
    white-space: nowrap;
  }

  .data-table tbody td {
    padding: 0.78rem var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
  }

  .data-table tbody tr {
    transition: background-color var(--dur-fast) var(--ease-out);
  }

  .data-table tbody tr:hover {
    background-color: var(--bg-row-hover);
  }

  .data-table tbody tr:last-child td {
    border-bottom: 0;
  }

  .data-table tbody tr.is-clickable {
    cursor: pointer;
  }

  /* Mobile Structured Transaction / Asset Cards (Hidden on Desktop >768px) */
  .mobile-card-list {
    display: none;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
    max-width: 100%;
  }

  @media (max-width: 768px) {
    .mobile-card-list {
      display: flex;
    }

    .table-wrap.desktop-only {
      display: none;
    }
  }

  .mobile-entity-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
    transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  }

  .mobile-entity-card:hover {
    background-color: var(--bg-row-hover);
    border-color: var(--border-strong);
  }

  .mobile-entity-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-width: 0;
  }

  .mobile-entity-title {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
  }

  .mobile-entity-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2) var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
  }

  .mobile-entity-kv {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
  }

  .mobile-entity-k {
    font-size: 0.6875rem;
    color: var(--text-muted);
  }

  .mobile-entity-v {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
  }

  /* Symbol Avatar Badge (Real Stock/Crypto Logo with Monogram SVG Fallback) */
  .symbol-badge {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
  }

  .symbol-badge.is-sm {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }

  .symbol-badge.is-lg {
    width: 46px;
    height: 46px;
    border-radius: 12px;
  }

  .symbol-logo-img {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 3px;
    background-color: #FFFFFF;
    display: block;
    opacity: 1;
  }

  .symbol-badge.is-sm .symbol-logo-img {
    padding: 2px;
  }

  .symbol-monogram-fallback {
    width: 100%;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .symbol-badge.has-logo .symbol-monogram-fallback {
    display: none;
  }

  .symbol-badge.is-logo-failed .symbol-logo-img {
    display: none;
    opacity: 0;
  }

  .symbol-badge.is-logo-failed .symbol-monogram-fallback {
    display: inline-flex;
  }

  /* ------------------------------------------------------------------------
     Progress & Budget Limit Bars
     ------------------------------------------------------------------------ */
  .progress-track {
    width: 100%;
    height: 8px;
    background-color: var(--bg-linen);
    border-radius: var(--radius-pill);
    overflow: hidden;
  }

  .progress-fill {
    height: 100%;
    border-radius: var(--radius-pill);
    background-color: var(--color-sage);
    transition: width var(--dur-normal) var(--ease-out);
  }

  .progress-fill.is-brand {
    background-color: var(--brand-primary);
  }

  .progress-fill.is-warning {
    background-color: var(--warning-fill);
  }

  .progress-fill.is-danger {
    background-color: var(--negative-fill);
  }

  /* ------------------------------------------------------------------------
     Treemap Foundation (Squarified DOM/CSS Treemap)
     ------------------------------------------------------------------------ */
  .treemap-canvas {
    position: relative;
    width: 100%;
    min-height: 340px;
    background-color: var(--bg-subtle);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
  }

  .treemap-tile {
    position: absolute;
    padding: 8px 10px;
    border: 1px solid var(--bg-canvas);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    cursor: pointer;
    transition: filter var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  }

  .treemap-tile:hover {
    filter: brightness(0.95);
    z-index: 2;
  }

  :root[data-theme="dark"] .treemap-tile:hover {
    filter: brightness(1.1);
  }

  .treemap-tile-sym {
    font-weight: 700;
    font-size: var(--text-sm);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .treemap-tile-val {
    font-size: var(--text-xs);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    opacity: 0.92;
  }

  .floating-tooltip {
    position: fixed;
    z-index: var(--z-tooltip);
    pointer-events: none;
    background-color: var(--bg-dark);
    color: var(--text-on-dark);
    border: 1px solid rgba(255, 255, 255, 0.09);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-tooltip);
    font-size: var(--text-xs);
    line-height: 1.5;
    max-width: 260px;
    display: none;
  }

  .floating-tooltip.is-visible {
    display: block;
  }

  /* ------------------------------------------------------------------------
     Modals (Accessible role="dialog" + Focus Trap)
     ------------------------------------------------------------------------ */
  .modal-overlay {
    position: fixed;
    inset: 0;
    height: 100dvh;
    max-height: 100dvh;
    z-index: var(--z-modal);
    background-color: var(--bg-overlay);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
  }

  .modal-overlay.is-open {
    display: flex;
    animation: fadeInSoft var(--dur-fast) var(--ease-out) both;
  }

  .modal-overlay.is-nested {
    z-index: var(--z-modal-nested);
  }

  .modal-overlay.is-dialog-top {
    z-index: var(--z-dialog);
  }

  .modal-dialog {
    width: 100%;
    max-width: 540px;
    max-height: min(calc(100dvh - 24px - env(safe-area-inset-bottom, 0px)), 860px);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalPop var(--dur-normal) var(--ease-out) both;
  }

  .modal-dialog > form,
  .modal-dialog .modal-form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
  }

  .modal-dialog.is-sm { max-width: 420px; }
  .modal-dialog.is-md { max-width: 560px; }
  .modal-dialog.is-lg { max-width: 760px; }
  .modal-dialog.is-xl { width: min(96vw, 1100px); max-width: 1100px; }

  .modal-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-default);
    background-color: var(--bg-subtle);
  }

  .modal-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
  }

  .modal-header-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background-color: var(--bg-linen);
    color: var(--brand-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .modal-header-icon.is-danger {
    background-color: var(--negative-bg);
    color: var(--negative-text);
  }

  .modal-header-icon svg {
    width: 19px;
    height: 19px;
  }

  .modal-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.25;
  }

  .modal-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
  }

  .modal-close-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  }

  .modal-close-btn:hover {
    background-color: var(--bg-linen);
    color: var(--text-primary);
  }

  .modal-close-btn svg {
    width: 18px;
    height: 18px;
  }

  .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: var(--space-5) var(--space-6);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .modal-body > * {
    flex-shrink: 0;
  }

  .modal-footer {
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px var(--space-6) calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
  }

  /* Command Palette Modal */
  .cmd-dialog {
    max-width: 580px;
    align-self: flex-start;
    margin-top: 10vh;
  }

  .cmd-search-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    border-bottom: 1px solid var(--border-default);
    background-color: var(--bg-surface);
  }

  .cmd-search-bar svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .cmd-search-input {
    flex: 1;
    border: 0;
    background: transparent;
    font-size: var(--text-md);
    color: var(--text-primary);
    outline: none;
    height: 36px;
  }

  .cmd-list {
    max-height: 380px;
    overflow-y: auto;
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .cmd-group-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-3) var(--space-1);
  }

  .cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    padding: 0.6rem var(--space-3);
    border-radius: var(--radius-sm);
    text-align: left;
    font-size: var(--text-sm);
    color: var(--text-primary);
    transition: background-color var(--dur-fast) var(--ease-out);
  }

  .cmd-item-left {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
  }

  .cmd-item svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .cmd-item:hover,
  .cmd-item.is-selected {
    background-color: var(--bg-linen);
  }

  .cmd-item.is-selected svg {
    color: var(--brand-primary);
  }

  /* Notification List Items */
  .notif-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
  }

  .notif-item.is-unread {
    background-color: var(--bg-subtle);
    border-color: var(--border-strong);
  }

  .notif-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--brand-primary);
    margin-top: 6px;
    flex-shrink: 0;
  }

  .notif-item:not(.is-unread) .notif-dot {
    background-color: transparent;
  }

  .notif-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .notif-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
  }

  .notif-message {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.45;
  }

  .notif-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
  }

  /* Danger Zone Panel (Inside Data Management) */
  .danger-zone {
    border: 1px solid var(--negative-border);
    background-color: var(--negative-bg);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .danger-zone-title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--negative-text);
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .danger-zone-text {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.5;
  }

  /* Shortcuts Grid */
  .shortcut-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background-color: var(--bg-subtle);
    font-size: var(--text-sm);
  }

  .kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    padding: 2px 7px;
    border-radius: 6px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-primary);
    box-shadow: 0 1px 0 var(--border-default);
  }

  /* ------------------------------------------------------------------------
     Toast Notifications (aria-live="polite")
     ------------------------------------------------------------------------ */
  .toast-stack {
    position: fixed;
    right: var(--space-5);
    bottom: var(--space-5);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: min(400px, calc(100vw - 2rem));
    pointer-events: none;
  }

  .toast-item {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.75rem var(--space-4);
    border-radius: var(--radius-md);
    background-color: var(--bg-dark);
    color: var(--text-on-dark);
    border: 1px solid rgba(255, 255, 255, 0.09);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    line-height: 1.4;
    animation: toastSlideIn var(--dur-normal) var(--ease-out) both;
  }

  .toast-item.is-leaving {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  }

  .toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }

  .toast-item.is-success .toast-icon { color: var(--color-sage); }
  .toast-item.is-error .toast-icon { color: var(--color-coral); }
  .toast-item.is-warning .toast-icon { color: #E8B866; }
  .toast-item.is-info .toast-icon { color: var(--text-on-dark); }

  .toast-msg {
    flex: 1;
    min-width: 0;
  }

  .toast-undo-btn {
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    background-color: rgba(248, 243, 225, 0.14);
    color: var(--color-parchment);
    font-size: var(--text-xs);
    font-weight: 700;
    white-space: nowrap;
  }

  .toast-undo-btn:hover {
    background-color: rgba(248, 243, 225, 0.24);
  }

  .toast-close {
    color: rgba(248, 243, 225, 0.7);
    padding: 2px;
    display: inline-flex;
  }

  .toast-close:hover {
    color: var(--color-parchment);
  }

  .toast-close svg {
    width: 15px;
    height: 15px;
  }

  /* ------------------------------------------------------------------------
     Skeleton Shimmer & Empty States
     ------------------------------------------------------------------------ */
  .skeleton {
    display: inline-block;
    border-radius: var(--radius-xs);
    background: linear-gradient(
      90deg,
      var(--bg-linen) 25%,
      var(--bg-subtle) 50%,
      var(--bg-linen) 75%
    );
    background-size: 200% 100%;
    animation: skeletonShimmer 1.4s ease-in-out infinite;
  }

  .skeleton-line {
    height: 14px;
    width: 100%;
  }

  .skeleton-kpi {
    height: 32px;
    width: 65%;
  }

  .skeleton-block {
    height: 160px;
    width: 100%;
    border-radius: var(--radius-md);
  }

  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-10) var(--space-6);
    gap: var(--space-3);
  }

  .empty-state-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background-color: var(--bg-linen);
    color: var(--brand-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .empty-state-icon svg {
    width: 24px;
    height: 24px;
  }

  .empty-state-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
  }

  .empty-state-desc {
    font-size: var(--text-sm);
    color: var(--text-muted);
    max-width: 42ch;
    line-height: 1.5;
  }

  /* Privacy Masked Visual Indicator */
  .privacy-masked {
    letter-spacing: 0.08em;
    font-family: var(--font-sans);
  }

  /* ------------------------------------------------------------------------
     Responsive Adjustments for Shared Components
     ------------------------------------------------------------------------ */
  @media (max-width: 1023px) {
    .kpi-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nw-card {
      grid-template-columns: 1fr;
    }

    .nw-breakdown {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .toast-stack {
      left: var(--space-4);
      right: var(--space-4);
      bottom: calc(var(--mobile-bottombar-height) + var(--space-3));
      max-width: none;
    }
  }

  @media (max-width: 639px) {
    .form-row,
    .form-row-3 {
      grid-template-columns: 1fr;
    }

    .kpi-grid {
      gap: var(--space-3);
    }

    .kpi-card {
      padding: var(--space-3) var(--space-4);
    }

    .nw-card {
      padding: var(--space-4);
    }

    .card-header,
    .card-body {
      padding-inline: var(--space-4);
    }

    .modal-overlay {
      padding: 8px;
      padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
      align-items: flex-end;
    }

    .modal-dialog,
    .modal-dialog.is-xl,
    .modal-dialog.is-lg {
      width: 100%;
      max-width: 100%;
      max-height: calc(100dvh - 16px - env(safe-area-inset-bottom, 0px));
      border-radius: var(--radius-lg) var(--radius-lg) var(--radius-md) var(--radius-md);
    }

    .modal-header,
    .modal-body {
      padding-inline: var(--space-4);
    }

    .modal-footer {
      padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .kpi-value {
      font-size: var(--text-xl);
    }

    .nw-value {
      font-size: var(--text-2xl);
    }
  }

  @keyframes modalPop {
    from {
      opacity: 0;
      transform: translateY(10px) scale(0.985);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  @keyframes toastSlideIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }
}
